comparison mercurial/templatekw.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 f0b6fbea00cf
children 45987e2b64f0
comparison
equal deleted inserted replaced
37102:638a241202a3 37103:be3f33f5e232
581 ctx = context.resource(mapping, 'ctx') 581 ctx = context.resource(mapping, 'ctx')
582 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node())) 582 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
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], 'revcache': {}}, 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'})
590 def showreporoot(context, mapping): 590 def showreporoot(context, mapping):
591 """String. The root directory of the current repository.""" 591 """String. The root directory of the current repository."""
605 ssets = obsutil.successorssets(repo, ctx.node(), closest=True) 605 ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
606 ssets = [[hex(n) for n in ss] for ss in ssets] 606 ssets = [[hex(n) for n in ss] for ss in ssets]
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], 'revcache': {}}, 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
614 # Format the successorssets 614 # Format the successorssets
615 def render(d): 615 def render(d):
645 # Format successors 645 # Format successors
646 successors = i['successors'] 646 successors = i['successors']
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], 'revcache': {}}, 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
654 finalmarkers = [] 654 finalmarkers = []
655 for m in i['markers']: 655 for m in i['markers']:
708 parents = [[('rev', p.rev()), 708 parents = [[('rev', p.rev()),
709 ('node', p.hex()), 709 ('node', p.hex()),
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], 'revcache': {}}, 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'})
717 def showphase(context, mapping): 717 def showphase(context, mapping):
718 """String. The changeset phase name.""" 718 """String. The changeset phase name."""
735 """helper to generate a list of revisions in which a mapped template will 735 """helper to generate a list of revisions in which a mapped template will
736 be evaluated""" 736 be evaluated"""
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], 'revcache': {}}, 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'})
744 def showsubrepos(context, mapping): 744 def showsubrepos(context, mapping):
745 """List of strings. Updated subrepositories in the changeset.""" 745 """List of strings. Updated subrepositories in the changeset."""