Patchwork [2,of,3] templatekw: populate all keywords depending on predecessor in map operation

login
register
mail settings
Submitter Yuya Nishihara
Date June 17, 2017, 5:02 a.m.
Message ID <5b1a8349209c04dfc5ae.1497675766@mimosa>
Download mbox | patch
Permalink /patch/21447/
State Accepted
Headers show

Comments

Yuya Nishihara - June 17, 2017, 5:02 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1497673435 -32400
#      Sat Jun 17 13:23:55 2017 +0900
# Node ID 5b1a8349209c04dfc5aec3c52a97f7302bcaf322
# Parent  89557eb72b36450b6833ee04673a131b063c77d5
templatekw: populate all keywords depending on predecessor in map operation

This is what showparents() does. repo[precnode] should never fail since its
validity is tested by closestpredecessors().

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -568,8 +568,9 @@  def showpredecessors(repo, ctx, **args):
     predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
     predecessors = map(hex, predecessors)
 
-    return _hybrid(None, predecessors, lambda x: {'node': x},
-                   lambda d: d['node'][:12])
+    return _hybrid(None, predecessors,
+                   lambda x: {'ctx': repo[x], 'revcache': {}},
+                   lambda d: short(scmutil.binnode(d['ctx'])))
 
 @templatekeyword('p1rev')
 def showp1rev(repo, ctx, templ, **args):
diff --git a/tests/test-obsmarker-template.t b/tests/test-obsmarker-template.t
--- a/tests/test-obsmarker-template.t
+++ b/tests/test-obsmarker-template.t
@@ -16,7 +16,7 @@  Global setup
   >     {if(predecessors, "\n  Predecessors: {predecessors}")}\
   >     {if(predecessors, "\n  semi-colon: {join(predecessors, "; ")}")}\
   >     {if(predecessors, "\n  json: {predecessors|json}")}\
-  >     {if(predecessors, "\n  map: {join(predecessors % "{node}", " ")}")}\n'
+  >     {if(predecessors, "\n  map: {join(predecessors % "{rev}:{node}", " ")}")}\n'
   > EOF
 
 Test templates on amended commit
@@ -73,7 +73,7 @@  Predecessors template should show curren
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -87,7 +87,7 @@  Predecessors template should show curren
   |    Predecessors: a468dc9b3633
   |    semi-colon: a468dc9b3633
   |    json: ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]
-  |    map: a468dc9b36338b14fdb7825f55ce3df4e71517ad
+  |    map: 3:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   | @  a468dc9b3633
   |/
   o  ea207398892e
@@ -99,12 +99,12 @@  with --hidden
   |    Predecessors: a468dc9b3633
   |    semi-colon: a468dc9b3633
   |    json: ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]
-  |    map: a468dc9b36338b14fdb7825f55ce3df4e71517ad
+  |    map: 3:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   | @  a468dc9b3633
   |/     Predecessors: 471f378eab4c
   |      semi-colon: 471f378eab4c
   |      json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |      map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  f137d23bb3e1
   | |
   | x  471f378eab4c
@@ -126,12 +126,12 @@  visible.
   |    Predecessors: a468dc9b3633
   |    semi-colon: a468dc9b3633
   |    json: ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]
-  |    map: a468dc9b36338b14fdb7825f55ce3df4e71517ad
+  |    map: 3:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   | x  a468dc9b3633
   |/     Predecessors: 471f378eab4c
   |      semi-colon: 471f378eab4c
   |      json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |      map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  f137d23bb3e1
   | |
   | x  471f378eab4c
@@ -209,12 +209,12 @@  Predecessors template should show curren
   |    Predecessors: 471597cad322
   |    semi-colon: 471597cad322
   |    json: ["471597cad322d1f659bb169751be9133dad92ef3"]
-  |    map: 471597cad322d1f659bb169751be9133dad92ef3
+  |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   o  337fec4d2edc
   |    Predecessors: 471597cad322
   |    semi-colon: 471597cad322
   |    json: ["471597cad322d1f659bb169751be9133dad92ef3"]
-  |    map: 471597cad322d1f659bb169751be9133dad92ef3
+  |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   | @  471597cad322
   |/
   o  ea207398892e
@@ -238,12 +238,12 @@  with --hidden
   |    Predecessors: 471597cad322
   |    semi-colon: 471597cad322
   |    json: ["471597cad322d1f659bb169751be9133dad92ef3"]
-  |    map: 471597cad322d1f659bb169751be9133dad92ef3
+  |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   o  337fec4d2edc
   |    Predecessors: 471597cad322
   |    semi-colon: 471597cad322
   |    json: ["471597cad322d1f659bb169751be9133dad92ef3"]
-  |    map: 471597cad322d1f659bb169751be9133dad92ef3
+  |    map: 1:471597cad322d1f659bb169751be9133dad92ef3
   | x  471597cad322
   |/
   o  ea207398892e
@@ -323,7 +323,7 @@  Predecessors template should show curren
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -338,7 +338,7 @@  displayed
   |    Predecessors: 0dec01379d3b 471f378eab4c
   |    semi-colon: 0dec01379d3b; 471f378eab4c
   |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", "471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  0dec01379d3b
   | |
   | x  471f378eab4c
@@ -362,7 +362,7 @@  with --hidden
   |    Predecessors: 0dec01379d3b 471f378eab4c
   |    semi-colon: 0dec01379d3b; 471f378eab4c
   |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", "471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  0dec01379d3b
   | |
   | x  471f378eab4c
@@ -474,12 +474,12 @@  Predecessors template should show curren
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | o  fdf9bde5129a
   |/     Predecessors: 471f378eab4c
   |      semi-colon: 471f378eab4c
   |      json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |      map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -503,17 +503,17 @@  Predecessors template should the predece
   |    Predecessors: 65b757b745b9
   |    semi-colon: 65b757b745b9
   |    json: ["65b757b745b935093c87a2bccd877521cccffcbd"]
-  |    map: 65b757b745b935093c87a2bccd877521cccffcbd
+  |    map: 3:65b757b745b935093c87a2bccd877521cccffcbd
   | x  65b757b745b9
   |/     Predecessors: 471f378eab4c
   |      semi-colon: 471f378eab4c
   |      json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |      map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  fdf9bde5129a
   |/     Predecessors: 471f378eab4c
   |      semi-colon: 471f378eab4c
   |      json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |      map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |      map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  471f378eab4c
   |/
   o  ea207398892e
@@ -607,7 +607,7 @@  Predecessors template should show curren
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -621,7 +621,7 @@  Predecessors template should both predec
   |    Predecessors: 0dec01379d3b 471f378eab4c
   |    semi-colon: 0dec01379d3b; 471f378eab4c
   |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", "471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  0dec01379d3b
   | |
   | x  471f378eab4c
@@ -637,7 +637,7 @@  Predecessors template should both predec
   |    Predecessors: 471f378eab4c b7ea6d14e664
   |    semi-colon: 471f378eab4c; b7ea6d14e664
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874", "b7ea6d14e664bdc8922221f7992631b50da3fb07"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874 b7ea6d14e664bdc8922221f7992631b50da3fb07
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874 3:b7ea6d14e664bdc8922221f7992631b50da3fb07
   | @  b7ea6d14e664
   | |
   | x  471f378eab4c
@@ -660,12 +660,12 @@  with --hidden
   |    Predecessors: 471f378eab4c b7ea6d14e664
   |    semi-colon: 471f378eab4c; b7ea6d14e664
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874", "b7ea6d14e664bdc8922221f7992631b50da3fb07"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874 b7ea6d14e664bdc8922221f7992631b50da3fb07
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874 3:b7ea6d14e664bdc8922221f7992631b50da3fb07
   | x  b7ea6d14e664
   | |    Predecessors: 0dec01379d3b
   | |    semi-colon: 0dec01379d3b
   | |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]
-  | |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5
+  | |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   | | x  0dec01379d3b
   | |/
   | x  471f378eab4c
@@ -768,7 +768,7 @@  Predecessors template should show curren
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -789,7 +789,7 @@  with --hidden
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  471f378eab4c
   |/
   o  ea207398892e
@@ -833,17 +833,17 @@  Check templates
   |    Predecessors: 0dec01379d3b
   |    semi-colon: 0dec01379d3b
   |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]
-  |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5
+  |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   | @  0dec01379d3b
   | |    Predecessors: 471f378eab4c
   | |    semi-colon: 471f378eab4c
   | |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  | |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  | |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  471f378eab4c
   |/     Predecessors: 0dec01379d3b
   |      semi-colon: 0dec01379d3b
   |      json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]
-  |      map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5
+  |      map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   o  ea207398892e
   
 
@@ -854,7 +854,7 @@  Check templates
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -873,16 +873,16 @@  Check templates
   |    Predecessors: 0dec01379d3b
   |    semi-colon: 0dec01379d3b
   |    json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]
-  |    map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5
+  |    map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   | x  0dec01379d3b
   | |    Predecessors: 471f378eab4c
   | |    semi-colon: 471f378eab4c
   | |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  | |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  | |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  471f378eab4c
   |/     Predecessors: 0dec01379d3b
   |      semi-colon: 0dec01379d3b
   |      json: ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]
-  |      map: 0dec01379d3be6318c470ead31b1fe7ae7cb53d5
+  |      map: 2:0dec01379d3be6318c470ead31b1fe7ae7cb53d5
   @  ea207398892e