Mercurial > hg
comparison mercurial/match.py @ 32553:20c9f3ecc192
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.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 19 May 2017 11:50:01 -0700 |
parents | e7aa11f3abcd |
children | f44ea253ffe2 |
comparison
equal
deleted
inserted
replaced
32552:e7aa11f3abcd | 32553:20c9f3ecc192 |
---|---|
142 kindpats.append((kind, pats, source)) | 142 kindpats.append((kind, pats, source)) |
143 return kindpats | 143 return kindpats |
144 | 144 |
145 if exact: | 145 if exact: |
146 m = exactmatcher(root, cwd, patterns, badfn) | 146 m = exactmatcher(root, cwd, patterns, badfn) |
147 else: | 147 elif patterns: |
148 m = patternmatcher(root, cwd, normalize, patterns, default=default, | 148 m = patternmatcher(root, cwd, normalize, patterns, default=default, |
149 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, | 149 auditor=auditor, ctx=ctx, listsubrepos=listsubrepos, |
150 warn=warn, badfn=badfn) | 150 warn=warn, badfn=badfn) |
151 else: | |
152 # It's a little strange that no patterns means to match everything. | |
153 # Consider changing this to match nothing (probably adding a | |
154 # "nevermatcher"). | |
155 m = alwaysmatcher(root, cwd, badfn) | |
156 | |
151 if include: | 157 if include: |
152 im = includematcher(root, cwd, normalize, include, auditor=auditor, | 158 im = includematcher(root, cwd, normalize, include, auditor=auditor, |
153 ctx=ctx, listsubrepos=listsubrepos, warn=warn, | 159 ctx=ctx, listsubrepos=listsubrepos, warn=warn, |
154 badfn=None) | 160 badfn=None) |
155 m = intersectmatchers(m, im) | 161 m = intersectmatchers(m, im) |
162 | 168 |
163 def exact(root, cwd, files, badfn=None): | 169 def exact(root, cwd, files, badfn=None): |
164 return exactmatcher(root, cwd, files, badfn=badfn) | 170 return exactmatcher(root, cwd, files, badfn=badfn) |
165 | 171 |
166 def always(root, cwd): | 172 def always(root, cwd): |
167 return match(root, cwd, []) | 173 return alwaysmatcher(root, cwd) |
168 | 174 |
169 def badmatch(match, badfn): | 175 def badmatch(match, badfn): |
170 """Make a copy of the given matcher, replacing its bad method with the given | 176 """Make a copy of the given matcher, replacing its bad method with the given |
171 one. | 177 one. |
172 """ | 178 """ |
308 def isexact(self): | 314 def isexact(self): |
309 return False | 315 return False |
310 | 316 |
311 def prefix(self): | 317 def prefix(self): |
312 return not self.always() and not self.isexact() and not self.anypats() | 318 return not self.always() and not self.isexact() and not self.anypats() |
319 | |
320 class alwaysmatcher(basematcher): | |
321 '''Matches everything.''' | |
322 | |
323 def __init__(self, root, cwd, badfn=None): | |
324 super(alwaysmatcher, self).__init__(root, cwd, badfn, | |
325 relativeuipath=False) | |
326 | |
327 def always(self): | |
328 return True | |
329 | |
330 def matchfn(self, f): | |
331 return True | |
332 | |
333 def visitdir(self, dir): | |
334 return 'all' | |
335 | |
336 def __repr__(self): | |
337 return '<alwaysmatcher>' | |
313 | 338 |
314 class patternmatcher(basematcher): | 339 class patternmatcher(basematcher): |
315 | 340 |
316 def __init__(self, root, cwd, normalize, patterns, default='glob', | 341 def __init__(self, root, cwd, normalize, patterns, default='glob', |
317 auditor=None, ctx=None, listsubrepos=False, warn=None, | 342 auditor=None, ctx=None, listsubrepos=False, warn=None, |