--- a/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py Wed Jan 08 19:13:57 2020 +0100 +++ b/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py Mon Jan 13 19:23:08 2020 +0100 @@ -7,7 +7,6 @@ Module implementing the version control systems interface to Mercurial. """ - import os import shutil @@ -25,6 +24,7 @@ from VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog from .HgDialog import HgDialog +from .HgClient import HgClient import Utilities @@ -127,6 +127,7 @@ self.__iniWatcher.addPath(cfgFile) self.__client = None + self.__createClient() self.__projectHelper = None self.__repoDir = "" @@ -221,14 +222,6 @@ # shut down the client self.__client and self.__client.stopServer() - def getClient(self): - """ - Public method to get a reference to the command server interface. - - @return reference to the client (HgClient) - """ - return self.__client - def initCommand(self, command): """ Public method to initialize a command arguments list. @@ -371,11 +364,8 @@ args.append(projectDir) if noDialog: - if self.__client is None: - return self.startSynchronizedProcess(QProcess(), 'hg', args) - else: - out, err = self.__client.runcommand(args) - return err == "" + out, err = self.__client.runcommand(args) + return err == "" else: dia = HgDialog( self.tr('Cloning project from a Mercurial repository'), @@ -544,28 +534,18 @@ if msg: args.append("--message") args.append(msg) - if self.__client: - if isinstance(name, list): - self.addArguments(args, name) - else: - if dname != repodir or fname != ".": - args.append(name) + if isinstance(name, list): + self.addArguments(args, name) else: - if isinstance(name, list): - self.addArguments(args, fnames) - else: - if dname != repodir or fname != ".": - args.append(fname) - - if noDialog: - self.startSynchronizedProcess(QProcess(), "hg", args, dname) - else: - dia = HgDialog( - self.tr('Committing changes to Mercurial repository'), - self) - res = dia.startProcess(args, dname) - if res: - dia.exec_() + if dname != repodir or fname != ".": + args.append(name) + + dia = HgDialog( + self.tr('Committing changes to Mercurial repository'), + self) + res = dia.startProcess(args, dname) + if res: + dia.exec_() self.committed.emit() if self.__forgotNames: model = e5App().getObject("Project").getModel() @@ -592,19 +572,7 @@ args.append('--template') args.append('{desc}') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) return output @@ -640,10 +608,7 @@ return False if noDialog: - if self.__client is None: - self.startSynchronizedProcess(QProcess(), 'hg', args, repodir) - else: - out, err = self.__client.runcommand(args) + out, err = self.__client.runcommand(args) res = False else: dia = HgDialog(self.tr( @@ -691,10 +656,7 @@ args.append(name) if noDialog: - if self.__client is None: - self.startSynchronizedProcess(QProcess(), 'hg', args, repodir) - else: - out, err = self.__client.runcommand(args) + out, err = self.__client.runcommand(args) else: dia = HgDialog( self.tr( @@ -758,12 +720,8 @@ return False if noDialog: - if self.__client is None: - res = self.startSynchronizedProcess( - QProcess(), 'hg', args, repodir) - else: - out, err = self.__client.runcommand(args) - res = err == "" + out, err = self.__client.runcommand(args) + res = err == "" else: dia = HgDialog( self.tr( @@ -819,12 +777,8 @@ return False if noDialog: - if self.__client is None: - res = self.startSynchronizedProcess( - QProcess(), 'hg', args, repodir) - else: - out, err = self.__client.runcommand(args) - res = err == "" + out, err = self.__client.runcommand(args) + res = err == "" else: dia = HgDialog(self.tr('Renaming {0}').format(name), self) res = dia.startProcess(args, repodir) @@ -1183,19 +1137,7 @@ args.append('--all') args.append('--noninteractive') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: for line in output.splitlines(): @@ -1251,19 +1193,7 @@ args.append('--all') args.append('--noninteractive') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(dname) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: dirs = [x for x in names.keys() if os.path.isdir(x)] @@ -1411,19 +1341,7 @@ args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@' '{date|isodate}@@@{branches}@@@{bookmarks}\n') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(ppath) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) infoBlock = [] if output: @@ -1470,18 +1388,7 @@ args = self.initCommand("showconfig") args.append('paths.default') - output = "" - if self.__client is None: - process.setWorkingDirectory(ppath) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: url = output.splitlines()[0].strip() @@ -1581,19 +1488,7 @@ args = self.initCommand("tags") args.append('--verbose') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) tagsList = [] if output: @@ -1630,19 +1525,7 @@ args = self.initCommand("branches") args.append('--closed') - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: self.branchesList = [] @@ -1768,39 +1651,7 @@ args.append(rev) args.append(name) - if self.__client is None: - output = "" - error = "" - - # find the root of the repo - repodir = self.splitPath(name)[0] - while not os.path.isdir(os.path.join(repodir, self.adminDir)): - repodir = os.path.dirname(repodir) - if os.path.splitdrive(repodir)[1] == os.sep: - return "", "" - - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished: - if process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - error = str(process.readAllStandardError(), - self.getEncoding(), 'replace') - else: - error = self.tr( - "The hg process did not finish within 30s.") - else: - error = self.tr( - 'The process {0} could not be started. ' - 'Ensure, that it is in the search path.').format('hg') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) # return file contents with 'universal newlines' return output.replace('\r\n', '\n').replace('\r', '\n'), error @@ -2032,26 +1883,7 @@ args.append('{rev}:{node|short}@@@{tags}@@@{author|xmlescape}@@@' '{date|isodate}@@@{branches}@@@{parents}@@@{bookmarks}\n') - output = "" - if self.__client is None: - # find the root of the repo - repodir = self.splitPath(ppath)[0] - while not os.path.isdir(os.path.join(repodir, self.adminDir)): - repodir = os.path.dirname(repodir) - if os.path.splitdrive(repodir)[1] == os.sep: - return - - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: index = 0 @@ -2263,19 +2095,7 @@ """ args = self.initCommand("branch") - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) return output.strip() @@ -3356,19 +3176,7 @@ args = self.initCommand("showconfig") args.append('paths') - output = "" - if self.__client is None: - process = QProcess() - self.__repoDir and process.setWorkingDirectory(self.__repoDir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) self.__defaultConfigured = False self.__defaultPushConfigured = False @@ -3406,19 +3214,7 @@ args = self.initCommand("identify") - output = "" - if self.__client is None: - process = QProcess() - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) return output.count('+') == 2 @@ -3453,7 +3249,6 @@ self.tr( """<p>The Mercurial Command Server could not be""" """ restarted.</p><p>Reason: {0}</p>""").format(err)) - self.__client = None self.__getExtensionsInfo() @@ -3498,19 +3293,7 @@ args = self.initCommand("showconfig") args.append('extensions') - output = "" - if self.__client is None: - process = QProcess() - self.__repoDir and process.setWorkingDirectory(self.__repoDir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - self.getEncoding(), 'replace') - else: - output, error = self.__client.runcommand(args) + output, error = self.__client.runcommand(args) if output: for line in output.splitlines(): @@ -3587,21 +3370,46 @@ self.__monitorRepoIniFile(project.getProjectPath()) if repodir: - from .HgClient import HgClient - client = HgClient(repodir, "utf-8", self) - ok, err = client.startServer() - if ok: - self.__client = client - else: - E5MessageBox.warning( - None, - self.tr("Mercurial Command Server"), - self.tr( - """<p>The Mercurial Command Server could not be""" - """ started.</p><p>Reason: {0}</p>""").format(err)) + self.__createClient(repodir) return self.__projectHelper - + + ########################################################################### + ## Methods to handle the Mercurial command server are below. + ########################################################################### + + def __createClient(self, repodir=""): + """ + Private method to create a Mercurial command server client. + + @param repodir path of the local repository + @type str + """ + if self.__client is not None: + self.__client.stopServer() + self.__client = None + + self.__client = HgClient(repodir, "utf-8", self) + ok, err = self.__client.startServer() + if not ok: + E5MessageBox.warning( + None, + self.tr("Mercurial Command Server"), + self.tr( + """<p>The Mercurial Command Server could not be""" + """ started.</p><p>Reason: {0}</p>""").format(err)) + + def getClient(self): + """ + Public method to get a reference to the command server interface. + + @return reference to the client (HgClient) + """ + if self.__client is None: + self.__createClient(self.__repoDir) + + return self.__client + ########################################################################### ## Status Monitor Thread methods ###########################################################################