Patchwork D3460: shortest: extract function for checking if a prefix is a revnum

login
register
mail settings
Submitter phabricator
Date May 8, 2018, 12:47 p.m.
Message ID <25f735636cc3804b8140c7253d95da78@localhost.localdomain>
Download mbox | patch
Permalink /patch/31339/
State Not Applicable
Headers show

Comments

phabricator - May 8, 2018, 12:47 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG890bdf0e33c8: shortest: extract function for checking if a prefix is a revnum (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3460?vs=8485&id=8514

REVISION DETAIL
  https://phab.mercurial-scm.org/D3460

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS




To: martinvonz, indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -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