[PATCH] templates: add "successors" and "precursors" template keywords
Kostia Balytskyi
ikostia at fb.com
Thu Feb 18 18:00:30 UTC 2016
# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1455818392 28800
# Thu Feb 18 09:59:52 2016 -0800
# Node ID 6b9367739dcb96910a858f8898f870d1b8e6dcda
# Parent 6c3ab048228f9b1760bf0b6baa307a4ec361c638
templates: add "successors" and "precursors" template keywords
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -6,7 +6,7 @@
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
-
+from .obsolete import successorssets, allprecursors
from .node import hex, nullid
from . import (
error,
@@ -517,6 +517,20 @@
""":tags: List of strings. Any tags associated with the changeset."""
return shownames('tags', **args)
+def showsuccessors(repo, ctx, **args):
+ """Display a list of commit's final successors"""
+ succsets = set().union(*successorssets(repo, ctx.node()))
+ if len(succsets) == 1 and ctx.node() in succsets:
+ return ''
+ hashes = [hex(n) for n in succsets]
+ return showlist('successor', hashes, **args)
+
+def showprecursors(repo, ctx, **args):
+ """Display a list of all commit's precursors"""
+ hashes = [hex(n) for n in allprecursors(repo.obsstore, [ctx.node()])
+ if n != ctx.node()]
+ return showlist('precursor', hashes, **args)
+
# keywords are callables like:
# fn(repo, ctx, templ, cache, revcache, **args)
# with:
@@ -559,8 +573,10 @@
'parents': showparents,
'phase': showphase,
'phaseidx': showphaseidx,
+ 'precursors': showprecursors,
'rev': showrev,
'subrepos': showsubrepos,
+ 'successors': showsuccessors,
'tags': showtags,
}
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3557,3 +3557,20 @@
"\ufffd\ufffd"
$ cd ..
+
+Test "successors" and "precursors" template keywords
+ $ echo "[experimental]" >> $HGRCPATH
+ $ echo "evolution=all" >> $HGRCPATH
+ $ hg init succprec
+ $ cd succprec
+ $ echo a > a && hg add a && hg commit -m a
+ $ hg commit --amend -m b
+ $ hg log --hidden -T "{node}: {successors}\n" -r 0
+ cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b: 0e141029c361d35262b35cc605f6f1e5e999c7f8
+ $ hg log --hidden -T "{node}: {successors}\n" -r 1
+ 0e141029c361d35262b35cc605f6f1e5e999c7f8:
+ $ hg log --hidden -T "{node}: {precursors}\n" -r 0
+ cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b:
+ $ hg log --hidden -T "{node}: {precursors}\n" -r 1
+ 0e141029c361d35262b35cc605f6f1e5e999c7f8: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
+
More information about the Mercurial-devel
mailing list