mercurial/revlog.py
changeset 37863 6921d3ecadc1
parent 37862 858c7bfb3f49
child 37864 890bdf0e33c8
equal deleted inserted replaced
37862:858c7bfb3f49 37863:6921d3ecadc1
  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 isvalid(test):
  1505         def isvalid(prefix):
  1506             try:
  1506             try:
  1507                 if self._partialmatch(test) is None:
  1507                 if self._partialmatch(prefix) is None:
  1508                     return False
  1508                     return False
  1509             except error.RevlogError:
  1509             except error.RevlogError:
  1510                 return False
  1510                 return False
  1511             except error.WdirUnsupported:
  1511             except error.WdirUnsupported:
  1512                 # single 'ff...' match
  1512                 # single 'ff...' match
  1513                 return True
  1513                 return True
  1514             try:
  1514             try:
  1515                 i = int(test)
  1515                 i = int(prefix)
  1516                 # if we are a pure int, then starting with zero will not be
  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
  1517                 # confused as a rev; or, obviously, if the int is larger
  1518                 # than the value of the tip rev
  1518                 # than the value of the tip rev
  1519                 if test[0] == '0' or i > len(self):
  1519                 if prefix[0] == '0' or i > len(self):
  1520                     return True
  1520                     return True
  1521                 return False
  1521                 return False
  1522             except ValueError:
  1522             except ValueError:
  1523                 return True
  1523                 return True
  1524 
  1524 
  1525         hexnode = hex(node)
  1525         hexnode = hex(node)
  1526         shortest = hexnode
  1526         shortest = hexnode
  1527         startlength = max(6, minlength)
  1527         startlength = max(6, minlength)
  1528         length = startlength
  1528         length = startlength
  1529         while True:
  1529         while True:
  1530             test = hexnode[:length]
  1530             prefix = hexnode[:length]
  1531             if isvalid(test):
  1531             if isvalid(prefix):
  1532                 shortest = test
  1532                 shortest = prefix
  1533                 if length == minlength or length > startlength:
  1533                 if length == minlength or length > startlength:
  1534                     return shortest
  1534                     return shortest
  1535                 length -= 1
  1535                 length -= 1
  1536             else:
  1536             else:
  1537                 length += 1
  1537                 length += 1