Patchwork [14,of,17] match: introduce alwaysmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 25, 2017, 6:24 p.m.
Message ID <3f19697ac9db9a9dc871.1495736695@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20916/
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 1495219801 25200
#      Fri May 19 11:50:01 2017 -0700
# Node ID 3f19697ac9db9a9dc8716f830cc43421d3c3274f
# Parent  85bcfda434b272bbbedffcf0037c5008759fb748
match: introduce alwaysmatcher

Having a special matcher that always matches seems to make more sense
than making on of the other matchers handle the case. For now, we just
use this new matcher when no patterns were provided. We'll simplify
patternmatcher soon.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -144,10 +144,16 @@ 
 
     if exact:
         m = exactmatcher(root, cwd, patterns, badfn)
-    else:
+    elif patterns:
         m = patternmatcher(root, cwd, normalize, patterns, default=default,
                            auditor=auditor, ctx=ctx, listsubrepos=listsubrepos,
                            warn=warn, badfn=badfn)
+    else:
+        # It's a little strange that no patterns means to match everything.
+        # Consider changing this to match nothing (probably adding a
+        # "nevermatcher").
+        m = alwaysmatcher(root, cwd, badfn)
+
     if include:
         im = includematcher(root, cwd, normalize, include, auditor=auditor,
                             ctx=ctx, listsubrepos=listsubrepos, warn=warn,
@@ -164,7 +170,7 @@ 
     return exactmatcher(root, cwd, files, badfn=badfn)
 
 def always(root, cwd):
-    return match(root, cwd, [])
+    return alwaysmatcher(root, cwd)
 
 def badmatch(match, badfn):
     """Make a copy of the given matcher, replacing its bad method with the given
@@ -310,6 +316,26 @@ 
     def prefix(self):
         return not self.always() and not self.isexact() and not self.anypats()
 
+class alwaysmatcher(basematcher):
+
+    def __init__(self, root, cwd, badfn=None):
+        super(alwaysmatcher, self).__init__(root, cwd, badfn)
+
+    def uipath(self, f):
+        return self.abs(f)
+
+    def always(self):
+        return True
+
+    def matchfn(self, f):
+        return True
+
+    def visitdir(self, dir):
+        return 'all'
+
+    def __repr__(self):
+        return '<alwaysmatcher>'
+
 class patternmatcher(basematcher):
 
     def __init__(self, root, cwd, normalize, patterns, default='glob',
diff --git a/tests/test-eolfilename.t b/tests/test-eolfilename.t
--- a/tests/test-eolfilename.t
+++ b/tests/test-eolfilename.t
@@ -33,7 +33,7 @@ 
   [255]
   $ echo foo > "$A"
   $ hg debugwalk
-  matcher: <patternmatcher patterns=None>
+  matcher: <alwaysmatcher>
   f  he\r (no-eol) (esc)
   llo  he\r (no-eol) (esc)
   llo
diff --git a/tests/test-walk.t b/tests/test-walk.t
--- a/tests/test-walk.t
+++ b/tests/test-walk.t
@@ -29,7 +29,7 @@ 
   $ hg commit -m "commit #0"
 
   $ hg debugwalk
-  matcher: <patternmatcher patterns=None>
+  matcher: <alwaysmatcher>
   f  beans/black                     beans/black
   f  beans/borlotti                  beans/borlotti
   f  beans/kidney                    beans/kidney
@@ -61,7 +61,7 @@ 
 
   $ cd mammals
   $ hg debugwalk
-  matcher: <patternmatcher patterns=None>
+  matcher: <alwaysmatcher>
   f  beans/black                     ../beans/black
   f  beans/borlotti                  ../beans/borlotti
   f  beans/kidney                    ../beans/kidney
@@ -76,7 +76,7 @@ 
   f  mammals/Procyonidae/raccoon     Procyonidae/raccoon
   f  mammals/skunk                   skunk
   $ hg debugwalk -X ../beans
-  matcher: <differencematcher m1=<patternmatcher patterns=None>, m2=<includematcher includes='(?:beans(?:/|$))'>>
+  matcher: <differencematcher m1=<alwaysmatcher>, m2=<includematcher includes='(?:beans(?:/|$))'>>
   f  fennel                          ../fennel
   f  fenugreek                       ../fenugreek
   f  fiddlehead                      ../fiddlehead
@@ -146,7 +146,7 @@ 
   f  fenugreek   ../fenugreek
   f  fiddlehead  ../fiddlehead
   $ hg debugwalk -X 'rootfilesin:'
-  matcher: <differencematcher m1=<patternmatcher patterns=None>, m2=<includematcher includes='(?:^[^/]+$)'>>
+  matcher: <differencematcher m1=<alwaysmatcher>, m2=<includematcher includes='(?:^[^/]+$)'>>
   f  beans/black                     ../beans/black
   f  beans/borlotti                  ../beans/borlotti
   f  beans/kidney                    ../beans/kidney
@@ -194,7 +194,7 @@ 
   matcher: <includematcher includes='(?:^mammals/[^/]+$)'>
   f  mammals/skunk  skunk
   $ hg debugwalk -X 'rootfilesin:mammals'
-  matcher: <differencematcher m1=<patternmatcher patterns=None>, m2=<includematcher includes='(?:^mammals/[^/]+$)'>>
+  matcher: <differencematcher m1=<alwaysmatcher>, m2=<includematcher includes='(?:^mammals/[^/]+$)'>>
   f  beans/black                     ../beans/black
   f  beans/borlotti                  ../beans/borlotti
   f  beans/kidney                    ../beans/kidney