Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
37102:638a241202a3 | 37103:be3f33f5e232 |
---|---|
392 | 392 |
393 def _renderitem(self, part, item): | 393 def _renderitem(self, part, item): |
394 if part not in self._parts: | 394 if part not in self._parts: |
395 return | 395 return |
396 ref = self._parts[part] | 396 ref = self._parts[part] |
397 | 397 self._out.write(self._t.render(ref, item)) |
398 props = {} | |
399 # explicitly-defined fields precede templatekw | |
400 props.update(item) | |
401 if 'ctx' in item or 'fctx' in item: | |
402 # but template resources must be always available | |
403 props['revcache'] = {} | |
404 self._out.write(self._t.render(ref, props)) | |
405 | 398 |
406 def end(self): | 399 def end(self): |
407 baseformatter.end(self) | 400 baseformatter.end(self) |
408 self._renderitem('docfooter', {}) | 401 self._renderitem('docfooter', {}) |
409 | 402 |
516 if not get: | 509 if not get: |
517 return None | 510 return None |
518 return get(self, context, mapping, key) | 511 return get(self, context, mapping, key) |
519 | 512 |
520 def populatemap(self, context, origmapping, newmapping): | 513 def populatemap(self, context, origmapping, newmapping): |
521 return {} | 514 mapping = {} |
515 if self._hasctx(newmapping): | |
516 mapping['revcache'] = {} # per-ctx cache | |
517 return mapping | |
522 | 518 |
523 def _getsome(self, context, mapping, key): | 519 def _getsome(self, context, mapping, key): |
524 v = mapping.get(key) | 520 v = mapping.get(key) |
525 if v is not None: | 521 if v is not None: |
526 return v | 522 return v |
527 return self._resmap.get(key) | 523 return self._resmap.get(key) |
524 | |
525 def _hasctx(self, mapping): | |
526 return 'ctx' in mapping or 'fctx' in mapping | |
528 | 527 |
529 def _getctx(self, context, mapping, key): | 528 def _getctx(self, context, mapping, key): |
530 ctx = mapping.get('ctx') | 529 ctx = mapping.get('ctx') |
531 if ctx is not None: | 530 if ctx is not None: |
532 return ctx | 531 return ctx |
543 _gettermap = { | 542 _gettermap = { |
544 'cache': _getsome, | 543 'cache': _getsome, |
545 'ctx': _getctx, | 544 'ctx': _getctx, |
546 'fctx': _getsome, | 545 'fctx': _getsome, |
547 'repo': _getrepo, | 546 'repo': _getrepo, |
548 'revcache': _getsome, # per-ctx cache; set later | 547 'revcache': _getsome, |
549 'ui': _getsome, | 548 'ui': _getsome, |
550 } | 549 } |
551 _knownkeys = set(_gettermap.keys()) | 550 _knownkeys = set(_gettermap.keys()) |
552 | 551 |
553 def formatter(ui, out, topic, opts): | 552 def formatter(ui, out, topic, opts): |