diff mercurial/templatekw.py @ 33276:89796a25d4bb

template: add successors template Add a 'successorssets' template that returns the list of all closest known sucessorssets for a changectx. The elements of the list are changesets. The "closest successors" are the first locally known revisions encountered while, walking successors markers. It uses successorsets previously modified to support the closest argument. This logic respect repository filtering. So hidden revision will be skipped by this logic unless --hidden is specified. Since we only display the visible predecessors, this template will not display anything in most case. It makes a good candidate for inclusion in the default log output. I updated the test-obsmarker-template.t test file introduced with the predecessors template to test successorssets template.
author Boris Feld <boris.feld@octobus.net>
date Mon, 03 Jul 2017 11:22:00 +0200
parents 46fa46608ca5
children 16ed67164002
line wrap: on
line diff
--- a/mercurial/templatekw.py	Mon Jul 03 14:22:28 2017 +0200
+++ b/mercurial/templatekw.py	Mon Jul 03 11:22:00 2017 +0200
@@ -602,6 +602,38 @@
                    lambda x: {'ctx': repo[x], 'revcache': {}},
                    lambda d: _formatrevnode(d['ctx']))
 
+@templatekeyword("successorssets")
+def showsuccessorssets(repo, ctx, **args):
+    """Returns a string of sets of successors for a changectx
+
+    Format used is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and
+    ctx2 while also diverged into ctx3"""
+    if not ctx.obsolete():
+        return ''
+    args = pycompat.byteskwargs(args)
+
+    ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
+    ssets = [[hex(n) for n in ss] for ss in ssets]
+
+    data = []
+    for ss in ssets:
+        h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
+                    lambda d: _formatrevnode(d['ctx']))
+        data.append(h)
+
+    # Format the successorssets
+    def render(d):
+        t = []
+        for i in d.gen:
+            t.append(i)
+        return "".join(t)
+
+    def gen(data):
+        yield "; ".join(render(d) for d in data)
+
+    return _hybrid(gen(data), data, lambda x: {'successorset': x},
+                   lambda d: d["successorset"])
+
 @templatekeyword('p1rev')
 def showp1rev(repo, ctx, templ, **args):
     """Integer. The repository-local revision number of the changeset's