changeset 17358:2917f82f6040

templatekw: merge, preferring the second implementation
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 14 Aug 2012 08:11:15 -0700
parents bd605568c5a0 (diff) c25531ed58b0 (current diff)
children d7753a0bb0cd
files mercurial/templatekw.py tests/test-template-engine.t
diffstat 3 files changed, 133 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Tue Jul 10 08:43:32 2012 -0700
+++ b/mercurial/templatekw.py	Tue Aug 14 08:11:15 2012 -0700
@@ -275,35 +275,27 @@
     """
     return ctx.hex()
 
-def showparent1(repo, ctx, templ, **args):
-    """:parent1: Integer. The repository-local revision number of the
-    changeset's first parent, or -1 if the changeset has no parents."""
-    return ctx.parents()[0].rev()
+def showp1rev(repo, ctx, templ, **args):
+    """:p1rev: Integer. The repository-local revision number of the changeset's
+    first parent, or -1 if the changeset has no parents."""
+    return ctx.p1().rev()
 
-def showparent2(repo, ctx, templ, **args):
-    """:parent2: Integer. The repository-local revision number of the
-    changeset's second parent, or -1 if the changeset has no second parent."""
-    parents = ctx.parents()
-    if len(parents) > 1:
-        return parents[1].rev()
-    else:
-        return repo['null'].rev()
+def showp2rev(repo, ctx, templ, **args):
+    """:p2rev: Integer. The repository-local revision number of the changeset's
+    second parent, or -1 if the changeset has no second parent."""
+    return ctx.p2().rev()
 
-def showparent1node(repo, ctx, templ, **args):
-    """:parent1node: String. The identification hash of the changeset's
-    first parent, as a 40 digit hexadecimal string. If the changeset has no
-    parents, all digits are 0."""
-    return ctx.parents()[0].hex()
+def showp1node(repo, ctx, templ, **args):
+    """:p1node: String. The identification hash of the changeset's first parent,
+    as a 40 digit hexadecimal string. If the changeset has no parents, all
+    digits are 0."""
+    return ctx.p1().hex()
 
-def showparent2node(repo, ctx, templ, **args):
-    """:parent2node: String. The identification hash of the changeset's
-    second parent, as a 40 digit hexadecimal string. If the changeset has no
-    second parent, all digits are 0."""
-    parents = ctx.parents()
-    if len(parents) > 1:
-        return parents[1].hex()
-    else:
-        return repo['null'].hex()
+def showp2node(repo, ctx, templ, **args):
+    """:p2node: String. The identification hash of the changeset's second
+    parent, as a 40 digit hexadecimal string. If the changeset has no second
+    parent, all digits are 0."""
+    return ctx.p2().hex()
 
 def showphase(repo, ctx, templ, **args):
     """:phase: String. The changeset phase name."""
@@ -350,10 +342,10 @@
     'latesttagdistance': showlatesttagdistance,
     'manifest': showmanifest,
     'node': shownode,
-    'parent1': showparent1,
-    'parent1node': showparent1node,
-    'parent2': showparent2,
-    'parent2node': showparent2node,
+    'p1rev': showp1rev,
+    'p1node': showp1node,
+    'p2rev': showp2rev,
+    'p2node': showp2node,
     'phase': showphase,
     'phaseidx': showphaseidx,
     'rev': showrev,
--- a/tests/test-command-template.t	Tue Jul 10 08:43:32 2012 -0700
+++ b/tests/test-command-template.t	Tue Aug 14 08:11:15 2012 -0700
@@ -592,7 +592,8 @@
 
   $ for key in author branch branches date desc file_adds file_dels file_mods \
   >         file_copies file_copies_switch files \
-  >         manifest node parents rev tags diffstat extras; do
+  >         manifest node parents rev tags diffstat extras \
+  >         p1rev p2rev p1node p2node; do
   >     for mode in '' --verbose --debug; do
   >         hg log $mode --template "$key$mode: {$key}\n"
   >     done
@@ -1095,7 +1096,114 @@
   extras--debug: branch=default
   extras--debug: branch=default
   extras--debug: branch=default
-
+  p1rev: 7
+  p1rev: -1
+  p1rev: 5
+  p1rev: 3
+  p1rev: 3
+  p1rev: 2
+  p1rev: 1
+  p1rev: 0
+  p1rev: -1
+  p1rev--verbose: 7
+  p1rev--verbose: -1
+  p1rev--verbose: 5
+  p1rev--verbose: 3
+  p1rev--verbose: 3
+  p1rev--verbose: 2
+  p1rev--verbose: 1
+  p1rev--verbose: 0
+  p1rev--verbose: -1
+  p1rev--debug: 7
+  p1rev--debug: -1
+  p1rev--debug: 5
+  p1rev--debug: 3
+  p1rev--debug: 3
+  p1rev--debug: 2
+  p1rev--debug: 1
+  p1rev--debug: 0
+  p1rev--debug: -1
+  p2rev: -1
+  p2rev: -1
+  p2rev: 4
+  p2rev: -1
+  p2rev: -1
+  p2rev: -1
+  p2rev: -1
+  p2rev: -1
+  p2rev: -1
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--verbose: 4
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--verbose: -1
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p2rev--debug: 4
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p2rev--debug: -1
+  p1node: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
+  p1node: 0000000000000000000000000000000000000000
+  p1node: 13207e5a10d9fd28ec424934298e176197f2c67f
+  p1node: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node: 97054abb4ab824450e9164180baf491ae0078465
+  p1node: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
+  p1node: 1e4e1b8f71e05681d422154f5421e385fec3454f
+  p1node: 0000000000000000000000000000000000000000
+  p1node--verbose: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
+  p1node--verbose: 0000000000000000000000000000000000000000
+  p1node--verbose: 13207e5a10d9fd28ec424934298e176197f2c67f
+  p1node--verbose: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node--verbose: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node--verbose: 97054abb4ab824450e9164180baf491ae0078465
+  p1node--verbose: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
+  p1node--verbose: 1e4e1b8f71e05681d422154f5421e385fec3454f
+  p1node--verbose: 0000000000000000000000000000000000000000
+  p1node--debug: 29114dbae42b9f078cf2714dbe3a86bba8ec7453
+  p1node--debug: 0000000000000000000000000000000000000000
+  p1node--debug: 13207e5a10d9fd28ec424934298e176197f2c67f
+  p1node--debug: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node--debug: 10e46f2dcbf4823578cf180f33ecf0b957964c47
+  p1node--debug: 97054abb4ab824450e9164180baf491ae0078465
+  p1node--debug: b608e9d1a3f0273ccf70fb85fd6866b3482bf965
+  p1node--debug: 1e4e1b8f71e05681d422154f5421e385fec3454f
+  p1node--debug: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: bbe44766e73d5f11ed2177f1838de10c53ef3e74
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: bbe44766e73d5f11ed2177f1838de10c53ef3e74
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--verbose: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: bbe44766e73d5f11ed2177f1838de10c53ef3e74
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
+  p2node--debug: 0000000000000000000000000000000000000000
 
 Filters work:
 
--- a/tests/test-template-engine.t	Tue Jul 10 08:43:32 2012 -0700
+++ b/tests/test-template-engine.t	Tue Aug 14 08:11:15 2012 -0700
@@ -37,7 +37,7 @@
   0 97e5f848f0936960273bbf75be6388cd0350a32b test
 
   $ cat > changeset.txt << EOF
-  > {{parent1}} {{parent1node}} {{parent2}} {{parent2node}}
+  > {{p1rev}} {{p1node}} {{p2rev}} {{p2node}}
   > EOF
   $ hg ci -Ama
   $ hg log --style=./mymap