Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatekw.py @ 33930: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 |
line wrap: on
line diff
--- a/mercurial/templatekw.py Mon Jul 03 03:27:58 2017 +0200 +++ b/mercurial/templatekw.py Thu Aug 17 18:26:11 2017 +0200 @@ -674,6 +674,48 @@ return _hybrid(gen(data), data, lambda x: {'successorset': x}, lambda d: d["successorset"]) +@templatekeyword("succsandmarkers") +def showsuccsandmarkers(repo, ctx, **args): + """Returns a list of dict for each final successor of ctx. + + The dict contains successors node id in "successors" keys and the list of + obs-markers from ctx to the set of successors in "markers" + + (EXPERIMENTAL) + """ + + values = obsutil.successorsandmarkers(repo, ctx) + + if values is None: + values = [] + + # Format successors and markers to avoid exposing binary to templates + data = [] + for i in values: + # Format successors + successors = i['successors'] + + successors = [hex(n) for n in successors] + successors = _hybrid(None, successors, + lambda x: {'ctx': repo[x], 'revcache': {}}, + lambda d: _formatrevnode(d['ctx'])) + + # Format markers + finalmarkers = [] + for m in i['markers']: + hexprec = hex(m[0]) + hexsucs = tuple(hex(n) for n in m[1]) + hexparents = None + if m[5] is not None: + hexparents = tuple(hex(n) for n in m[5]) + newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] + finalmarkers.append(newmarker) + + data.append({'successors': successors, 'markers': finalmarkers}) + + f = _showlist('succsandmarkers', data, args) + return _hybrid(f, data, lambda x: x, lambda d: d) + @templatekeyword('p1rev') def showp1rev(repo, ctx, templ, **args): """Integer. The repository-local revision number of the changeset's