src/eric7/Plugins/VcsPlugins/vcsMercurial/HgUtilities.py

branch
eric7
changeset 11076
2989645b2618
parent 10439
21c28b0f9e41
child 11080
92cd5f094e7a
diff -r 282fc28b44ee -r 2989645b2618 src/eric7/Plugins/VcsPlugins/vcsMercurial/HgUtilities.py
--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgUtilities.py	Tue Dec 03 14:21:36 2024 +0100
+++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgUtilities.py	Tue Dec 03 17:46:41 2024 +0100
@@ -14,6 +14,12 @@
 
 from eric7.SystemUtilities import OSUtilities, PythonUtilities
 
+# progress bar            topic, bar (ignored), value, maximum, estimate
+progressRe = re.compile(r"(\w+)\s+(?:\[[=> ]*\])\s+(\d+)/(\d+)\s+(\w+)")
+
+# version                   major, minor, patch, additional
+versionRe = re.compile(r".*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?")
+
 
 def getHgExecutable():
     """
@@ -67,7 +73,7 @@
     @type str
     """
     env = QProcessEnvironment.systemEnvironment()
-    env.insert("HGPLAIN", "1")
+    env.insert("HGPLAINEXCEPT", "progress")
 
     # set the encoding for the process
     if encoding:
@@ -110,11 +116,7 @@
                 "replace",
             )
             versionStr = output.splitlines()[0].split()[-1][0:-1]
-            v = list(
-                re.match(
-                    r".*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?", versionStr
-                ).groups()
-            )
+            v = list(versionRe.match(versionStr).groups())
             if v[-1] is None:
                 del v[-1]
             for i in range(3):
@@ -140,3 +142,37 @@
         )
 
     return versionStr, version, errorMsg
+
+
+def isProgressInfo(line):
+    """
+    Function to check, if the given line contains progress information.
+
+    @param line output line to be checked
+    @type str
+    @return flag indicating a line containing progress information
+    @rtype bool
+    """
+    return progressRe.match(line.strip()) is not None
+
+
+def parseProgressInfo(progressLine):
+    """
+    Function to parse an output line containing progress information.
+
+    @param progressLine progress information line to be parsed
+    @type str
+    @return tuple containing the progress topic, current value, maximum value and
+        the completion estimate
+    @rtype tuple of (str, int, int, str)
+    """
+    match = progressRe.match(progressLine)
+    if match is not None:
+        return (
+            match[1],  # topic
+            int(match[2]),  # value
+            int(match[3]),  # maximum
+            match[4],  # estimate
+        )
+    else:
+        return "", 0, 0, ""

eric ide

mercurial