diff mercurial/templatefuncs.py @ 37015:a318bb154d42

templatefuncs: do not stringify result of if*() expression Returning a generator means that the result is a byte string. I can't find any reason to make the "if" condition lazy since it is evaluated anyway when {if()} has to be evaluated. So let's simply make if*() return an input expression unmodified.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 19 Mar 2018 22:10:40 +0900
parents 521f6c7e1756
children 0fb28899e81a
line wrap: on
line diff
--- a/mercurial/templatefuncs.py	Mon Mar 19 21:55:02 2018 +0900
+++ b/mercurial/templatefuncs.py	Mon Mar 19 22:10:40 2018 +0900
@@ -248,9 +248,9 @@
 
     test = evalboolean(context, mapping, args[0])
     if test:
-        yield evalrawexp(context, mapping, args[1])
+        return evalrawexp(context, mapping, args[1])
     elif len(args) == 3:
-        yield evalrawexp(context, mapping, args[2])
+        return evalrawexp(context, mapping, args[2])
 
 @templatefunc('ifcontains(needle, haystack, then[, else])')
 def ifcontains(context, mapping, args):
@@ -269,9 +269,9 @@
         found = False
 
     if found:
-        yield evalrawexp(context, mapping, args[2])
+        return evalrawexp(context, mapping, args[2])
     elif len(args) == 4:
-        yield evalrawexp(context, mapping, args[3])
+        return evalrawexp(context, mapping, args[3])
 
 @templatefunc('ifeq(expr1, expr2, then[, else])')
 def ifeq(context, mapping, args):
@@ -284,9 +284,9 @@
     test = evalstring(context, mapping, args[0])
     match = evalstring(context, mapping, args[1])
     if test == match:
-        yield evalrawexp(context, mapping, args[2])
+        return evalrawexp(context, mapping, args[2])
     elif len(args) == 4:
-        yield evalrawexp(context, mapping, args[3])
+        return evalrawexp(context, mapping, args[3])
 
 @templatefunc('join(list, sep)')
 def join(context, mapping, args):