Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 37906:858c7bfb3f49
shortest: move some safe code out of exception block
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.
Differential Revision: https://phab.mercurial-scm.org/D3458
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 02 May 2018 22:49:06 -0700 |
parents | ee3d58b4a47f |
children | 6921d3ecadc1 |
comparison
equal
deleted
inserted
replaced
37905:a9d9802d577e | 37906:858c7bfb3f49 |
---|---|
1504 """Find the shortest unambiguous prefix that matches node.""" | 1504 """Find the shortest unambiguous prefix that matches node.""" |
1505 def isvalid(test): | 1505 def isvalid(test): |
1506 try: | 1506 try: |
1507 if self._partialmatch(test) is None: | 1507 if self._partialmatch(test) is None: |
1508 return False | 1508 return False |
1509 | |
1510 try: | |
1511 i = int(test) | |
1512 # if we are a pure int, then starting with zero will not be | |
1513 # confused as a rev; or, obviously, if the int is larger | |
1514 # than the value of the tip rev | |
1515 if test[0] == '0' or i > len(self): | |
1516 return True | |
1517 return False | |
1518 except ValueError: | |
1519 return True | |
1520 except error.RevlogError: | 1509 except error.RevlogError: |
1521 return False | 1510 return False |
1522 except error.WdirUnsupported: | 1511 except error.WdirUnsupported: |
1523 # single 'ff...' match | 1512 # single 'ff...' match |
1513 return True | |
1514 try: | |
1515 i = int(test) | |
1516 # if we are a pure int, then starting with zero will not be | |
1517 # confused as a rev; or, obviously, if the int is larger | |
1518 # than the value of the tip rev | |
1519 if test[0] == '0' or i > len(self): | |
1520 return True | |
1521 return False | |
1522 except ValueError: | |
1524 return True | 1523 return True |
1525 | 1524 |
1526 hexnode = hex(node) | 1525 hexnode = hex(node) |
1527 shortest = hexnode | 1526 shortest = hexnode |
1528 startlength = max(6, minlength) | 1527 startlength = max(6, minlength) |