comparison mercurial/revlog.py @ 37971:3ac950cd5978

shortest: move revnum-disambiguation out of revlog I want to be able to change how we disambiguate and I think having revlog.shortest() worry only about finding a prefix that's unambiguous among nodeids makes more sense. This slows down `hg log -T '{shortest(node,1)}\n'` from 4.0s to 4.1s. Differential Revision: https://phab.mercurial-scm.org/D3502
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 03 May 2018 15:57:12 -0700
parents 76e933e0ccc9
children a4942675de6b
comparison
equal deleted inserted replaced
37970:76e933e0ccc9 37971:3ac950cd5978
1500 1500
1501 raise LookupError(id, self.indexfile, _('no match found')) 1501 raise LookupError(id, self.indexfile, _('no match found'))
1502 1502
1503 def shortest(self, node, minlength=1): 1503 def shortest(self, node, minlength=1):
1504 """Find the shortest unambiguous prefix that matches node.""" 1504 """Find the shortest unambiguous prefix that matches node."""
1505 def isrev(prefix):
1506 try:
1507 i = int(prefix)
1508 # if we are a pure int, then starting with zero will not be
1509 # confused as a rev; or, obviously, if the int is larger
1510 # than the value of the tip rev
1511 if prefix[0] == '0' or i > len(self):
1512 return False
1513 return True
1514 except ValueError:
1515 return False
1516
1517 def isvalid(prefix): 1505 def isvalid(prefix):
1518 try: 1506 try:
1519 node = self._partialmatch(prefix) 1507 node = self._partialmatch(prefix)
1520 except error.RevlogError: 1508 except error.RevlogError:
1521 return False 1509 return False
1530 return all(c == 'f' for c in prefix) 1518 return all(c == 'f' for c in prefix)
1531 1519
1532 hexnode = hex(node) 1520 hexnode = hex(node)
1533 1521
1534 def disambiguate(hexnode, minlength): 1522 def disambiguate(hexnode, minlength):
1523 """Disambiguate against wdirid."""
1535 for length in range(minlength, 41): 1524 for length in range(minlength, 41):
1536 prefix = hexnode[:length] 1525 prefix = hexnode[:length]
1537 if not isrev(prefix) and not maybewdir(prefix): 1526 if not maybewdir(prefix):
1538 return prefix 1527 return prefix
1539 1528
1540 if not getattr(self, 'filteredrevs', None): 1529 if not getattr(self, 'filteredrevs', None):
1541 try: 1530 try:
1542 length = max(self.index.shortest(node), minlength) 1531 length = max(self.index.shortest(node), minlength)