Patchwork match: allow pats to be None

login
register
mail settings
Submitter via Mercurial-devel
Date June 9, 2017, 5:29 a.m.
Message ID <6f66d0e87e1fe4d444cc.1496986192@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21269/
State Accepted
Headers show

Comments

via Mercurial-devel - June 9, 2017, 5:29 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1496985497 25200
#      Thu Jun 08 22:18:17 2017 -0700
# Node ID 6f66d0e87e1fe4d444ccc4e2df4a2b3597a40afc
# Parent  04c19c8082410049465e2cdc510e24801530c94b
match: allow pats to be None

match.match already interprets "!bool(patterns)" as matching
everything (but includes and excludes still apply). We might as well
allow None, which lets us simplify some callers a bit.

I originally wrote this patch while trying to change
match.match(patterns=[]) to mean to match no patterns. This patch is
one step towards that goal. I'm not sure it'll be worth the effort to
go all the way there, but I think this patch still makes sense on its
own.
Yuya Nishihara - June 9, 2017, 1:27 p.m.
On Thu, 08 Jun 2017 22:29:52 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1496985497 25200
> #      Thu Jun 08 22:18:17 2017 -0700
> # Node ID 6f66d0e87e1fe4d444ccc4e2df4a2b3597a40afc
> # Parent  04c19c8082410049465e2cdc510e24801530c94b
> match: allow pats to be None

Queued, thanks.

> -def match(root, cwd, patterns, include=None, exclude=None, default='glob',
> +def match(root, cwd, patterns=None, include=None, exclude=None, default='glob',
>            exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
>            badfn=None, icasefs=False):

match(root, cwd, exact=True) could have a better exception message.
via Mercurial-devel - June 10, 2017, 5:15 a.m.
On Fri, Jun 9, 2017 at 6:27 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Thu, 08 Jun 2017 22:29:52 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> # HG changeset patch
>> # User Martin von Zweigbergk <martinvonz@google.com>
>> # Date 1496985497 25200
>> #      Thu Jun 08 22:18:17 2017 -0700
>> # Node ID 6f66d0e87e1fe4d444ccc4e2df4a2b3597a40afc
>> # Parent  04c19c8082410049465e2cdc510e24801530c94b
>> match: allow pats to be None
>
> Queued, thanks.
>
>> -def match(root, cwd, patterns, include=None, exclude=None, default='glob',
>> +def match(root, cwd, patterns=None, include=None, exclude=None, default='glob',
>>            exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
>>            badfn=None, icasefs=False):
>
> match(root, cwd, exact=True) could have a better exception message.

Sorry, I don't follow. Which exception do you mean?
Yuya Nishihara - June 10, 2017, 5:29 a.m.
On Fri, 9 Jun 2017 22:15:00 -0700, Martin von Zweigbergk wrote:
> On Fri, Jun 9, 2017 at 6:27 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> > On Thu, 08 Jun 2017 22:29:52 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> >> # HG changeset patch
> >> # User Martin von Zweigbergk <martinvonz@google.com>
> >> # Date 1496985497 25200
> >> #      Thu Jun 08 22:18:17 2017 -0700
> >> # Node ID 6f66d0e87e1fe4d444ccc4e2df4a2b3597a40afc
> >> # Parent  04c19c8082410049465e2cdc510e24801530c94b
> >> match: allow pats to be None
> >
> > Queued, thanks.
> >
> >> -def match(root, cwd, patterns, include=None, exclude=None, default='glob',
> >> +def match(root, cwd, patterns=None, include=None, exclude=None, default='glob',
> >>            exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
> >>            badfn=None, icasefs=False):
> >
> > match(root, cwd, exact=True) could have a better exception message.
> 
> Sorry, I don't follow. Which exception do you mean?

'patterns' are required by exactmatcher.

>>> matchmod.match('', '', exact=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mercurial/match.py", line 146, in match
    m = exactmatcher(root, cwd, patterns, badfn)
  File "mercurial/match.py", line 427, in __init__
    self._files = list(files)
TypeError: 'NoneType' object is not iterable
via Mercurial-devel - June 10, 2017, 5:39 a.m.
On Fri, Jun 9, 2017 at 10:29 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Fri, 9 Jun 2017 22:15:00 -0700, Martin von Zweigbergk wrote:
>> On Fri, Jun 9, 2017 at 6:27 AM, Yuya Nishihara <yuya@tcha.org> wrote:
>> > On Thu, 08 Jun 2017 22:29:52 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> >> # HG changeset patch
>> >> # User Martin von Zweigbergk <martinvonz@google.com>
>> >> # Date 1496985497 25200
>> >> #      Thu Jun 08 22:18:17 2017 -0700
>> >> # Node ID 6f66d0e87e1fe4d444ccc4e2df4a2b3597a40afc
>> >> # Parent  04c19c8082410049465e2cdc510e24801530c94b
>> >> match: allow pats to be None
>> >
>> > Queued, thanks.
>> >
>> >> -def match(root, cwd, patterns, include=None, exclude=None, default='glob',
>> >> +def match(root, cwd, patterns=None, include=None, exclude=None, default='glob',
>> >>            exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
>> >>            badfn=None, icasefs=False):
>> >
>> > match(root, cwd, exact=True) could have a better exception message.
>>
>> Sorry, I don't follow. Which exception do you mean?
>
> 'patterns' are required by exactmatcher.
>
>>>> matchmod.match('', '', exact=True)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "mercurial/match.py", line 146, in match
>     m = exactmatcher(root, cwd, patterns, badfn)
>   File "mercurial/match.py", line 427, in __init__
>     self._files = list(files)
> TypeError: 'NoneType' object is not iterable

Ah, that makes sense. Perhaps that should be another ProgrammingError.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -301,8 +301,6 @@ 
 
     def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
-        if pats is None:
-            pats = []
         r = self._repo
         return matchmod.match(r.root, r.getcwd(), pats,
                               include, exclude, default,
@@ -1701,8 +1699,6 @@ 
 
     def match(self, pats=None, include=None, exclude=None, default='glob',
               listsubrepos=False, badfn=None):
-        if pats is None:
-            pats = []
         r = self._repo
 
         # Only a case insensitive filesystem needs magic to translate user input
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -85,7 +85,7 @@ 
             return False
     return True
 
-def match(root, cwd, patterns, include=None, exclude=None, default='glob',
+def match(root, cwd, patterns=None, include=None, exclude=None, default='glob',
           exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None,
           badfn=None, icasefs=False):
     """build an object to match a set of file patterns