D3458: shortest: move some safe code out of exception block

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon May 7 12:55:58 EDT 2018


martinvonz created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The RevlogError and WdirUnsupported could be raised by
  _partialmatch(), but not by the rest of isvalid(), so let's move the
  rest out to make it clearer.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1506,22 +1506,21 @@
             try:
                 if self._partialmatch(test) is None:
                     return False
-
-                try:
-                    i = int(test)
-                    # 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 test[0] == '0' or i > len(self):
-                        return True
-                    return False
-                except ValueError:
-                    return True
             except error.RevlogError:
                 return False
             except error.WdirUnsupported:
                 # single 'ff...' match
                 return True
+            try:
+                i = int(test)
+                # 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 test[0] == '0' or i > len(self):
+                    return True
+                return False
+            except ValueError:
+                return True
 
         hexnode = hex(node)
         shortest = hexnode



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


More information about the Mercurial-devel mailing list