##// END OF EJS Templates
shortest: cache disambiguation revset...
Martin von Zweigbergk -
r38889:3588e41f default
parent child Browse files
Show More
@@ -462,8 +462,12 b' def resolvehexnodeidprefix(repo, prefix)'
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.
@@ -491,7 +495,13 b' def shortesthexnodeidprefix(repo, node, '
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):
@@ -596,7 +596,7 b' def separate(context, mapping, args):'
596 yield sep
596 yield sep
597 yield argstr
597 yield argstr
598
598
599 @templatefunc('shortest(node, minlength=4)', requires={'repo'})
599 @templatefunc('shortest(node, minlength=4)', requires={'repo', 'cache'})
600 def shortest(context, mapping, args):
600 def shortest(context, mapping, args):
601 """Obtain the shortest representation of
601 """Obtain the shortest representation of
602 a node."""
602 a node."""
@@ -629,8 +629,9 b' def shortest(context, mapping, args):'
629 return hexnode
629 return hexnode
630 if not node:
630 if not node:
631 return hexnode
631 return hexnode
632 cache = context.resource(mapping, 'cache')
632 try:
633 try:
633 return scmutil.shortesthexnodeidprefix(repo, node, minlength)
634 return scmutil.shortesthexnodeidprefix(repo, node, minlength, cache)
634 except error.RepoLookupError:
635 except error.RepoLookupError:
635 return hexnode
636 return hexnode
636
637
General Comments 0
You need to be logged in to leave comments. Login now