Mercurial > hg
changeset 44591: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 | e3e44e6e7245 |
children | 7cd5c0968139 |
files | mercurial/templatefuncs.py mercurial/templateutil.py |
diffstat | 2 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatefuncs.py Sun Mar 15 22:01:38 2020 +0900 +++ b/mercurial/templatefuncs.py Sun Mar 15 16:00:45 2020 +0900 @@ -658,17 +658,19 @@ return m(repo) if len(args) > 1: + key = None # dynamically-created revs shouldn't be cached formatargs = [evalfuncarg(context, mapping, a) for a in args[1:]] revs = query(revsetlang.formatspec(raw, *formatargs)) else: cache = context.resource(mapping, b'cache') revsetcache = cache.setdefault(b"revsetcache", {}) - if raw in revsetcache: - revs = revsetcache[raw] + key = raw + if key in revsetcache: + revs = revsetcache[key] else: revs = query(raw) - revsetcache[raw] = revs - return templateutil.revslist(repo, revs, name=b'revision') + revsetcache[key] = revs + return templateutil.revslist(repo, revs, name=b'revision', cachekey=key) @templatefunc(b'rstdoc(text, style)')
--- a/mercurial/templateutil.py Sun Mar 15 22:01:38 2020 +0900 +++ b/mercurial/templateutil.py Sun Mar 15 16:00:45 2020 +0900 @@ -414,13 +414,18 @@ If name specified, the revs will be rendered with the old-style list template of the given name by default. + + The cachekey provides a hint to cache further computation on this + smartset. If the underlying smartset is dynamically created, the cachekey + should be None. """ - def __init__(self, repo, revs, name=None): + def __init__(self, repo, revs, name=None, cachekey=None): assert isinstance(revs, smartset.abstractsmartset) self._repo = repo self._revs = revs self._name = name + self.cachekey = cachekey def contains(self, context, mapping, item): rev = unwrapinteger(context, mapping, item)