[PATCH 1 of 2] templater: make pad function evaluate both string and rawstring templates

Yuya Nishihara yuya at tcha.org
Wed Jun 10 10:06:02 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1433756925 -32400
#      Mon Jun 08 18:48:45 2015 +0900
# Node ID 345ebbada28faee5263b09514102553444e6963c
# Parent  ad14fb602e5e54e5432fbc776dd5d1bad63f1f68
templater: make pad function evaluate both string and rawstring templates

"pad" function and "rawstring" type were introduced in parallel, aa51392da507
in default and 5ab28a2e9962 in stable respectively. Therefore, "pad" function
lacked handling of "rawstring" unintentionally.

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -310,10 +310,7 @@ def pad(context, mapping, args):
 
     width = int(args[1][1])
 
-    text = stringify(args[0][0](context, mapping, args[0][1]))
-    if args[0][0] == runstring:
-        text = stringify(runtemplate(context, mapping,
-            compiletemplate(text, context)))
+    text = stringify(_evalifliteral(args[0], context, mapping))
 
     right = False
     fillchar = ' '
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
@@ -3042,6 +3042,14 @@ Test pad function
   1------------------- {node|short}
   0------------------- test
 
+Test template string in pad function
+
+  $ hg log -r 0 -T '{pad("\{{rev}}", 10)} {author|user}\n'
+  {0}        test
+
+  $ hg log -r 0 -T '{pad(r"\{rev}", 10)} {author|user}\n'
+  \0         test
+
 Test ifcontains function
 
   $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n'


More information about the Mercurial-devel mailing list