##// END OF EJS Templates
templater: do not reevaluate rawstring as template (BC)...
Yuya Nishihara -
r25597:fd5bc660 default
parent child Browse files
Show More
@@ -496,14 +496,14 b' def templatelabel(context, mapping, args'
496 # etc. don't need to be quoted
496 # etc. don't need to be quoted
497 mapping.update(dict([(k, k) for k in _effects]))
497 mapping.update(dict([(k, k) for k in _effects]))
498
498
499 thing = templater._evalifliteral(args[1], context, mapping)
499 thing = args[1][0](context, mapping, args[1][1])
500
500
501 # apparently, repo could be a string that is the favicon?
501 # apparently, repo could be a string that is the favicon?
502 repo = mapping.get('repo', '')
502 repo = mapping.get('repo', '')
503 if isinstance(repo, str):
503 if isinstance(repo, str):
504 return thing
504 return thing
505
505
506 label = templater._evalifliteral(args[0], context, mapping)
506 label = args[0][0](context, mapping, args[0][1])
507
507
508 thing = templater.stringify(thing)
508 thing = templater.stringify(thing)
509 label = templater.stringify(label)
509 label = templater.stringify(label)
@@ -146,8 +146,6 b' def getfilter(exp, context):'
146 def gettemplate(exp, context):
146 def gettemplate(exp, context):
147 if exp[0] == 'template':
147 if exp[0] == 'template':
148 return compiletemplate(exp[1], context)
148 return compiletemplate(exp[1], context)
149 if exp[0] == 'rawstring':
150 return compiletemplate(exp[1], context, strtoken=exp[0])
151 if exp[0] == 'symbol':
149 if exp[0] == 'symbol':
152 return context._load(exp[1])
150 return context._load(exp[1])
153 raise error.ParseError(_("expected template specifier"))
151 raise error.ParseError(_("expected template specifier"))
@@ -302,8 +300,8 b' def fill(context, mapping, args):'
302 # i18n: "fill" is a keyword
300 # i18n: "fill" is a keyword
303 raise error.ParseError(_("fill expects an integer width"))
301 raise error.ParseError(_("fill expects an integer width"))
304 try:
302 try:
305 initindent = stringify(_evalifliteral(args[2], context, mapping))
303 initindent = stringify(args[2][0](context, mapping, args[2][1]))
306 hangindent = stringify(_evalifliteral(args[3], context, mapping))
304 hangindent = stringify(args[3][0](context, mapping, args[3][1]))
307 except IndexError:
305 except IndexError:
308 pass
306 pass
309
307
@@ -318,7 +316,7 b' def pad(context, mapping, args):'
318
316
319 width = int(args[1][1])
317 width = int(args[1][1])
320
318
321 text = stringify(_evalifliteral(args[0], context, mapping))
319 text = stringify(args[0][0](context, mapping, args[0][1]))
322
320
323 right = False
321 right = False
324 fillchar = ' '
322 fillchar = ' '
@@ -368,15 +366,6 b' def get(context, mapping, args):'
368 key = args[1][0](context, mapping, args[1][1])
366 key = args[1][0](context, mapping, args[1][1])
369 yield dictarg.get(key)
367 yield dictarg.get(key)
370
368
371 def _evalifliteral(arg, context, mapping):
372 # get back to token tag to reinterpret string as template
373 strtoken = {runrawstring: 'rawstring'}.get(arg[0])
374 if strtoken:
375 yield runtemplate(context, mapping,
376 compiletemplate(arg[1], context, strtoken))
377 else:
378 yield stringify(arg[0](context, mapping, arg[1]))
379
380 def if_(context, mapping, args):
369 def if_(context, mapping, args):
381 """:if(expr, then[, else]): Conditionally execute based on the result of
370 """:if(expr, then[, else]): Conditionally execute based on the result of
382 an expression."""
371 an expression."""
@@ -386,9 +375,9 b' def if_(context, mapping, args):'
386
375
387 test = stringify(args[0][0](context, mapping, args[0][1]))
376 test = stringify(args[0][0](context, mapping, args[0][1]))
388 if test:
377 if test:
389 yield _evalifliteral(args[1], context, mapping)
378 yield args[1][0](context, mapping, args[1][1])
390 elif len(args) == 3:
379 elif len(args) == 3:
391 yield _evalifliteral(args[2], context, mapping)
380 yield args[2][0](context, mapping, args[2][1])
392
381
393 def ifcontains(context, mapping, args):
382 def ifcontains(context, mapping, args):
394 """:ifcontains(search, thing, then[, else]): Conditionally execute based
383 """:ifcontains(search, thing, then[, else]): Conditionally execute based
@@ -401,9 +390,9 b' def ifcontains(context, mapping, args):'
401 items = args[1][0](context, mapping, args[1][1])
390 items = args[1][0](context, mapping, args[1][1])
402
391
403 if item in items:
392 if item in items:
404 yield _evalifliteral(args[2], context, mapping)
393 yield args[2][0](context, mapping, args[2][1])
405 elif len(args) == 4:
394 elif len(args) == 4:
406 yield _evalifliteral(args[3], context, mapping)
395 yield args[3][0](context, mapping, args[3][1])
407
396
408 def ifeq(context, mapping, args):
397 def ifeq(context, mapping, args):
409 """:ifeq(expr1, expr2, then[, else]): Conditionally execute based on
398 """:ifeq(expr1, expr2, then[, else]): Conditionally execute based on
@@ -415,9 +404,9 b' def ifeq(context, mapping, args):'
415 test = stringify(args[0][0](context, mapping, args[0][1]))
404 test = stringify(args[0][0](context, mapping, args[0][1]))
416 match = stringify(args[1][0](context, mapping, args[1][1]))
405 match = stringify(args[1][0](context, mapping, args[1][1]))
417 if test == match:
406 if test == match:
418 yield _evalifliteral(args[2], context, mapping)
407 yield args[2][0](context, mapping, args[2][1])
419 elif len(args) == 4:
408 elif len(args) == 4:
420 yield _evalifliteral(args[3], context, mapping)
409 yield args[3][0](context, mapping, args[3][1])
421
410
422 def join(context, mapping, args):
411 def join(context, mapping, args):
423 """:join(list, sep): Join items in a list with a delimiter."""
412 """:join(list, sep): Join items in a list with a delimiter."""
@@ -451,7 +440,7 b' def label(context, mapping, args):'
451 raise error.ParseError(_("label expects two arguments"))
440 raise error.ParseError(_("label expects two arguments"))
452
441
453 # ignore args[0] (the label string) since this is supposed to be a a no-op
442 # ignore args[0] (the label string) since this is supposed to be a a no-op
454 yield _evalifliteral(args[1], context, mapping)
443 yield args[1][0](context, mapping, args[1][1])
455
444
456 def revset(context, mapping, args):
445 def revset(context, mapping, args):
457 """:revset(query[, formatargs...]): Execute a revision set query. See
446 """:revset(query[, formatargs...]): Execute a revision set query. See
@@ -567,7 +556,7 b' def sub(context, mapping, args):'
567
556
568 pat = stringify(args[0][0](context, mapping, args[0][1]))
557 pat = stringify(args[0][0](context, mapping, args[0][1]))
569 rpl = stringify(args[1][0](context, mapping, args[1][1]))
558 rpl = stringify(args[1][0](context, mapping, args[1][1]))
570 src = stringify(_evalifliteral(args[2], context, mapping))
559 src = stringify(args[2][0](context, mapping, args[2][1]))
571 yield re.sub(pat, rpl, src)
560 yield re.sub(pat, rpl, src)
572
561
573 def startswith(context, mapping, args):
562 def startswith(context, mapping, args):
@@ -2812,6 +2812,12 b' Test string literal:'
2812 $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n'
2812 $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n'
2813 rawstring: {rev}
2813 rawstring: {rev}
2814
2814
2815 because map operation requires template, raw string can't be used
2816
2817 $ hg log -Ra -r0 -T '{files % r"rawstring"}\n'
2818 hg: parse error: expected template specifier
2819 [255]
2820
2815 Test string escaping:
2821 Test string escaping:
2816
2822
2817 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
2823 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
@@ -2865,23 +2871,23 b' stripped before parsing:'
2865 Test leading backslashes:
2871 Test leading backslashes:
2866
2872
2867 $ cd latesttag
2873 $ cd latesttag
2868 $ hg log -r 2 -T '\{rev} {files % "\{file}"} {files % r"\{file}"}\n'
2874 $ hg log -r 2 -T '\{rev} {files % "\{file}"}\n'
2869 {rev} {file} \head1
2875 {rev} {file}
2870 $ hg log -r 2 -T '\\{rev} {files % "\\{file}"} {files % r"\\{file}"}\n'
2876 $ hg log -r 2 -T '\\{rev} {files % "\\{file}"}\n'
2871 \2 \head1 \\head1
2877 \2 \head1
2872 $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"} {files % r"\\\{file}"}\n'
2878 $ hg log -r 2 -T '\\\{rev} {files % "\\\{file}"}\n'
2873 \{rev} \{file} \\\head1
2879 \{rev} \{file}
2874 $ cd ..
2880 $ cd ..
2875
2881
2876 Test leading backslashes in "if" expression (issue4714):
2882 Test leading backslashes in "if" expression (issue4714):
2877
2883
2878 $ cd latesttag
2884 $ cd latesttag
2879 $ hg log -r 2 -T '{if("1", "\{rev}")} {if("1", r"\{rev}")}\n'
2885 $ hg log -r 2 -T '{if("1", "\{rev}")} {if("1", r"\{rev}")}\n'
2880 {rev} \2
2886 {rev} \{rev}
2881 $ hg log -r 2 -T '{if("1", "\\{rev}")} {if("1", r"\\{rev}")}\n'
2887 $ hg log -r 2 -T '{if("1", "\\{rev}")} {if("1", r"\\{rev}")}\n'
2882 \2 \\2
2888 \2 \\{rev}
2883 $ hg log -r 2 -T '{if("1", "\\\{rev}")} {if("1", r"\\\{rev}")}\n'
2889 $ hg log -r 2 -T '{if("1", "\\\{rev}")} {if("1", r"\\\{rev}")}\n'
2884 \{rev} \\\2
2890 \{rev} \\\{rev}
2885 $ cd ..
2891 $ cd ..
2886
2892
2887 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
2893 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
@@ -2951,8 +2957,6 b' Test leading backslashes in "if" express'
2951 fourth
2957 fourth
2952 second
2958 second
2953 third
2959 third
2954 $ hg log -R a -r 8 --template '{files % r"{file}\n"}\n'
2955 fourth\nsecond\nthird\n
2956
2960
2957 Test string escaping in nested expression:
2961 Test string escaping in nested expression:
2958
2962
@@ -3064,7 +3068,7 b' Test template string in pad function'
3064 {0} test
3068 {0} test
3065
3069
3066 $ hg log -r 0 -T '{pad(r"\{rev}", 10)} {author|user}\n'
3070 $ hg log -r 0 -T '{pad(r"\{rev}", 10)} {author|user}\n'
3067 \0 test
3071 \{rev} test
3068
3072
3069 Test ifcontains function
3073 Test ifcontains function
3070
3074
General Comments 0
You need to be logged in to leave comments. Login now