comparison mercurial/templatefuncs.py @ 38853:3588e41f796d

shortest: cache disambiguation revset This makes it actually useful. In compared the time in my hg repo with 69.6k revisions and with a disambiguation revset of "not public()" that matches 563 visible revisions. I ran "time hg log -T '{shortest(node1,)}' -r 0:1000" (no revisions within the revset in that revision range). Before this patch, it took 57s and after it took 0.7s. Differential Revision: https://phab.mercurial-scm.org/D4039
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 17 Apr 2018 11:16:59 -0700
parents bc8d925342f0
children a2a5d4ad5276
comparison
equal deleted inserted replaced
38852:a3dacabd476b 38853:3588e41f796d
594 first = False 594 first = False
595 else: 595 else:
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."""
603 if not (1 <= len(args) <= 2): 603 if not (1 <= len(args) <= 2):
604 # i18n: "shortest" is a keyword 604 # i18n: "shortest" is a keyword
627 node = wdirid 627 node = wdirid
628 except error.LookupError: 628 except error.LookupError:
629 return hexnode 629 return hexnode
630 if not node: 630 if not node:
631 return hexnode 631 return hexnode
632 try: 632 cache = context.resource(mapping, 'cache')
633 return scmutil.shortesthexnodeidprefix(repo, node, minlength) 633 try:
634 return scmutil.shortesthexnodeidprefix(repo, node, minlength, cache)
634 except error.RepoLookupError: 635 except error.RepoLookupError:
635 return hexnode 636 return hexnode
636 637
637 @templatefunc('strip(text[, chars])') 638 @templatefunc('strip(text[, chars])')
638 def strip(context, mapping, args): 639 def strip(context, mapping, args):