diff mercurial/templatekw.py @ 17357:bd605568c5a0

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}'.
author epriestley <hg@yghe.net>
date Tue, 10 Jul 2012 08:43:32 -0700
parents 293dd81e4601
children 2917f82f6040
line wrap: on
line diff
--- 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,