Patchwork [1,of,3,V2] templater: support using templates with non-standard names from map file

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 16, 2013, 8:11 p.m.
Message ID <ddde0a1022e607fb58b2.1376683881@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2193/
State Superseded
Commit 0361163efbaf8b96fac8db712a72b9dfa916079e
Headers show

Comments

Alexander Plavin - Aug. 16, 2013, 8:11 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1374620882 -14400
#      Wed Jul 24 03:08:02 2013 +0400
# Node ID ddde0a1022e607fb58b2dad291ffa0eb17f53eb1
# Parent  102f22af77f1e5556aa36b30fd60d7a3289e2f8d
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.

Patch

diff -r 102f22af77f1 -r ddde0a1022e6 mercurial/templater.py
--- a/mercurial/templater.py	Tue Aug 06 01:12:13 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 102f22af77f1 -r ddde0a1022e6 tests/test-command-template.t
--- a/tests/test-command-template.t	Tue Aug 06 01:12:13 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