shortest: extract function for checking if a prefix is a revnum
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 02 May 2018 22:56:10 -0700
changeset 37864 890bdf0e33c8
parent 37863 6921d3ecadc1
child 37865 da083d9fafab
shortest: extract function for checking if a prefix is a revnum Much of isvalid() was about testing if a prefix is a valid revnum. I want to reuse that soon, so let's move it out. There is no significant slowdown from the function call overhead. Differential Revision: https://phab.mercurial-scm.org/D3460
mercurial/revlog.py
--- a/mercurial/revlog.py	Thu May 03 10:12:47 2018 -0700
+++ b/mercurial/revlog.py	Wed May 02 22:56:10 2018 -0700
@@ -1502,6 +1502,18 @@
 
     def shortest(self, node, minlength=1):
         """Find the shortest unambiguous prefix that matches node."""
+        def isrev(prefix):
+            try:
+                i = int(prefix)
+                # if we are a pure int, then starting with zero will not be
+                # confused as a rev; or, obviously, if the int is larger
+                # than the value of the tip rev
+                if prefix[0] == '0' or i > len(self):
+                    return False
+                return True
+            except ValueError:
+                return False
+
         def isvalid(prefix):
             try:
                 if self._partialmatch(prefix) is None:
@@ -1511,16 +1523,7 @@
             except error.WdirUnsupported:
                 # single 'ff...' match
                 return True
-            try:
-                i = int(prefix)
-                # if we are a pure int, then starting with zero will not be
-                # confused as a rev; or, obviously, if the int is larger
-                # than the value of the tip rev
-                if prefix[0] == '0' or i > len(self):
-                    return True
-                return False
-            except ValueError:
-                return True
+            return not isrev(prefix)
 
         hexnode = hex(node)
         shortest = hexnode