[PATCH 1 of 3] template: call runtemplate on the src argument to sub
Sean Farley
sean.michael.farley at gmail.com
Thu Apr 18 21:01:30 UTC 2013
# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1365640069 18000
# Wed Apr 10 19:27:49 2013 -0500
# Node ID b657a963876cb670bb003ec4c1cacce3189b2055
# Parent 63a783d1ac852d60e60669b2f8551a9b26de2947
template: call runtemplate on the src argument to sub
This allows using a template keyword on calls to the sub function and brings
the function inline with most other semantics of the other template functions.
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -249,10 +249,12 @@
raise error.ParseError(_("sub expects three arguments"))
pat = stringify(args[0][0](context, mapping, args[0][1]))
rpl = stringify(args[1][0](context, mapping, args[1][1]))
src = stringify(args[2][0](context, mapping, args[2][1]))
+ src = stringify(runtemplate(context, mapping,
+ compiletemplate(src, context)))
yield re.sub(pat, rpl, src)
def if_(context, mapping, args):
if not (2 <= len(args) <= 3):
# i18n: "if" is a keyword
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
@@ -1529,5 +1529,9 @@
Test new-style inline templating:
$ hg log -R latesttag -r tip --template 'modified files: {file_mods % " {file}\n"}\n'
modified files: .hgtags
+Test the sub function of templating for expansion:
+
+ $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
+ xx
More information about the Mercurial-devel
mailing list