Patchwork [1,of,5] match: handle everything-matching using new alwaysmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 30, 2017, 6:50 a.m.
Message ID <6be5ea3cf222fd799abf.1496127031@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21057/
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 1495219801 25200
#      Fri May 19 11:50:01 2017 -0700
# Node ID 6be5ea3cf222fd799abff57f42e48da5a764c0a7
# Parent  cf7c88986e9f64926bdf79b04e2777d730cf8cb0
match: handle everything-matching using new alwaysmatcher

Having a special matcher that always matches seems to make more sense
than making one of the other matchers handle the case. For now, we
just use this new matcher when no patterns were provided.
Yuya Nishihara - May 31, 2017, 12:40 p.m.
On Mon, 29 May 2017 23:50:31 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1495219801 25200
> #      Fri May 19 11:50:01 2017 -0700
> # Node ID 6be5ea3cf222fd799abff57f42e48da5a764c0a7
> # Parent  cf7c88986e9f64926bdf79b04e2777d730cf8cb0
> match: handle everything-matching using new alwaysmatcher

Great. Queued these, thanks.

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
@@ -311,6 +317,25 @@ 
     def prefix(self):
         return not self.always() and not self.isexact() and not self.anypats()
 
+class alwaysmatcher(basematcher):
+    '''Matches everything.'''
+
+    def __init__(self, root, cwd, badfn=None):
+        super(alwaysmatcher, self).__init__(root, cwd, badfn,
+                                            relativeuipath=False)
+
+    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