Patchwork [15,of,17] match: drop support for empty pattern list in patternmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 25, 2017, 6:24 p.m.
Message ID <12576790a6d03a4319f1.1495736696@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20917/
State Accepted
Headers show

Comments

via Mercurial-devel - May 25, 2017, 6:24 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495220296 25200
#      Fri May 19 11:58:16 2017 -0700
# Node ID 12576790a6d03a4319f10d8504076a856c2155fb
# Parent  3f19697ac9db9a9dc8716f830cc43421d3c3274f
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 no in-core
caller will pass no patterns yet).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -343,37 +343,19 @@ 
                  badfn=None):
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
-        self._anypats = False
-        self._always = False
-        self._pathrestricted = bool(patterns)
-        self.patternspat = None
-
-        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
-
-    def uipath(self, f):
-        return (self._pathrestricted and self.rel(f)) or self.abs(f)
+            self.matchfn = lambda f: True
 
     @propertycache
     def _dirs(self):