##// END OF EJS Templates
templater: switch 'revcache' based on new mapping items...
Yuya Nishihara -
r37121:be3f33f5 default
parent child Browse files
Show More
@@ -909,7 +909,7 b' def rendertemplate(ctx, tmpl, props=None'
909 909 tres = formatter.templateresources(repo.ui, repo)
910 910 t = formatter.maketemplater(repo.ui, tmpl, defaults=templatekw.keywords,
911 911 resources=tres)
912 mapping = {'ctx': ctx, 'revcache': {}}
912 mapping = {'ctx': ctx}
913 913 if props:
914 914 mapping.update(props)
915 915 return t.renderdefault(mapping)
@@ -394,14 +394,7 b' class templateformatter(baseformatter):'
394 394 if part not in self._parts:
395 395 return
396 396 ref = self._parts[part]
397
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))
397 self._out.write(self._t.render(ref, item))
405 398
406 399 def end(self):
407 400 baseformatter.end(self)
@@ -518,7 +511,10 b' class templateresources(templater.resour'
518 511 return get(self, context, mapping, key)
519 512
520 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 519 def _getsome(self, context, mapping, key):
524 520 v = mapping.get(key)
@@ -526,6 +522,9 b' class templateresources(templater.resour'
526 522 return v
527 523 return self._resmap.get(key)
528 524
525 def _hasctx(self, mapping):
526 return 'ctx' in mapping or 'fctx' in mapping
527
529 528 def _getctx(self, context, mapping, key):
530 529 ctx = mapping.get('ctx')
531 530 if ctx is not None:
@@ -545,7 +544,7 b' class templateresources(templater.resour'
545 544 'ctx': _getctx,
546 545 'fctx': _getsome,
547 546 'repo': _getrepo,
548 'revcache': _getsome, # per-ctx cache; set later
547 'revcache': _getsome,
549 548 'ui': _getsome,
550 549 }
551 550 _knownkeys = set(_gettermap.keys())
@@ -392,7 +392,6 b' def commonentry(repo, ctx):'
392 392 # filectx, but I'm not pretty sure if that would always work because
393 393 # fctx.parents() != fctx.changectx.parents() for example.
394 394 'ctx': ctx,
395 'revcache': {},
396 395 'rev': ctx.rev(),
397 396 'node': hex(node),
398 397 'author': ctx.user(),
@@ -288,7 +288,7 b' class changesetprinter(object):'
288 288 t = formatter.maketemplater(self.repo.ui, '{join(obsfate, "\n")}',
289 289 defaults=templatekw.keywords,
290 290 resources=tres)
291 obsfate = t.renderdefault({'ctx': ctx, 'revcache': {}}).splitlines()
291 obsfate = t.renderdefault({'ctx': ctx}).splitlines()
292 292
293 293 if obsfate:
294 294 for obsfateline in obsfate:
@@ -856,7 +856,7 b' def _graphnodeformatter(ui, displayer):'
856 856 templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords,
857 857 resources=tres)
858 858 def formatnode(repo, ctx):
859 props = {'ctx': ctx, 'repo': repo, 'revcache': {}}
859 props = {'ctx': ctx, 'repo': repo}
860 860 return templ.renderdefault(props)
861 861 return formatnode
862 862
@@ -583,7 +583,7 b' def showpredecessors(context, mapping):'
583 583 predecessors = map(hex, predecessors)
584 584
585 585 return _hybrid(None, predecessors,
586 lambda x: {'ctx': repo[x], 'revcache': {}},
586 lambda x: {'ctx': repo[x]},
587 587 lambda x: scmutil.formatchangeid(repo[x]))
588 588
589 589 @templatekeyword('reporoot', requires={'repo'})
@@ -607,7 +607,7 b' def showsuccessorssets(context, mapping)'
607 607
608 608 data = []
609 609 for ss in ssets:
610 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
610 h = _hybrid(None, ss, lambda x: {'ctx': repo[x]},
611 611 lambda x: scmutil.formatchangeid(repo[x]))
612 612 data.append(h)
613 613
@@ -647,7 +647,7 b' def showsuccsandmarkers(context, mapping'
647 647
648 648 successors = [hex(n) for n in successors]
649 649 successors = _hybrid(None, successors,
650 lambda x: {'ctx': repo[x], 'revcache': {}},
650 lambda x: {'ctx': repo[x]},
651 651 lambda x: scmutil.formatchangeid(repo[x]))
652 652
653 653 # Format markers
@@ -710,7 +710,7 b' def showparents(context, mapping):'
710 710 ('phase', p.phasestr())]
711 711 for p in pctxs]
712 712 f = _showcompatlist(context, mapping, 'parent', parents)
713 return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}},
713 return _hybrid(f, prevs, lambda x: {'ctx': repo[x]},
714 714 lambda x: scmutil.formatchangeid(repo[x]), keytype=int)
715 715
716 716 @templatekeyword('phase', requires={'ctx'})
@@ -737,7 +737,7 b' def showrevslist(context, mapping, name,'
737 737 repo = context.resource(mapping, 'repo')
738 738 f = _showcompatlist(context, mapping, name, ['%d' % r for r in revs])
739 739 return _hybrid(f, revs,
740 lambda x: {name: x, 'ctx': repo[x], 'revcache': {}},
740 lambda x: {name: x, 'ctx': repo[x]},
741 741 pycompat.identity, keytype=int)
742 742
743 743 @templatekeyword('subrepos', requires={'ctx'})
General Comments 0
You need to be logged in to leave comments. Login now