Mercurial > hg
changeset 17355:c25531ed58b0
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}'.
author | epriestley <hg@yghe.net> |
---|---|
date | Tue, 10 Jul 2012 08:43:32 -0700 |
parents | c87ba0a6fb79 |
children | 511dfb34b412 2917f82f6040 |
files | mercurial/templatekw.py tests/test-template-engine.t |
diffstat | 2 files changed, 42 insertions(+), 0 deletions(-) [+] |
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,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,
--- a/tests/test-template-engine.t Mon Aug 13 11:49:55 2012 -0700 +++ 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 ..