Submitter | Anton Shestakov |
---|---|
Date | Oct. 1, 2016, 2 a.m. |
Message ID | <3d02056ddf0cc2de8ab3.1475287245@neuro> |
Download | mbox | patch |
Permalink | /patch/16814/ |
State | Accepted |
Headers | show |
Comments
On Sat, 01 Oct 2016 10:00:45 +0800, Anton Shestakov wrote: > # HG changeset patch > # User Anton Shestakov <av6@dwimlabs.net> > # Date 1475286932 -28800 > # Sat Oct 01 09:55:32 2016 +0800 > # Node ID 3d02056ddf0cc2de8ab39bfcef4ca106d74e69f9 > # Parent 3f4e1c033f40aaa8111de9b8212f05e8e09590aa > templater: use "needle" and "haystack" as (meta-)variables for ifcontains() > > It wasn't immediately clear if it's supposed to look for "search" in "thing" or > "thing" in "search". > > diff --git a/mercurial/templater.py b/mercurial/templater.py > --- a/mercurial/templater.py > +++ b/mercurial/templater.py > @@ -596,18 +596,18 @@ def if_(context, mapping, args): > elif len(args) == 3: > yield args[2][0](context, mapping, args[2][1]) > > -@templatefunc('ifcontains(search, thing, then[, else])') > +@templatefunc('ifcontains(needle, haystack, then[, else])') The change looks good, but I honestly don't know if needle/haystack metaphor is very common. (I always had to search the doc to know which is which when I was writing PHP.) So I let someone take this or not.
On Tue, Oct 04, 2016 at 11:29:05PM +0900, Yuya Nishihara wrote: > On Sat, 01 Oct 2016 10:00:45 +0800, Anton Shestakov wrote: > > # HG changeset patch > > # User Anton Shestakov <av6@dwimlabs.net> > > # Date 1475286932 -28800 > > # Sat Oct 01 09:55:32 2016 +0800 > > # Node ID 3d02056ddf0cc2de8ab39bfcef4ca106d74e69f9 > > # Parent 3f4e1c033f40aaa8111de9b8212f05e8e09590aa > > templater: use "needle" and "haystack" as (meta-)variables for ifcontains() > > > > It wasn't immediately clear if it's supposed to look for "search" in "thing" or > > "thing" in "search". > > > > diff --git a/mercurial/templater.py b/mercurial/templater.py > > --- a/mercurial/templater.py > > +++ b/mercurial/templater.py > > @@ -596,18 +596,18 @@ def if_(context, mapping, args): > > elif len(args) == 3: > > yield args[2][0](context, mapping, args[2][1]) > > > > -@templatefunc('ifcontains(search, thing, then[, else])') > > +@templatefunc('ifcontains(needle, haystack, then[, else])') > > The change looks good, but I honestly don't know if needle/haystack metaphor > is very common. (I always had to search the doc to know which is which when > I was writing PHP.) > > So I let someone take this or not. It's more likely to be obvious, at least to those familar with the English colloquialism "like looking for a needle in a haystack". I've queued it. > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Fwiw, I was tempted to +1 this change
Patch
diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -596,18 +596,18 @@ def if_(context, mapping, args): elif len(args) == 3: yield args[2][0](context, mapping, args[2][1]) -@templatefunc('ifcontains(search, thing, then[, else])') +@templatefunc('ifcontains(needle, haystack, then[, else])') def ifcontains(context, mapping, args): """Conditionally execute based - on whether the item "search" is in "thing".""" + on whether the item "needle" is in "haystack".""" if not (3 <= len(args) <= 4): # i18n: "ifcontains" is a keyword raise error.ParseError(_("ifcontains expects three or four arguments")) - item = evalstring(context, mapping, args[0]) - items = evalfuncarg(context, mapping, args[1]) + needle = evalstring(context, mapping, args[0]) + haystack = evalfuncarg(context, mapping, args[1]) - if item in items: + if needle in haystack: yield args[2][0](context, mapping, args[2][1]) elif len(args) == 4: yield args[3][0](context, mapping, args[3][1])