##// END OF EJS Templates
templater: fix if() to not evaluate False as bool('False')...
Yuya Nishihara -
r29816:034412ca default
parent child Browse files
Show More
@@ -289,6 +289,15 b' def evalfuncarg(context, mapping, arg):'
289 thing = stringify(thing)
289 thing = stringify(thing)
290 return thing
290 return thing
291
291
292 def evalboolean(context, mapping, arg):
293 func, data = arg
294 thing = func(context, mapping, data)
295 if isinstance(thing, bool):
296 return thing
297 # other objects are evaluated as strings, which means 0 is True, but
298 # empty dict/list should be False as they are expected to be ''
299 return bool(stringify(thing))
300
292 def evalinteger(context, mapping, arg, err):
301 def evalinteger(context, mapping, arg, err):
293 v = evalfuncarg(context, mapping, arg)
302 v = evalfuncarg(context, mapping, arg)
294 try:
303 try:
@@ -560,7 +569,7 b' def if_(context, mapping, args):'
560 # i18n: "if" is a keyword
569 # i18n: "if" is a keyword
561 raise error.ParseError(_("if expects two or three arguments"))
570 raise error.ParseError(_("if expects two or three arguments"))
562
571
563 test = evalstring(context, mapping, args[0])
572 test = evalboolean(context, mapping, args[0])
564 if test:
573 if test:
565 yield args[1][0](context, mapping, args[1][1])
574 yield args[1][0](context, mapping, args[1][1])
566 elif len(args) == 3:
575 elif len(args) == 3:
@@ -516,6 +516,8 b' template output:'
516 }
516 }
517 ]
517 ]
518
518
519 $ hg branches --closed -T '{if(closed, "{branch}\n")}'
520 c
519
521
520 Tests of revision branch name caching
522 Tests of revision branch name caching
521
523
General Comments 0
You need to be logged in to leave comments. Login now