Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

changeset 6529
1c2968f124b7
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
--- a/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py	Wed Oct 03 14:31:58 2018 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py	Wed Oct 03 17:33:40 2018 +0200
@@ -59,14 +59,7 @@
         """
         self.shouldUpdate = False
         
-        if self.__client is None and not self.__useCommandLine:
-            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
+        self.__initClient()
         
         # step 1: get overall status
         args = self.vcs.initCommand("status")
@@ -150,9 +143,76 @@
         return True, \
             self.tr("Mercurial status checked successfully")
     
+    def _getInfo(self):
+        """
+        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()
+        
+        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.")
+        
+        if error:
+            # ignore errors
+            return ""
+        
+        globalRev, localRev, branch = output.splitlines()[0].split()
+        if globalRev.endswith("+"):
+            globalRev = globalRev[:-1]
+        if localRev.endswith("+"):
+            localRev = localRev[:-1]
+        
+        return self.tr("{0} / {1}:{2}", "branch, local id, global id").format(
+            branch, localRev, globalRev)
+    
     def _shutdown(self):
         """
         Protected method performing shutdown actions.
         """
         if self.__client:
             self.__client.stopServer()
+
+    def __initClient(self):
+        """
+        Private method to initialize the Mercurial client.
+        """
+        if self.__client is None and not self.__useCommandLine:
+            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

eric ide

mercurial