templates: fix ifcontains against sets with length > 1 (issue4259) stable
authorDurham Goode <durham@fb.com>
Fri, 23 May 2014 16:25:55 -0700
branchstable
changeset 21540 d8fb835376d1
parent 21229 54d7657d7d1e
child 21542 d12d8d41428e
templates: fix ifcontains against sets with length > 1 (issue4259) Previously the ifcontains revset was checking against the set using a pure __contains__ check. It turns out the set was actually a list of formatted strings meant for ui output, which meant the contains check failed if the formatted string wasn't significantly different from the raw value. This change makes it check against the raw data, prior to it being formatted.
mercurial/templater.py
tests/test-command-template.t
--- a/mercurial/templater.py	Mon May 05 16:54:15 2014 +0200
+++ b/mercurial/templater.py	Fri May 23 16:25:55 2014 -0700
@@ -310,7 +310,9 @@
     item = stringify(args[0][0](context, mapping, args[0][1]))
     items = args[1][0](context, mapping, args[1][1])
 
-    if item in items:
+    # 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()]:
         yield _evalifliteral(args[2], context, mapping)
     elif len(args) == 4:
         yield _evalifliteral(args[3], context, mapping)
--- a/tests/test-command-template.t	Mon May 05 16:54:15 2014 +0200
+++ b/tests/test-command-template.t	Fri May 23 16:25:55 2014 -0700
@@ -1819,6 +1819,11 @@
   1 not current rev
   0 not current rev
 
+  $ hg log --template '{rev} {ifcontains(rev, revset(". + .^"), "match rev", "not match rev")}\n'
+  2 match rev
+  1 match rev
+  0 not match rev
+
   $ hg log --template '{rev} Parents: {revset("parents(%s)", rev)}\n'
   2 Parents: 1
   1 Parents: 0