Patchwork [17,of,17] match: remove special-casing of always-matching patterns in patternmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 25, 2017, 6:24 p.m.
Message ID <5a2d63a7aee98d9ac6f2.1495736698@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20919/
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 1495224975 25200
#      Fri May 19 13:16:15 2017 -0700
# Node ID 5a2d63a7aee98d9ac6f216eca60e4017a3d38a07
# Parent  ec486afeb2c980d6a5959a27159fc8e629f33dd2
match: remove special-casing of always-matching patterns in patternmatcher

Note that we need to teach alwaysmatcher to use relative paths now in
cases like "hg files .." from inside mercurial/, because while it
still matches everything, paths should be printed relative to the
working directory.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -146,8 +146,11 @@ 
         m = exactmatcher(root, cwd, patterns, badfn)
     elif patterns:
         kindpats = normalize(patterns, default, root, cwd, auditor, warn)
-        m = patternmatcher(root, cwd, kindpats, ctx=ctx,
-                           listsubrepos=listsubrepos, badfn=badfn)
+        if _kindpatsalwaysmatch(kindpats):
+            m = alwaysmatcher(root, cwd, badfn, relativeuipath=True)
+        else:
+            m = patternmatcher(root, cwd, kindpats, ctx=ctx,
+                               listsubrepos=listsubrepos, badfn=badfn)
     else:
         # It's a little strange that no patterns means to match everything.
         # Consider changing this to match nothing (probably adding a
@@ -318,11 +321,11 @@ 
 
 class alwaysmatcher(basematcher):
 
-    def __init__(self, root, cwd, badfn=None):
+    def __init__(self, root, cwd, badfn=None, relativeuipath=False):
         super(alwaysmatcher, self).__init__(root, cwd, badfn)
-
-    def uipath(self, f):
-        return self.abs(f)
+        self.uipath = self.abs
+        if relativeuipath:
+            self.uipath = self.rel
 
     def always(self):
         return True
@@ -342,26 +345,17 @@ 
                  badfn=None):
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
-        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
-            self.matchfn = lambda f: True
+        self._files = _explicitfiles(kindpats)
+        self._anypats = _anypats(kindpats)
+        self.patternspat, pm = _buildmatch(ctx, kindpats, '$', listsubrepos,
+                                           root)
+        self.matchfn = pm
 
     @propertycache
     def _dirs(self):
         return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
-        if self.always():
-            return 'all'
         if self.prefix() and dir in self._fileset:
             return 'all'
         return ('.' in self._fileset or
@@ -373,9 +367,6 @@ 
     def anypats(self):
         return self._anypats
 
-    def always(self):
-        return self._always
-
     def __repr__(self):
         return ('<patternmatcher patterns=%r>' % self.patternspat)