Patchwork [3,of,4] templatekw: add p1/p2 keywords which switches the current ctx

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 2, 2018, 1:18 p.m.
Message ID <cd356034a839f6cfd0e6.1541164718@mimosa>
Download mbox | patch
Permalink /patch/36337/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 2, 2018, 1:18 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540557800 -32400
#      Fri Oct 26 21:43:20 2018 +0900
# Node ID cd356034a839f6cfd0e64c894d9696e79e3c25f7
# Parent  49a6ece003a203da3e4a74fb60256f811fd2f32b
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.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -691,6 +691,20 @@  def showsuccsandmarkers(context, mapping
 
     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
diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t
--- a/tests/test-template-keywords.t
+++ b/tests/test-template-keywords.t
@@ -836,6 +836,25 @@  Test index keyword:
   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'