comparison mercurial/templatekw.py @ 33912:e278d6d2d7d2

template: add minimal obsfate template function The goal of this series is to have templates capable of displaying the evolution of a changeset in a clean and human-readable way. Add the succsandmarkers template return successors and markers so it can be used separately like this: > {succsandmarkers % "{get(succsandmarkers, "markers")|json};"} The following patches will add template functions that takes successors and markers as inputs and compute various obsfate fields from them.
author Boris Feld <boris.feld@octobus.net>
date Thu, 17 Aug 2017 18:26:11 +0200
parents af20468eb0a4
children 4647e0a8d3d7
comparison
equal deleted inserted replaced
33911:34e10e09afa5 33912:e278d6d2d7d2
672 yield "; ".join(render(d) for d in data) 672 yield "; ".join(render(d) for d in data)
673 673
674 return _hybrid(gen(data), data, lambda x: {'successorset': x}, 674 return _hybrid(gen(data), data, lambda x: {'successorset': x},
675 lambda d: d["successorset"]) 675 lambda d: d["successorset"])
676 676
677 @templatekeyword("succsandmarkers")
678 def showsuccsandmarkers(repo, ctx, **args):
679 """Returns a list of dict for each final successor of ctx.
680
681 The dict contains successors node id in "successors" keys and the list of
682 obs-markers from ctx to the set of successors in "markers"
683
684 (EXPERIMENTAL)
685 """
686
687 values = obsutil.successorsandmarkers(repo, ctx)
688
689 if values is None:
690 values = []
691
692 # Format successors and markers to avoid exposing binary to templates
693 data = []
694 for i in values:
695 # Format successors
696 successors = i['successors']
697
698 successors = [hex(n) for n in successors]
699 successors = _hybrid(None, successors,
700 lambda x: {'ctx': repo[x], 'revcache': {}},
701 lambda d: _formatrevnode(d['ctx']))
702
703 # Format markers
704 finalmarkers = []
705 for m in i['markers']:
706 hexprec = hex(m[0])
707 hexsucs = tuple(hex(n) for n in m[1])
708 hexparents = None
709 if m[5] is not None:
710 hexparents = tuple(hex(n) for n in m[5])
711 newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
712 finalmarkers.append(newmarker)
713
714 data.append({'successors': successors, 'markers': finalmarkers})
715
716 f = _showlist('succsandmarkers', data, args)
717 return _hybrid(f, data, lambda x: x, lambda d: d)
718
677 @templatekeyword('p1rev') 719 @templatekeyword('p1rev')
678 def showp1rev(repo, ctx, templ, **args): 720 def showp1rev(repo, ctx, templ, **args):
679 """Integer. The repository-local revision number of the changeset's 721 """Integer. The repository-local revision number of the changeset's
680 first parent, or -1 if the changeset has no parents.""" 722 first parent, or -1 if the changeset has no parents."""
681 return ctx.p1().rev() 723 return ctx.p1().rev()