Patchwork [3,of,5] match: drop support for empty pattern list in patternmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 30, 2017, 6:50 a.m.
Message ID <f563ef561ef7f41b2628.1496127033@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21059/
State Accepted
Headers show

Comments

via Mercurial-devel - May 30, 2017, 6:50 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495220296 25200
#      Fri May 19 11:58:16 2017 -0700
# Node ID f563ef561ef7f41b2628039c52e17b335e3764e3
# Parent  b096fab5cc395a8f91d6026f7562573f01274458
match: drop support for empty pattern list in patternmatcher

Since the caller now deals with empty pattern lists, we can drop that
support in the patternmatcher. It now gets the more logical behavior
of matching nothing when no patterns are given (although there is no
in-core caller that will pass no patterns).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -341,36 +341,21 @@ 
     def __init__(self, root, cwd, normalize, patterns, default='glob',
                  auditor=None, ctx=None, listsubrepos=False, warn=None,
                  badfn=None):
-        super(patternmatcher, self).__init__(root, cwd, badfn,
-                                             relativeuipath=bool(patterns))
-
-        self._anypats = False
-        self._always = False
-        self.patternspat = None
+        super(patternmatcher, self).__init__(root, cwd, badfn)
 
-        matchfns = []
-        if patterns:
-            kindpats = normalize(patterns, default, root, cwd, auditor, warn)
-            if not _kindpatsalwaysmatch(kindpats):
-                self._files = _explicitfiles(kindpats)
-                self._anypats = self._anypats or _anypats(kindpats)
-                self.patternspat, pm = _buildmatch(ctx, kindpats, '$',
-                                                   listsubrepos, root)
-                matchfns.append(pm)
-
-        if not matchfns:
-            m = util.always
+        kindpats = normalize(patterns, default, root, cwd, auditor, warn)
+        if not _kindpatsalwaysmatch(kindpats):
+            self._files = _explicitfiles(kindpats)
+            self._anypats = _anypats(kindpats)
+            self.patternspat, pm = _buildmatch(ctx, kindpats, '$',
+                                               listsubrepos, root)
+            self._always = False
+            self.matchfn = pm
+        else:
+            self._anypats = False
+            self.patternspat = None
             self._always = True
-        elif len(matchfns) == 1:
-            m = matchfns[0]
-        else:
-            def m(f):
-                for matchfn in matchfns:
-                    if not matchfn(f):
-                        return False
-                return True
-
-        self.matchfn = m
+            self.matchfn = lambda f: True
 
     @propertycache
     def _dirs(self):