Mercurial > hg
diff mercurial/formatter.py @ 37103:be3f33f5e232
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 15 Mar 2018 21:52:47 +0900 |
parents | 638a241202a3 |
children | 7db3c28dfdfd |
line wrap: on
line diff
--- 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())