D3460: shortest: extract function for checking if a prefix is a revnum
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon May 7 16:56:03 UTC 2018
martinvonz created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
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.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D3460
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
@@ -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
To: martinvonz, indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list