changeset 22843:b6531d806de8 stable

templater: fix ifcontains when list is a string (issue4399)
author Matt Mackall <mpm@selenic.com>
date Fri, 10 Oct 2014 11:38:00 -0500
parents d43d116a118c
children 1533e642262d ee5f834077be
files mercurial/templater.py tests/test-command-template.t
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Wed Oct 08 07:47:11 2014 -0400
+++ b/mercurial/templater.py	Fri Oct 10 11:38:00 2014 -0500
@@ -312,7 +312,8 @@
 
     # Iterating over items gives a formatted string, so we iterate
     # directly over the raw values.
-    if item in [i.values()[0] for i in items()]:
+    if ((callable(items) and item in [i.values()[0] for i in items()]) or
+        (isinstance(items, str) and item in items)):
         yield _evalifliteral(args[2], context, mapping)
     elif len(args) == 4:
         yield _evalifliteral(args[3], context, mapping)
--- a/tests/test-command-template.t	Wed Oct 08 07:47:11 2014 -0400
+++ b/tests/test-command-template.t	Fri Oct 10 11:38:00 2014 -0500
@@ -1817,6 +1817,11 @@
 
 Test ifcontains function
 
+  $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n'
+  2 is in the string
+  1 is not
+  0 is in the string
+
   $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
   2 did not add a
   1 did not add a