templater: fix ifcontains when list is a string (issue4399) stable
authorMatt Mackall <mpm@selenic.com>
Fri, 10 Oct 2014 11:38:00 -0500
branchstable
changeset 22843 b6531d806de8
parent 22842 d43d116a118c
child 22844 1533e642262d
child 23048 ee5f834077be
templater: fix ifcontains when list is a string (issue4399)
mercurial/templater.py
tests/test-command-template.t
--- 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