comparison mercurial/formatter.py @ 39583:ee1e74ee037c

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.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 01 Sep 2018 13:21:45 +0900
parents 28f974d83c0a
children 109b2c2d9942
comparison
equal deleted inserted replaced
39582:28f974d83c0a 39583:ee1e74ee037c
197 '''set of context object keys to be required given datafields set''' 197 '''set of context object keys to be required given datafields set'''
198 return set() 198 return set()
199 def context(self, **ctxs): 199 def context(self, **ctxs):
200 '''insert context objects to be used to render template keywords''' 200 '''insert context objects to be used to render template keywords'''
201 ctxs = pycompat.byteskwargs(ctxs) 201 ctxs = pycompat.byteskwargs(ctxs)
202 assert all(k in {'ctx', 'fctx'} for k in ctxs) 202 assert all(k in {'repo', 'ctx', 'fctx'} for k in ctxs)
203 if self._converter.storecontext: 203 if self._converter.storecontext:
204 # populate missing resources in fctx -> ctx -> repo order
205 if 'fctx' in ctxs and 'ctx' not in ctxs:
206 ctxs['ctx'] = ctxs['fctx'].changectx()
207 if 'ctx' in ctxs and 'repo' not in ctxs:
208 ctxs['repo'] = ctxs['ctx'].repo()
204 self._item.update(ctxs) 209 self._item.update(ctxs)
205 def datahint(self): 210 def datahint(self):
206 '''set of field names to be referenced''' 211 '''set of field names to be referenced'''
207 return set() 212 return set()
208 def data(self, **data): 213 def data(self, **data):
576 if v is not None: 581 if v is not None:
577 return v 582 return v
578 return self._resmap.get(key) 583 return self._resmap.get(key)
579 584
580 def _hasctx(self, mapping): 585 def _hasctx(self, mapping):
581 return 'ctx' in mapping or 'fctx' in mapping 586 return 'ctx' in mapping
582
583 def _getctx(self, mapping, key):
584 ctx = mapping.get('ctx')
585 if ctx is not None:
586 return ctx
587 fctx = mapping.get('fctx')
588 if fctx is not None:
589 return fctx.changectx()
590
591 def _getrepo(self, mapping, key):
592 ctx = self._getctx(mapping, 'ctx')
593 if ctx is not None:
594 return ctx.repo()
595 return self._getsome(mapping, key)
596 587
597 _gettermap = { 588 _gettermap = {
598 'cache': _getsome, 589 'cache': _getsome,
599 'ctx': _getctx, 590 'ctx': _getsome,
600 'fctx': _getsome, 591 'fctx': _getsome,
601 'repo': _getrepo, 592 'repo': _getsome,
602 'revcache': _getsome, 593 'revcache': _getsome,
603 'ui': _getsome, 594 'ui': _getsome,
604 } 595 }
605 _knownkeys = set(_gettermap.keys()) 596 _knownkeys = set(_gettermap.keys())
606 597