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

login
register
mail settings
Submitter Yuya Nishihara
Date June 10, 2015, 3:06 p.m.
Message ID <345ebbada28faee5263b.1433948762@mimosa>
Download mbox | patch
Permalink /patch/9579/
State Accepted
Headers show

Comments

Yuya Nishihara - June 10, 2015, 3:06 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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'