changeset 32910:498e9dcc5fa9

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().
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Jun 2017 13:23:55 +0900
parents 89610c586fa2
children 7f1d07d2c8f8
files mercurial/templatekw.py tests/test-obsmarker-template.t
diffstat 2 files changed, 36 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sat Jun 17 13:18:03 2017 +0900
+++ b/mercurial/templatekw.py	Sat Jun 17 13:23:55 2017 +0900
@@ -568,8 +568,9 @@
     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):
--- a/tests/test-obsmarker-template.t	Sat Jun 17 13:18:03 2017 +0900
+++ b/tests/test-obsmarker-template.t	Sat Jun 17 13:23:55 2017 +0900
@@ -16,7 +16,7 @@
   >     {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: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -87,7 +87,7 @@
   |    Predecessors: a468dc9b3633
   |    semi-colon: a468dc9b3633
   |    json: ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]
-  |    map: a468dc9b36338b14fdb7825f55ce3df4e71517ad
+  |    map: 3:a468dc9b36338b14fdb7825f55ce3df4e71517ad
   | @  a468dc9b3633
   |/
   o  ea207398892e
@@ -99,12 +99,12 @@
   |    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 @@
   |    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: 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 @@
   |    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: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -338,7 +338,7 @@
   |    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 @@
   |    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: 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: 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: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -621,7 +621,7 @@
   |    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: 471f378eab4c b7ea6d14e664
   |    semi-colon: 471f378eab4c; b7ea6d14e664
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874", "b7ea6d14e664bdc8922221f7992631b50da3fb07"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874 b7ea6d14e664bdc8922221f7992631b50da3fb07
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874 3:b7ea6d14e664bdc8922221f7992631b50da3fb07
   | @  b7ea6d14e664
   | |
   | x  471f378eab4c
@@ -660,12 +660,12 @@
   |    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: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -789,7 +789,7 @@
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | x  471f378eab4c
   |/
   o  ea207398892e
@@ -833,17 +833,17 @@
   |    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 @@
   |    Predecessors: 471f378eab4c
   |    semi-colon: 471f378eab4c
   |    json: ["471f378eab4c5e25f6c77f785b27c936efb22874"]
-  |    map: 471f378eab4c5e25f6c77f785b27c936efb22874
+  |    map: 1:471f378eab4c5e25f6c77f785b27c936efb22874
   | @  471f378eab4c
   |/
   o  ea207398892e
@@ -873,16 +873,16 @@
   |    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