[PATCH] match: allow pats to be None

Martin von Zweigbergk martinvonz at google.com
Fri Jun 9 05:29:52 UTC 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at 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.

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


More information about the Mercurial-devel mailing list