templatekw: add p1/p2 keywords which switches the current ctx
This is just an example of mappingdict.
I have no idea what should be displayed as {p1|json}. Currently it is an
empty dict since {'ctx'} isn't displayable, which is clearly useless and
should be changed later.
--- a/mercurial/templatekw.py Fri Oct 19 21:11:30 2018 +0900
+++ b/mercurial/templatekw.py Fri Oct 26 21:43:20 2018 +0900
@@ -691,6 +691,20 @@
return templateutil.mappinglist(data)
+@templatekeyword('p1', requires={'ctx'})
+def showp1(context, mapping):
+ """Changeset. The changeset's first parent. ``{p1.rev}`` for the revision
+ number, and ``{p1.node}`` for the identification hash."""
+ ctx = context.resource(mapping, 'ctx')
+ return templateutil.mappingdict({'ctx': ctx.p1()}, tmpl=_changeidtmpl)
+
+@templatekeyword('p2', requires={'ctx'})
+def showp2(context, mapping):
+ """Changeset. The changeset's second parent. ``{p2.rev}`` for the revision
+ number, and ``{p2.node}`` for the identification hash."""
+ ctx = context.resource(mapping, 'ctx')
+ return templateutil.mappingdict({'ctx': ctx.p2()}, tmpl=_changeidtmpl)
+
@templatekeyword('p1rev', requires={'ctx'})
def showp1rev(context, mapping):
"""Integer. The repository-local revision number of the changeset's
--- a/tests/test-template-keywords.t Fri Oct 19 21:11:30 2018 +0900
+++ b/tests/test-template-keywords.t Fri Oct 26 21:43:20 2018 +0900
@@ -836,6 +836,25 @@
0 default
1 foo
+p1/p2 keywords:
+
+ $ hg log -r4:7 -GT '{rev} p1:{p1} p2:{p2} p1.rev:{p1.rev} p2.node:{p2.node}\n'
+ o 7 p1:-1:000000000000 p2:-1:000000000000 p1.rev:-1 p2.node:0000000000000000000000000000000000000000
+
+ o 6 p1:5:13207e5a10d9 p2:4:bbe44766e73d p1.rev:5 p2.node:bbe44766e73d5f11ed2177f1838de10c53ef3e74
+ |\
+ | o 5 p1:3:10e46f2dcbf4 p2:-1:000000000000 p1.rev:3 p2.node:0000000000000000000000000000000000000000
+ | |
+ | ~
+ o 4 p1:3:10e46f2dcbf4 p2:-1:000000000000 p1.rev:3 p2.node:0000000000000000000000000000000000000000
+ |
+ ~
+
+TODO: no idea what should be displayed as a JSON representation
+ $ hg log -r6 -T 'p1:{p1|json}\np2:{p2|json}\n'
+ p1:{}
+ p2:{}
+
ui verbosity:
$ hg log -l1 -T '{verbosity}\n'