mercurial/scmutil.py
changeset 38853 3588e41f796d
parent 38843 6f7c9527030b
child 38854 531b86cc8fb3
equal deleted inserted replaced
38852:a3dacabd476b 38853:3588e41f796d
   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 shortesthexnodeidprefix(repo, node, minlength=1):
   465 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
   466     """Find the shortest unambiguous prefix that matches hexnode."""
   466     """Find the shortest unambiguous prefix that matches hexnode.
       
   467 
       
   468     If "cache" is not None, it must be a dictionary that can be used for
       
   469     caching between calls to this method.
       
   470     """
   467     # _partialmatch() of filtered changelog could take O(len(repo)) time,
   471     # _partialmatch() of filtered changelog could take O(len(repo)) time,
   468     # which would be unacceptably slow. so we look for hash collision in
   472     # which would be unacceptably slow. so we look for hash collision in
   469     # unfiltered space, which means some hashes may be slightly longer.
   473     # unfiltered space, which means some hashes may be slightly longer.
   470     cl = repo.unfiltered().changelog
   474     cl = repo.unfiltered().changelog
   471 
   475 
   489             if not isrev(prefix):
   493             if not isrev(prefix):
   490                 return prefix
   494                 return prefix
   491 
   495 
   492     revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
   496     revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
   493     if revset:
   497     if revset:
   494         revs = repo.anyrevs([revset], user=True)
   498         revs = None
       
   499         if cache is not None:
       
   500             revs = cache.get('disambiguationrevset')
       
   501         if revs is None:
       
   502             revs = repo.anyrevs([revset], user=True)
       
   503             if cache is not None:
       
   504                 cache['disambiguationrevset'] = revs
   495         if cl.rev(node) in revs:
   505         if cl.rev(node) in revs:
   496             hexnode = hex(node)
   506             hexnode = hex(node)
   497             for length in range(minlength, len(hexnode) + 1):
   507             for length in range(minlength, len(hexnode) + 1):
   498                 matches = []
   508                 matches = []
   499                 prefix = hexnode[:length]
   509                 prefix = hexnode[:length]