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.
--- a/mercurial/match.py Fri May 26 13:08:30 2017 -0700
+++ b/mercurial/match.py Fri May 19 11:50:01 2017 -0700
@@ -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',
--- a/tests/test-eolfilename.t Fri May 26 13:08:30 2017 -0700
+++ b/tests/test-eolfilename.t Fri May 19 11:50:01 2017 -0700
@@ -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
--- a/tests/test-walk.t Fri May 26 13:08:30 2017 -0700
+++ b/tests/test-walk.t Fri May 19 11:50:01 2017 -0700
@@ -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