[PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Evan Priestley
# HG changeset patch
# User epriestley <[hidden email]>
# Date 1341935012 25200
# Node ID 1c053d939f42f9face52f8c991e624e111189d97
# Parent  2e13c1bd34dc6afda8fc7cfa22a8cd658276724f
templatekw: add parent1, parent1node, parent2, parent2node 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: {parent1}, {parent2}, {parent1node} and
{parent2node}. The "node" flavors of these always show full 40 digit hashes,
but users can get the short version with a filter construction like
'{parent1node|short}'.

diff -r 2e13c1bd34dc -r 1c053d939f42 mercurial/templatekw.py
--- a/mercurial/templatekw.py Wed Jul 04 17:29:49 2012 +0200
+++ b/mercurial/templatekw.py Tue Jul 10 08:43:32 2012 -0700
@@ -275,6 +275,36 @@
     """
     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 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 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 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 showphase(repo, ctx, templ, **args):
     """:phase: String. The changeset phase name."""
     return ctx.phasestr()
@@ -320,6 +350,10 @@
     'latesttagdistance': showlatesttagdistance,
     'manifest': showmanifest,
     'node': shownode,
+    'parent1': showparent1,
+    'parent1node': showparent1node,
+    'parent2': showparent2,
+    'parent2node': showparent2node,
     'phase': showphase,
     'phaseidx': showphaseidx,
     'rev': showrev,
diff -r 2e13c1bd34dc -r 1c053d939f42 tests/test-template-engine.t
--- a/tests/test-template-engine.t Wed Jul 04 17:29:49 2012 +0200
+++ b/tests/test-template-engine.t Tue Jul 10 08:43:32 2012 -0700
@@ -36,4 +36,12 @@
   $ hg log --style=./mymap
   0 97e5f848f0936960273bbf75be6388cd0350a32b test
 
+  $ cat > changeset.txt << EOF
+  > {{parent1}} {{parent1node}} {{parent2}} {{parent2node}}
+  > EOF
+  $ hg ci -Ama
+  $ hg log --style=./mymap
+  0 97e5f848f0936960273bbf75be6388cd0350a32b -1 0000000000000000000000000000000000000000
+  -1 0000000000000000000000000000000000000000 -1 0000000000000000000000000000000000000000
+
   $ cd ..


_______________________________________________
Mercurial-devel mailing list
[hidden email]
http://selenic.com/mailman/listinfo/mercurial-devel

kwargs_parents.hgexport (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Bryan O'Sullivan
Applied, thanks: http://hg.intevation.org/mercurial/crew/rev/c25531ed58b0

On Tue, Jul 10, 2012 at 8:46 AM, Evan Priestley <[hidden email]> wrote:
templatekw: add parent1, parent1node, parent2, parent2node keywords


_______________________________________________
Mercurial-devel mailing list
[hidden email]
http://selenic.com/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Evan Priestley
This version (from the second incarnation of this thread) is much cleaner if you want to take it instead:


On Aug 13, 2012, at 1:56 PM, Bryan O'Sullivan wrote:

Applied, thanks: http://hg.intevation.org/mercurial/crew/rev/c25531ed58b0

On Tue, Jul 10, 2012 at 8:46 AM, Evan Priestley <[hidden email]> wrote:
templatekw: add parent1, parent1node, parent2, parent2node keywords



_______________________________________________
Mercurial-devel mailing list
[hidden email]
http://selenic.com/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Patrick Mézard
Le 13/08/12 22:58, Evan Priestley a écrit :

> This version (from the second incarnation of this thread) is much cleaner if you want to take it instead:
>
> http://www.selenic.com/pipermail/mercurial-devel/2012-August/043474.html
>
> On Aug 13, 2012, at 1:56 PM, Bryan O'Sullivan wrote:
>
>> Applied, thanks: http://hg.intevation.org/mercurial/crew/rev/c25531ed58b0
>>
>> On Tue, Jul 10, 2012 at 8:46 AM, Evan Priestley <[hidden email]> wrote:
>> templatekw: add parent1, parent1node, parent2, parent2node keywords

Bryan, can we have the p1rev/p1node version or do you prefer the other one?

--
Patrick Mézard

_______________________________________________
Mercurial-devel mailing list
[hidden email]
http://selenic.com/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] templatekw: add parent1, parent1node, parent2, parent2node keywords

Bryan O'Sullivan
In reply to this post by Evan Priestley
On Mon, Aug 13, 2012 at 1:58 PM, Evan Priestley <[hidden email]> wrote:
This version (from the second incarnation of this thread) is much cleaner if you want to take it instead:

Blargh, I missed that. I'll apply the second version of the patch and have it supersede the first. Thanks for drawing my attention to it.

_______________________________________________
Mercurial-devel mailing list
[hidden email]
http://selenic.com/mailman/listinfo/mercurial-devel