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