[PATCH STABLE] templates: fix ifcontains against sets with length > 1 (issue4259)

Augie Fackler raf at durin42.com
Mon May 26 11:10:58 CDT 2014


On Fri, May 23, 2014 at 04:53:28PM -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1400887555 25200
> #      Fri May 23 16:25:55 2014 -0700
> # Node ID a78fcab054436e316acf8ff154234f292cab49d3
> # Parent  9fb6f328576ac4e38f4e5071c4d669a6ceb3a76e
> templates: fix ifcontains against sets with length > 1 (issue4259)

looks sensible, queued for stable

>
> 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 --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -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 --git a/tests/test-command-template.t b/tests/test-command-template.t
> --- a/tests/test-command-template.t
> +++ b/tests/test-command-template.t
> @@ -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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list