mercurial/scmutil.py
changeset 38854 531b86cc8fb3
parent 38853 3588e41f796d
child 38855 7848f284b211
equal deleted inserted replaced
38853:3588e41f796d 38854:531b86cc8fb3
   460     if node is None:
   460     if node is None:
   461         return
   461         return
   462     repo.changelog.rev(node)  # make sure node isn't filtered
   462     repo.changelog.rev(node)  # make sure node isn't filtered
   463     return node
   463     return node
   464 
   464 
       
   465 def mayberevnum(repo, prefix):
       
   466     """Checks if the given prefix may be mistaken for a revision number"""
       
   467     try:
       
   468         i = int(prefix)
       
   469         # if we are a pure int, then starting with zero will not be
       
   470         # confused as a rev; or, obviously, if the int is larger
       
   471         # than the value of the tip rev
       
   472         if prefix[0:1] == b'0' or i > len(repo):
       
   473             return False
       
   474         return True
       
   475     except ValueError:
       
   476         return False
       
   477 
   465 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
   478 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
   466     """Find the shortest unambiguous prefix that matches hexnode.
   479     """Find the shortest unambiguous prefix that matches hexnode.
   467 
   480 
   468     If "cache" is not None, it must be a dictionary that can be used for
   481     If "cache" is not None, it must be a dictionary that can be used for
   469     caching between calls to this method.
   482     caching between calls to this method.
   470     """
   483     """
   471     # _partialmatch() of filtered changelog could take O(len(repo)) time,
   484     # _partialmatch() of filtered changelog could take O(len(repo)) time,
   472     # which would be unacceptably slow. so we look for hash collision in
   485     # which would be unacceptably slow. so we look for hash collision in
   473     # unfiltered space, which means some hashes may be slightly longer.
   486     # unfiltered space, which means some hashes may be slightly longer.
   474     cl = repo.unfiltered().changelog
       
   475 
       
   476     def isrev(prefix):
       
   477         try:
       
   478             i = int(prefix)
       
   479             # if we are a pure int, then starting with zero will not be
       
   480             # confused as a rev; or, obviously, if the int is larger
       
   481             # than the value of the tip rev
       
   482             if prefix[0:1] == b'0' or i > len(cl):
       
   483                 return False
       
   484             return True
       
   485         except ValueError:
       
   486             return False
       
   487 
   487 
   488     def disambiguate(prefix):
   488     def disambiguate(prefix):
   489         """Disambiguate against revnums."""
   489         """Disambiguate against revnums."""
   490         hexnode = hex(node)
   490         hexnode = hex(node)
   491         for length in range(len(prefix), len(hexnode) + 1):
   491         for length in range(len(prefix), len(hexnode) + 1):
   492             prefix = hexnode[:length]
   492             prefix = hexnode[:length]
   493             if not isrev(prefix):
   493             if not mayberevnum(repo, prefix):
   494                 return prefix
   494                 return prefix
   495 
   495 
       
   496     cl = repo.unfiltered().changelog
   496     revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
   497     revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
   497     if revset:
   498     if revset:
   498         revs = None
   499         revs = None
   499         if cache is not None:
   500         if cache is not None:
   500             revs = cache.get('disambiguationrevset')
   501             revs = cache.get('disambiguationrevset')