# HG changeset patch # User Yuya Nishihara # Date 1521118367 -32400 # Node ID be3f33f5e232512a8b128720579feda239191376 # Parent 638a241202a326c8ec2761c5f6957fb7e77463e5 templater: switch 'revcache' based on new mapping items It was pretty easy to leave a stale 'revcache' when switching 'ctx'. Let's make it be automatically replaced. diff -r 638a241202a3 -r be3f33f5e232 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Thu Mar 15 21:49:33 2018 +0900 +++ b/mercurial/cmdutil.py Thu Mar 15 21:52:47 2018 +0900 @@ -909,7 +909,7 @@ tres = formatter.templateresources(repo.ui, repo) t = formatter.maketemplater(repo.ui, tmpl, defaults=templatekw.keywords, resources=tres) - mapping = {'ctx': ctx, 'revcache': {}} + mapping = {'ctx': ctx} if props: mapping.update(props) return t.renderdefault(mapping) diff -r 638a241202a3 -r be3f33f5e232 mercurial/formatter.py --- a/mercurial/formatter.py Thu Mar 15 21:49:33 2018 +0900 +++ b/mercurial/formatter.py Thu Mar 15 21:52:47 2018 +0900 @@ -394,14 +394,7 @@ if part not in self._parts: return ref = self._parts[part] - - props = {} - # explicitly-defined fields precede templatekw - props.update(item) - if 'ctx' in item or 'fctx' in item: - # but template resources must be always available - props['revcache'] = {} - self._out.write(self._t.render(ref, props)) + self._out.write(self._t.render(ref, item)) def end(self): baseformatter.end(self) @@ -518,7 +511,10 @@ return get(self, context, mapping, key) def populatemap(self, context, origmapping, newmapping): - return {} + mapping = {} + if self._hasctx(newmapping): + mapping['revcache'] = {} # per-ctx cache + return mapping def _getsome(self, context, mapping, key): v = mapping.get(key) @@ -526,6 +522,9 @@ return v return self._resmap.get(key) + def _hasctx(self, mapping): + return 'ctx' in mapping or 'fctx' in mapping + def _getctx(self, context, mapping, key): ctx = mapping.get('ctx') if ctx is not None: @@ -545,7 +544,7 @@ 'ctx': _getctx, 'fctx': _getsome, 'repo': _getrepo, - 'revcache': _getsome, # per-ctx cache; set later + 'revcache': _getsome, 'ui': _getsome, } _knownkeys = set(_gettermap.keys()) diff -r 638a241202a3 -r be3f33f5e232 mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py Thu Mar 15 21:49:33 2018 +0900 +++ b/mercurial/hgweb/webutil.py Thu Mar 15 21:52:47 2018 +0900 @@ -392,7 +392,6 @@ # filectx, but I'm not pretty sure if that would always work because # fctx.parents() != fctx.changectx.parents() for example. 'ctx': ctx, - 'revcache': {}, 'rev': ctx.rev(), 'node': hex(node), 'author': ctx.user(), diff -r 638a241202a3 -r be3f33f5e232 mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py Thu Mar 15 21:49:33 2018 +0900 +++ b/mercurial/logcmdutil.py Thu Mar 15 21:52:47 2018 +0900 @@ -288,7 +288,7 @@ t = formatter.maketemplater(self.repo.ui, '{join(obsfate, "\n")}', defaults=templatekw.keywords, resources=tres) - obsfate = t.renderdefault({'ctx': ctx, 'revcache': {}}).splitlines() + obsfate = t.renderdefault({'ctx': ctx}).splitlines() if obsfate: for obsfateline in obsfate: @@ -856,7 +856,7 @@ templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords, resources=tres) def formatnode(repo, ctx): - props = {'ctx': ctx, 'repo': repo, 'revcache': {}} + props = {'ctx': ctx, 'repo': repo} return templ.renderdefault(props) return formatnode diff -r 638a241202a3 -r be3f33f5e232 mercurial/templatekw.py --- a/mercurial/templatekw.py Thu Mar 15 21:49:33 2018 +0900 +++ b/mercurial/templatekw.py Thu Mar 15 21:52:47 2018 +0900 @@ -583,7 +583,7 @@ predecessors = map(hex, predecessors) return _hybrid(None, predecessors, - lambda x: {'ctx': repo[x], 'revcache': {}}, + lambda x: {'ctx': repo[x]}, lambda x: scmutil.formatchangeid(repo[x])) @templatekeyword('reporoot', requires={'repo'}) @@ -607,7 +607,7 @@ data = [] for ss in ssets: - h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}}, + h = _hybrid(None, ss, lambda x: {'ctx': repo[x]}, lambda x: scmutil.formatchangeid(repo[x])) data.append(h) @@ -647,7 +647,7 @@ successors = [hex(n) for n in successors] successors = _hybrid(None, successors, - lambda x: {'ctx': repo[x], 'revcache': {}}, + lambda x: {'ctx': repo[x]}, lambda x: scmutil.formatchangeid(repo[x])) # Format markers @@ -710,7 +710,7 @@ ('phase', p.phasestr())] for p in pctxs] f = _showcompatlist(context, mapping, 'parent', parents) - return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, + return _hybrid(f, prevs, lambda x: {'ctx': repo[x]}, lambda x: scmutil.formatchangeid(repo[x]), keytype=int) @templatekeyword('phase', requires={'ctx'}) @@ -737,7 +737,7 @@ repo = context.resource(mapping, 'repo') f = _showcompatlist(context, mapping, name, ['%d' % r for r in revs]) return _hybrid(f, revs, - lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, + lambda x: {name: x, 'ctx': repo[x]}, pycompat.identity, keytype=int) @templatekeyword('subrepos', requires={'ctx'})