##// END OF EJS Templates
shortest: move revnum-disambiguation out of revlog...
Martin von Zweigbergk -
r37990:3ac950cd default
parent child Browse files
Show More
@@ -1502,18 +1502,6 b' class revlog(object):'
1502 1502
1503 1503 def shortest(self, node, minlength=1):
1504 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 1505 def isvalid(prefix):
1518 1506 try:
1519 1507 node = self._partialmatch(prefix)
@@ -1532,9 +1520,10 b' class revlog(object):'
1532 1520 hexnode = hex(node)
1533 1521
1534 1522 def disambiguate(hexnode, minlength):
1523 """Disambiguate against wdirid."""
1535 1524 for length in range(minlength, 41):
1536 1525 prefix = hexnode[:length]
1537 if not isrev(prefix) and not maybewdir(prefix):
1526 if not maybewdir(prefix):
1538 1527 return prefix
1539 1528
1540 1529 if not getattr(self, 'filteredrevs', None):
@@ -449,8 +449,30 b' def shortesthexnodeidprefix(repo, node, '
449 449 # _partialmatch() of filtered changelog could take O(len(repo)) time,
450 450 # which would be unacceptably slow. so we look for hash collision in
451 451 # unfiltered space, which means some hashes may be slightly longer.
452 cl = repo.unfiltered().changelog
453
454 def isrev(prefix):
452 455 try:
453 return repo.unfiltered().changelog.shortest(node, minlength)
456 i = int(prefix)
457 # if we are a pure int, then starting with zero will not be
458 # confused as a rev; or, obviously, if the int is larger
459 # than the value of the tip rev
460 if prefix[0] == '0' or i > len(cl):
461 return False
462 return True
463 except ValueError:
464 return False
465
466 def disambiguate(prefix):
467 """Disambiguate against revnums."""
468 hexnode = hex(node)
469 for length in range(len(prefix), 41):
470 prefix = hexnode[:length]
471 if not isrev(prefix):
472 return prefix
473
474 try:
475 return disambiguate(cl.shortest(node, minlength))
454 476 except error.LookupError:
455 477 raise error.RepoLookupError()
456 478
General Comments 0
You need to be logged in to leave comments. Login now