Mercurial > evolve
diff hgext3rd/evolve/templatekw.py @ 2486:cd4290f923b7
template: add precursors template
The precursors templates display the closest visible precursors of each
changeset, we may have gap, like in this case:
A -> B -> C
If we display A and C but not B, we can't display than B is the closest
precursor of C because it's not displayed. We display A as the closest
precursor of C instead.
Add a new test file as we will need to generate theses gaps and modifying
test-evolve-obshistory.t will lead to many unrelated lines changes.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 26 May 2017 10:05:27 +0200 |
parents | e6ecd35e99ec |
children | 590da9c523ae |
line wrap: on
line diff
--- a/hgext3rd/evolve/templatekw.py Fri May 26 16:00:05 2017 +0200 +++ b/hgext3rd/evolve/templatekw.py Fri May 26 10:05:27 2017 +0200 @@ -14,6 +14,7 @@ from mercurial import ( templatekw, + node, ) eh = exthelper.exthelper() @@ -41,3 +42,35 @@ except TypeError: return templatekw.showlist('trouble', ctx.troubles(), plural='troubles', **args) + +def closestprecursors(repo, nodeid): + """ Yield the list of next precursors pointing on visible changectx nodes + """ + + precursors = repo.obsstore.precursors + stack = [nodeid] + + while stack: + current = stack.pop() + currentpreccs = precursors.get(current, ()) + + for prec in currentpreccs: + precnodeid = prec[0] + + if precnodeid in repo: + yield precnodeid + else: + stack.append(precnodeid) + +@eh.templatekw("precursors") +def shownextvisibleprecursors(repo, ctx, templ, **args): + """Returns a string containing the list if the closest successors + displayed + """ + # XXX-review: I've added a couple of 'XXX' for future work. + + # XXX: template logic supports lists, so we should more to using a list at some point + + # XXX: I think we could returns something close to a "changectx" that would allow template to alter the way we render this. + shortnodes = map(node.short, sorted(closestprecursors(repo, ctx.node()))) + return ', '.join(shortnodes)