From patchwork Thu May 25 18:24:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [14,of,17] match: introduce alwaysmatcher From: via Mercurial-devel X-Patchwork-Id: 20916 Message-Id: <3f19697ac9db9a9dc871.1495736695@martinvonz.svl.corp.google.com> To: mercurial-devel@mercurial-scm.org Date: Thu, 25 May 2017 11:24:55 -0700 # HG changeset patch # User Martin von Zweigbergk # 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. 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 '' + 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: + matcher: 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: + matcher: f beans/black beans/black f beans/borlotti beans/borlotti f beans/kidney beans/kidney @@ -61,7 +61,7 @@ $ cd mammals $ hg debugwalk - matcher: + matcher: 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: , m2=> + matcher: , m2=> f fennel ../fennel f fenugreek ../fenugreek f fiddlehead ../fiddlehead @@ -146,7 +146,7 @@ f fenugreek ../fenugreek f fiddlehead ../fiddlehead $ hg debugwalk -X 'rootfilesin:' - matcher: , m2=> + matcher: , m2=> f beans/black ../beans/black f beans/borlotti ../beans/borlotti f beans/kidney ../beans/kidney @@ -194,7 +194,7 @@ matcher: f mammals/skunk skunk $ hg debugwalk -X 'rootfilesin:mammals' - matcher: , m2=> + matcher: , m2=> f beans/black ../beans/black f beans/borlotti ../beans/borlotti f beans/kidney ../beans/kidney