Plugins/VcsPlugins/vcsMercurial/hg.py

changeset 5292
ac8b476ba122
parent 5284
3a2f9bee8974
child 5319
a512d3951a13
diff -r e93d14b48c34 -r ac8b476ba122 Plugins/VcsPlugins/vcsMercurial/hg.py
--- a/Plugins/VcsPlugins/vcsMercurial/hg.py	Sun Nov 06 13:39:36 2016 +0100
+++ b/Plugins/VcsPlugins/vcsMercurial/hg.py	Sun Nov 06 17:02:45 2016 +0100
@@ -15,7 +15,6 @@
 
 import os
 import shutil
-import re
 
 from PyQt5.QtCore import QProcess, pyqtSignal, QFileInfo, QFileSystemWatcher, \
     QCoreApplication
@@ -248,46 +247,16 @@
         """
         Public method used to test for the presence of the hg executable.
         
-        @return flag indicating the existance (boolean) and an error message
+        @return flag indicating the existence (boolean) and an error message
             (string)
         """
-        self.versionStr = ''
-        errMsg = ""
-        
-        args = self.initCommand("version")
-        process = QProcess()
-        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')
-                self.versionStr = output.splitlines()[0].split()[-1][0:-1]
-                v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?',
-                                  self.versionStr).groups())
-                for i in range(3):
-                    try:
-                        v[i] = int(v[i])
-                    except TypeError:
-                        v[i] = 0
-                    except IndexError:
-                        v.append(0)
-                self.version = tuple(v)
-                self.__getExtensionsInfo()
-                return True, errMsg
-            else:
-                if finished:
-                    errMsg = self.tr(
-                        "The hg process finished with the exit code {0}")\
-                        .format(process.exitCode())
-                else:
-                    errMsg = self.tr(
-                        "The hg process did not finish within 30s.")
-        else:
-            errMsg = self.tr("Could not start the hg executable.")
-        
-        return False, errMsg
+        from .HgUtilities import hgVersion
+        
+        self.versionStr, self.version, errMsg = hgVersion(self.__plugin)
+        hgExists = errMsg == ""
+        if hgExists:
+            self.__getExtensionsInfo()
+        return hgExists, errMsg
     
     def vcsInit(self, vcsDir, noDialog=False):
         """

eric ide

mercurial