[PATCH 2 of 2] add `allparents' item
Paolo Bonzini
pbonzini at redhat.com
Thu Jul 2 01:37:57 CDT 2009
# HG changeset patch
# User Paolo Bonzini <pbonzini at redhat.com>
# Date 1246515264 -7200
# Node ID 174914193b9c556a81e941dfa29bac78c26d18ab
# Parent 189b8fdabf1a0fb54277ee7ff6244fa27f04ab18
add `allparents' item
The `allparents' item includes the first parent and the second if
nonempty. This is similar to --debug mode but different because
it omits an empty second parent.
The included test shows one use case, which is to always show the
first parent like `hg export' does.
The test also provides additional coverage for the template engine,
since `no_*' entries were not tested.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -827,6 +827,11 @@
branch = encoding.tolocal(branch)
return showlist('branch', [branch], plural='branches', **args)
+ def showallparents(**args):
+ parents = [[('rev', p.rev()), ('node', p.hex())]
+ for p in ctx.parents()]
+ return showlist('parent', parents, **args)
+
def showparents(**args):
parents = [[('rev', p.rev()), ('node', p.hex())]
for p in self._meaningful_parentrevs(ctx)]
@@ -875,6 +880,7 @@
return '%s: +%s/-%s' % (files, adds, removes)
defprops = {
+ 'allparents': showallparents,
'author': ctx.user(),
'branches': showbranches,
'date': ctx.date(),
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -372,6 +372,8 @@
keywords depends on the exact context of the templater. These
keywords are usually available for templating a log-like command:
+ - allparents: List of strings. All the parents of the changeset,
+ including noninteresting ones such as the revision that precedes it.
- author: String. The unmodified author of the changeset.
- branches: String. The name of the branch on which the changeset
was committed. Will be empty if the branch name was default.
diff --git a/tests/test-command-template b/tests/test-command-template
--- a/tests/test-command-template
+++ b/tests/test-command-template
@@ -92,7 +92,7 @@
cat changelog
echo "# keys work"
-for key in author branches date desc file_adds file_dels file_mods \
+for key in allparents author branches date desc file_adds file_dels file_mods \
files manifest node parents rev tags diffstat; do
for mode in '' --verbose --debug; do
hg log $mode --template "$key$mode: {$key}\n"
@@ -128,4 +128,13 @@
echo 'x = "f' >> t
hg log
+echo '# no_* works'
+cat >t <<\EOF
+changeset = '{parents}\n'
+no_parents = '{allparents|first}'
+parent = '{node} '
+last_parent = '{node}'
+EOF
+hg log --style=./t
+
echo '# done'
diff --git a/tests/test-command-template.out b/tests/test-command-template.out
--- a/tests/test-command-template.out
+++ b/tests/test-command-template.out
@@ -179,6 +179,33 @@
[1e4e1b8f71e0]
# keys work
+allparents: 7:29114dbae42b
+allparents: -1:000000000000
+allparents: 5:13207e5a10d9 4:32a18f097fcc
+allparents: 3:10e46f2dcbf4
+allparents: 3:10e46f2dcbf4
+allparents: 2:97054abb4ab8
+allparents: 1:b608e9d1a3f0
+allparents: 0:1e4e1b8f71e0
+allparents: -1:000000000000
+allparents--verbose: 7:29114dbae42b
+allparents--verbose: -1:000000000000
+allparents--verbose: 5:13207e5a10d9 4:32a18f097fcc
+allparents--verbose: 3:10e46f2dcbf4
+allparents--verbose: 3:10e46f2dcbf4
+allparents--verbose: 2:97054abb4ab8
+allparents--verbose: 1:b608e9d1a3f0
+allparents--verbose: 0:1e4e1b8f71e0
+allparents--verbose: -1:000000000000
+allparents--debug: 7:29114dbae42b9f078cf2714dbe3a86bba8ec7453
+allparents--debug: -1:0000000000000000000000000000000000000000
+allparents--debug: 5:13207e5a10d9fd28ec424934298e176197f2c67f 4:32a18f097fcccf76ef282f62f8a85b3adf8d13c4
+allparents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47
+allparents--debug: 3:10e46f2dcbf4823578cf180f33ecf0b957964c47
+allparents--debug: 2:97054abb4ab824450e9164180baf491ae0078465
+allparents--debug: 1:b608e9d1a3f0273ccf70fb85fd6866b3482bf965
+allparents--debug: 0:1e4e1b8f71e05681d422154f5421e385fec3454f
+allparents--debug: -1:0000000000000000000000000000000000000000
author: test
author: User Name <user at hostname>
author: person
@@ -681,4 +708,14 @@
1e4e1b8f71e05681d422154f5421e385fec3454f
# error on syntax
abort: t:3: unmatched quotes
+# no_* works
+29114dbae42b9f078cf2714dbe3a86bba8ec7453
+0000000000000000000000000000000000000000
+13207e5a10d9fd28ec424934298e176197f2c67f 32a18f097fcccf76ef282f62f8a85b3adf8d13c4
+10e46f2dcbf4823578cf180f33ecf0b957964c47
+10e46f2dcbf4823578cf180f33ecf0b957964c47
+97054abb4ab824450e9164180baf491ae0078465
+b608e9d1a3f0273ccf70fb85fd6866b3482bf965
+1e4e1b8f71e05681d422154f5421e385fec3454f
+0000000000000000000000000000000000000000
# done
More information about the Mercurial-devel
mailing list