[PATCH 2 of 4] templater: relax type of mapped template

Yuya Nishihara yuya at tcha.org
Fri Mar 11 11:40:49 EST 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1455432169 -32400
#      Sun Feb 14 15:42:49 2016 +0900
# Node ID 76b1033c0e88c32a8ba399e2f76f1cb64f5f4f28
# Parent  d7a8f0798508dba7d747dd59c0441299a0312bc8
templater: relax type of mapped template

Now compiled template fragments are packed into a generic type, (func, data),
a string can be a valid template. This change allows us to unwrap a trivial
string node. See the next patch for details.

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -210,7 +210,7 @@ def getlist(x):
 def gettemplate(exp, context):
     """Compile given template tree or load named template from map file;
     returns (func, data) pair"""
-    if exp[0] == 'template':
+    if exp[0] in ('template', 'string'):
         return compileexp(exp, context, methods)
     if exp[0] == 'symbol':
         # unlike runsymbol(), here 'symbol' is always taken as template name
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2900,12 +2900,8 @@ Test string literal:
   template: 0
   $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n'
   rawstring: {rev}
-
-because map operation requires template, raw string can't be used
-
-  $ hg log -Ra -r0 -T '{files % r"rawstring"}\n'
-  hg: parse error: expected template specifier
-  [255]
+  $ hg log -Ra -r0 -T '{files % r"rawstring: {file}"}\n'
+  rawstring: {file}
 
 Test string escaping:
 


More information about the Mercurial-devel mailing list