comparison mercurial/templatefuncs.py @ 44599:1f81f680912f

templater: remember cache key of evaluated revset This provides a hint for caching further computation result of the given revset. See the next patch for example.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 15 Mar 2020 16:00:45 +0900
parents fc1fa3a07af6
children 7cd5c0968139
comparison
equal deleted inserted replaced
44598:e3e44e6e7245 44599:1f81f680912f
656 def query(expr): 656 def query(expr):
657 m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo)) 657 m = revsetmod.match(repo.ui, expr, lookup=revsetmod.lookupfn(repo))
658 return m(repo) 658 return m(repo)
659 659
660 if len(args) > 1: 660 if len(args) > 1:
661 key = None # dynamically-created revs shouldn't be cached
661 formatargs = [evalfuncarg(context, mapping, a) for a in args[1:]] 662 formatargs = [evalfuncarg(context, mapping, a) for a in args[1:]]
662 revs = query(revsetlang.formatspec(raw, *formatargs)) 663 revs = query(revsetlang.formatspec(raw, *formatargs))
663 else: 664 else:
664 cache = context.resource(mapping, b'cache') 665 cache = context.resource(mapping, b'cache')
665 revsetcache = cache.setdefault(b"revsetcache", {}) 666 revsetcache = cache.setdefault(b"revsetcache", {})
666 if raw in revsetcache: 667 key = raw
667 revs = revsetcache[raw] 668 if key in revsetcache:
669 revs = revsetcache[key]
668 else: 670 else:
669 revs = query(raw) 671 revs = query(raw)
670 revsetcache[raw] = revs 672 revsetcache[key] = revs
671 return templateutil.revslist(repo, revs, name=b'revision') 673 return templateutil.revslist(repo, revs, name=b'revision', cachekey=key)
672 674
673 675
674 @templatefunc(b'rstdoc(text, style)') 676 @templatefunc(b'rstdoc(text, style)')
675 def rstdoc(context, mapping, args): 677 def rstdoc(context, mapping, args):
676 """Format reStructuredText.""" 678 """Format reStructuredText."""