##// END OF EJS Templates
templater: avoid recursive evaluation of string literals completely...
FUJIWARA Katsunori -
r20661:7e627fe6 stable
parent child Browse files
Show More
@@ -393,9 +393,7 b' def templatelabel(context, mapping, args'
393 if isinstance(repo, str):
393 if isinstance(repo, str):
394 return thing
394 return thing
395
395
396 label = templater.stringify(args[0][0](context, mapping, args[0][1]))
396 label = templater._evalifliteral(args[0], context, mapping)
397 label = templater.runtemplate(context, mapping,
398 templater.compiletemplate(label, context))
399
397
400 thing = templater.stringify(thing)
398 thing = templater.stringify(thing)
401 label = templater.stringify(label)
399 label = templater.stringify(label)
@@ -234,12 +234,8 b' def fill(context, mapping, args):'
234 except ValueError:
234 except ValueError:
235 raise error.ParseError(_("fill expects an integer width"))
235 raise error.ParseError(_("fill expects an integer width"))
236 try:
236 try:
237 initindent = stringify(args[2][0](context, mapping, args[2][1]))
237 initindent = stringify(_evalifliteral(args[2], context, mapping))
238 initindent = stringify(runtemplate(context, mapping,
238 hangindent = stringify(_evalifliteral(args[3], context, mapping))
239 compiletemplate(initindent, context)))
240 hangindent = stringify(args[3][0](context, mapping, args[3][1]))
241 hangindent = stringify(runtemplate(context, mapping,
242 compiletemplate(hangindent, context)))
243 except IndexError:
239 except IndexError:
244 pass
240 pass
245
241
@@ -345,9 +341,7 b' def sub(context, mapping, args):'
345
341
346 pat = stringify(args[0][0](context, mapping, args[0][1]))
342 pat = stringify(args[0][0](context, mapping, args[0][1]))
347 rpl = stringify(args[1][0](context, mapping, args[1][1]))
343 rpl = stringify(args[1][0](context, mapping, args[1][1]))
348 src = stringify(args[2][0](context, mapping, args[2][1]))
344 src = stringify(_evalifliteral(args[2], context, mapping))
349 src = stringify(runtemplate(context, mapping,
350 compiletemplate(src, context)))
351 yield re.sub(pat, rpl, src)
345 yield re.sub(pat, rpl, src)
352
346
353 methods = {
347 methods = {
@@ -1622,6 +1622,39 b' Test recursive evaluation:'
1622 $ hg log -r 0 --template '{if(rev, "{author} {rev}")}\n'
1622 $ hg log -r 0 --template '{if(rev, "{author} {rev}")}\n'
1623 test 0
1623 test 0
1624
1624
1625 $ hg branch -q 'text.{rev}'
1626 $ echo aa >> aa
1627 $ hg ci -u '{node|short}' -m 'desc to be wrapped desc to be wrapped'
1628
1629 $ hg log -r 1 --template '{fill(desc, "20", author, branch)}'
1630 {node|short}desc to
1631 text.{rev}be wrapped
1632 text.{rev}desc to be
1633 text.{rev}wrapped (no-eol)
1634 $ hg log -r 1 --template '{fill(desc, "20", "{node|short}:", "text.{rev}:")}'
1635 bcc7ff960b8e:desc to
1636 text.1:be wrapped
1637 text.1:desc to be
1638 text.1:wrapped (no-eol)
1639
1640 $ hg log -r 1 --template '{sub(r"[0-9]", "-", author)}'
1641 {node|short} (no-eol)
1642 $ hg log -r 1 --template '{sub(r"[0-9]", "-", "{node|short}")}'
1643 bcc-ff---b-e (no-eol)
1644
1645 $ cat >> .hg/hgrc <<EOF
1646 > [extensions]
1647 > color=
1648 > [color]
1649 > mode=ansi
1650 > text.{rev} = red
1651 > text.1 = green
1652 > EOF
1653 $ hg log --color=always -r 1 --template '{label(branch, "text\n")}'
1654 \x1b[0;31mtext\x1b[0m (esc)
1655 $ hg log --color=always -r 1 --template '{label("text.{rev}", "text\n")}'
1656 \x1b[0;32mtext\x1b[0m (esc)
1657
1625 Test branches inside if statement:
1658 Test branches inside if statement:
1626
1659
1627 $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'
1660 $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'
General Comments 0
You need to be logged in to leave comments. Login now