# HG changeset patch # User Yuya Nishihara # Date 1535775705 -32400 # Node ID ee1e74ee037c1c3df959bdcc39117dc2b76f6667 # Parent 28f974d83c0a7cf88745c6bcf79f22a48df28dd9 formatter: fill missing resources by formatter, not by resource mapper While working on demand loading of ctx/fctx objects, I found it's weird to support lookup in both directions. For instance, fctx can be loaded from (ctx, path) pair, but ctx may also be derived from fctx.changectx() in the original mapping. If the original mapping has had fctx but no ctx, and if the new mapping provides {path}, we can't be sure if fctx should be updated by fctx'.changectx()[path] or not. This patch simply drops the support for the resolution in fctx -> ctx -> repo direction. diff -r 28f974d83c0a -r ee1e74ee037c mercurial/formatter.py --- a/mercurial/formatter.py Thu Jun 07 23:27:54 2018 +0900 +++ b/mercurial/formatter.py Sat Sep 01 13:21:45 2018 +0900 @@ -199,8 +199,13 @@ def context(self, **ctxs): '''insert context objects to be used to render template keywords''' ctxs = pycompat.byteskwargs(ctxs) - assert all(k in {'ctx', 'fctx'} for k in ctxs) + assert all(k in {'repo', 'ctx', 'fctx'} for k in ctxs) if self._converter.storecontext: + # populate missing resources in fctx -> ctx -> repo order + if 'fctx' in ctxs and 'ctx' not in ctxs: + ctxs['ctx'] = ctxs['fctx'].changectx() + if 'ctx' in ctxs and 'repo' not in ctxs: + ctxs['repo'] = ctxs['ctx'].repo() self._item.update(ctxs) def datahint(self): '''set of field names to be referenced''' @@ -578,27 +583,13 @@ return self._resmap.get(key) def _hasctx(self, mapping): - return 'ctx' in mapping or 'fctx' in mapping - - def _getctx(self, mapping, key): - ctx = mapping.get('ctx') - if ctx is not None: - return ctx - fctx = mapping.get('fctx') - if fctx is not None: - return fctx.changectx() - - def _getrepo(self, mapping, key): - ctx = self._getctx(mapping, 'ctx') - if ctx is not None: - return ctx.repo() - return self._getsome(mapping, key) + return 'ctx' in mapping _gettermap = { 'cache': _getsome, - 'ctx': _getctx, + 'ctx': _getsome, 'fctx': _getsome, - 'repo': _getrepo, + 'repo': _getsome, 'revcache': _getsome, 'ui': _getsome, }