eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

changeset 7370
5fb53279f2df
parent 7360
9190402e4505
child 7923
91e843545d9a
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py	Wed Jan 08 19:13:57 2020 +0100
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py	Mon Jan 13 19:23:08 2020 +0100
@@ -7,9 +7,6 @@
 Module implementing the VCS status monitor thread class for Mercurial.
 """
 
-
-from PyQt5.QtCore import QProcess
-
 from VCS.StatusMonitorThread import VcsStatusMonitorThread
 
 
@@ -29,16 +26,15 @@
         VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
         
         self.__client = None
-        self.__useCommandLine = False
     
     def _performMonitor(self):
         """
         Protected method implementing the monitoring action.
         
-        This method populates the statusList member variable
-        with a list of strings giving the status in the first column and the
-        path relative to the project directory starting with the third column.
-        The allowed status flags are:
+        This method populates the statusList member variable with a list of
+        strings giving the status in the first column and the path relative
+        to the project directory starting with the third column. The allowed
+        status flags are:
         <ul>
             <li>"A" path was added but not yet comitted</li>
             <li>"M" path has local changes</li>
@@ -49,41 +45,22 @@
             <li>" " path is back at normal</li>
         </ul>
         
-        @return tuple of flag indicating successful operation (boolean) and
-            a status message in case of non successful operation (string)
+        @return tuple of flag indicating successful operation and a status
+            message in case of non successful operation
+        @rtype tuple of (bool, str)
         """
         self.shouldUpdate = False
         
-        self.__initClient()
+        ok, err = self.__initClient()
+        if not ok:
+            return False, err
         
         # step 1: get overall status
         args = self.vcs.initCommand("status")
         args.append('--noninteractive')
         args.append('--all')
         
-        output = ""
-        error = ""
-        if self.__client:
-            output, error = self.__client.runcommand(args)
-        else:
-            process = QProcess()
-            process.setWorkingDirectory(self.projectDir)
-            process.start('hg', args)
-            procStarted = process.waitForStarted(5000)
-            if procStarted:
-                finished = process.waitForFinished(300000)
-                if finished and process.exitCode() == 0:
-                    output = str(process.readAllStandardOutput(),
-                                 self.vcs.getEncoding(), 'replace')
-                else:
-                    process.kill()
-                    process.waitForFinished()
-                    error = str(process.readAllStandardError(),
-                                self.vcs.getEncoding(), 'replace')
-            else:
-                process.kill()
-                process.waitForFinished()
-                error = self.tr("Could not start the Mercurial process.")
+        output, error = self.__client.runcommand(args)
         
         if error:
             return False, error
@@ -103,19 +80,7 @@
         args = self.vcs.initCommand("resolve")
         args.append('--list')
         
-        output = ""
-        error = ""
-        if self.__client:
-            output, error = self.__client.runcommand(args)
-        else:
-            process.setWorkingDirectory(self.projectDir)
-            process.start('hg', args)
-            procStarted = process.waitForStarted(5000)
-            if procStarted:
-                finished = process.waitForFinished(300000)
-                if finished and process.exitCode() == 0:
-                    output = str(process.readAllStandardOutput(),
-                                 self.vcs.getEncoding(), 'replace')
+        output, error = self.__client.runcommand(args)
         
         for line in output.splitlines():
             flag, name = line.split(" ", 1)
@@ -144,42 +109,19 @@
         """
         Protected method implementing the real info action.
         
-        This method should be overridden and create a short info message to be
-        shown in the main window status bar right next to the status indicator.
-        
         @return short info message
         @rtype str
         """
-        self.__initClient()
+        ok, err = self.__initClient()
+        if not ok:
+            return ""
         
         args = self.vcs.initCommand("identify")
         args.append('--num')
         args.append('--id')
         args.append('--branch')
         
-        output = ""
-        error = ""
-        if self.__client:
-            output, error = self.__client.runcommand(args)
-        else:
-            process = QProcess()
-            process.setWorkingDirectory(self.projectDir)
-            process.start('hg', args)
-            procStarted = process.waitForStarted(5000)
-            if procStarted:
-                finished = process.waitForFinished(300000)
-                if finished and process.exitCode() == 0:
-                    output = str(process.readAllStandardOutput(),
-                                 self.vcs.getEncoding(), 'replace')
-                else:
-                    process.kill()
-                    process.waitForFinished()
-                    error = str(process.readAllStandardError(),
-                                self.vcs.getEncoding(), 'replace')
-            else:
-                process.kill()
-                process.waitForFinished()
-                error = self.tr("Could not start the Mercurial process.")
+        output, error = self.__client.runcommand(args)
         
         if error:
             # ignore errors
@@ -204,12 +146,18 @@
     def __initClient(self):
         """
         Private method to initialize the Mercurial client.
+        
+        @return tuple containing an OK flag and potentially an error message
+        @rtype tuple of (bool, str)
         """
-        if self.__client is None and not self.__useCommandLine:
+        if self.__client is None:
             from .HgClient import HgClient
             client = HgClient(self.projectDir, "utf-8", self.vcs)
             ok, err = client.startServer()
             if ok:
                 self.__client = client
-            else:
-                self.__useCommandLine = True
+        else:
+            ok = True
+            err = ""
+        
+        return ok, err

eric ide

mercurial