# HG changeset patch # User Durham Goode # Date 1400887555 25200 # Node ID d8fb835376d14f1cef240cd00ef4ef676e4f158a # Parent 54d7657d7d1e6a62315eea53f4498657e766bb60 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. diff -r 54d7657d7d1e -r d8fb835376d1 mercurial/templater.py --- 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) diff -r 54d7657d7d1e -r d8fb835376d1 tests/test-command-template.t --- 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