templatekw: add p1rev, p1node, p2rev, p2node keywords
The {parents} template is cumbersome for some uses, as it does not show
anything if there's only one "natural" parent and you can't use it to get the
full 40 digit node hashes for parents unless you rely on the behavior of
the --debug flag.
Introduce four new template keywords: {p1rev}, {p2rev}, {p1node} and
{p2node}. The "node" flavors of these always show full 40 digit hashes,
but users can get the short version with a filter construction like
'{p1node|short}'.
--- a/mercurial/templatekw.py Mon Aug 13 11:49:55 2012 -0700
+++ b/mercurial/templatekw.py Tue Jul 10 08:43:32 2012 -0700
@@ -275,6 +275,28 @@
"""
return ctx.hex()
+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 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 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 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."""
return ctx.phasestr()
@@ -320,6 +342,10 @@
'latesttagdistance': showlatesttagdistance,
'manifest': showmanifest,
'node': shownode,
+ 'p1rev': showp1rev,
+ 'p1node': showp1node,
+ 'p2rev': showp2rev,
+ 'p2node': showp2node,
'phase': showphase,
'phaseidx': showphaseidx,
'rev': showrev,
--- a/tests/test-command-template.t Mon Aug 13 11:49:55 2012 -0700
+++ b/tests/test-command-template.t Tue Jul 10 08:43:32 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: