[PATCH 2 of 4] templater: support using templates with non-standard names from map file
Alexander Plavin
alexander at plav.in
Fri Aug 2 21:39:13 UTC 2013
# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1374620882 -14400
# Wed Jul 24 03:08:02 2013 +0400
# Node ID 9f6c511249aca1e16fd1a50764cc014bcd8b9d85
# Parent 46f03aab5c7e287ac3c28d85de640e6b6abeda3b
templater: support using templates with non-standard names from map file
This allows adding arbitrarily-named entries to a template map file, and then
referencing them, giving the ability to deduplicate and simplify templates code.
diff -r 46f03aab5c7e -r 9f6c511249ac mercurial/templater.py
--- a/mercurial/templater.py Sat Aug 03 00:34:56 2013 +0400
+++ b/mercurial/templater.py Wed Jul 24 03:08:02 2013 +0400
@@ -139,7 +139,12 @@
def runsymbol(context, mapping, key):
v = mapping.get(key)
if v is None:
- v = context._defaults.get(key, '')
+ v = context._defaults.get(key)
+ if v is None:
+ try:
+ v = context.process(key, mapping)
+ except util.Abort:
+ v = ''
if util.safehasattr(v, '__call__'):
return v(**mapping)
if isinstance(v, types.GeneratorType):
diff -r 46f03aab5c7e -r 9f6c511249ac tests/test-command-template.t
--- a/tests/test-command-template.t Sat Aug 03 00:34:56 2013 +0400
+++ b/tests/test-command-template.t Wed Jul 24 03:08:02 2013 +0400
@@ -500,6 +500,23 @@
1
0
+Defining non-standard name works:
+
+ $ cat <<EOF > t
+ > changeset = '{c}'
+ > c = q
+ > EOF
+ $ hg log --style ./t
+ 8
+ 7
+ 6
+ 5
+ 4
+ 3
+ 2
+ 1
+ 0
+
ui.style works:
$ echo '[ui]' > .hg/hgrc
More information about the Mercurial-devel
mailing list