diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -251,6 +251,8 @@ def sub(context, mapping, args): 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): 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 @@ -1531,3 +1531,7 @@ 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