Mercurial > hg
comparison mercurial/match.py @ 32466:12e241b2713c
match: remove support for excludes from matcher class
The support is now provided by differencematcher() and still available
via the match() function.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 16 May 2017 22:15:42 -0700 |
parents | a83a7d27911e |
children | ca77a243ffa7 |
comparison
equal
deleted
inserted
replaced
32465:a83a7d27911e | 32466:12e241b2713c |
---|---|
140 kindpats.append((kind, p, source)) | 140 kindpats.append((kind, p, source)) |
141 | 141 |
142 kindpats.append((kind, pats, source)) | 142 kindpats.append((kind, pats, source)) |
143 return kindpats | 143 return kindpats |
144 | 144 |
145 m = matcher(root, cwd, normalize, patterns, include=include, exclude=None, | 145 m = matcher(root, cwd, normalize, patterns, include=include, |
146 default=default, exact=exact, auditor=auditor, ctx=ctx, | 146 default=default, exact=exact, auditor=auditor, ctx=ctx, |
147 listsubrepos=listsubrepos, warn=warn, badfn=badfn) | 147 listsubrepos=listsubrepos, warn=warn, badfn=badfn) |
148 if exclude: | 148 if exclude: |
149 em = matcher(root, cwd, normalize, [], include=exclude, exclude=None, | 149 em = matcher(root, cwd, normalize, [], include=exclude, default=default, |
150 default=default, exact=False, auditor=auditor, ctx=ctx, | 150 exact=False, auditor=auditor, ctx=ctx, |
151 listsubrepos=listsubrepos, warn=warn, badfn=None) | 151 listsubrepos=listsubrepos, warn=warn, badfn=None) |
152 m = differencematcher(m, em) | 152 m = differencematcher(m, em) |
153 return m | 153 return m |
154 | 154 |
155 def exact(root, cwd, files, badfn=None): | 155 def exact(root, cwd, files, badfn=None): |
303 return not self.always() and not self.isexact() and not self.anypats() | 303 return not self.always() and not self.isexact() and not self.anypats() |
304 | 304 |
305 class matcher(basematcher): | 305 class matcher(basematcher): |
306 | 306 |
307 def __init__(self, root, cwd, normalize, patterns, include=None, | 307 def __init__(self, root, cwd, normalize, patterns, include=None, |
308 exclude=None, default='glob', exact=False, auditor=None, | 308 default='glob', exact=False, auditor=None, ctx=None, |
309 ctx=None, listsubrepos=False, warn=None, badfn=None): | 309 listsubrepos=False, warn=None, badfn=None): |
310 super(matcher, self).__init__(root, cwd, badfn) | 310 super(matcher, self).__init__(root, cwd, badfn) |
311 if include is None: | 311 if include is None: |
312 include = [] | 312 include = [] |
313 if exclude is None: | 313 |
314 exclude = [] | 314 self._anypats = bool(include) |
315 | |
316 self._anypats = bool(include or exclude) | |
317 self._anyincludepats = False | 315 self._anyincludepats = False |
318 self._always = False | 316 self._always = False |
319 self._pathrestricted = bool(include or exclude or patterns) | 317 self._pathrestricted = bool(include or patterns) |
320 self.patternspat = None | 318 self.patternspat = None |
321 self.includepat = None | 319 self.includepat = None |
322 self.excludepat = None | 320 |
323 | 321 # roots are directories which are recursively included. |
324 # roots are directories which are recursively included/excluded. | |
325 self._includeroots = set() | 322 self._includeroots = set() |
326 self._excluderoots = set() | |
327 # dirs are directories which are non-recursively included. | 323 # dirs are directories which are non-recursively included. |
328 self._includedirs = set() | 324 self._includedirs = set() |
329 | 325 |
330 matchfns = [] | 326 matchfns = [] |
331 if include: | 327 if include: |
335 self._anyincludepats = _anypats(kindpats) | 331 self._anyincludepats = _anypats(kindpats) |
336 roots, dirs = _rootsanddirs(kindpats) | 332 roots, dirs = _rootsanddirs(kindpats) |
337 self._includeroots.update(roots) | 333 self._includeroots.update(roots) |
338 self._includedirs.update(dirs) | 334 self._includedirs.update(dirs) |
339 matchfns.append(im) | 335 matchfns.append(im) |
340 if exclude: | |
341 kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn) | |
342 self.excludepat, em = _buildmatch(ctx, kindpats, '(?:/|$)', | |
343 listsubrepos, root) | |
344 if not _anypats(kindpats): | |
345 # Only consider recursive excludes as such - if a non-recursive | |
346 # exclude is used, we must still recurse into the excluded | |
347 # directory, at least to find subdirectories. In such a case, | |
348 # the regex still won't match the non-recursively-excluded | |
349 # files. | |
350 self._excluderoots.update(_roots(kindpats)) | |
351 matchfns.append(lambda f: not em(f)) | |
352 if exact: | 336 if exact: |
353 if isinstance(patterns, list): | 337 if isinstance(patterns, list): |
354 self._files = patterns | 338 self._files = patterns |
355 else: | 339 else: |
356 self._files = list(patterns) | 340 self._files = list(patterns) |
386 return set(util.dirs(self._fileset)) | {'.'} | 370 return set(util.dirs(self._fileset)) | {'.'} |
387 | 371 |
388 def visitdir(self, dir): | 372 def visitdir(self, dir): |
389 if self.prefix() and dir in self._fileset: | 373 if self.prefix() and dir in self._fileset: |
390 return 'all' | 374 return 'all' |
391 if dir in self._excluderoots: | |
392 return False | |
393 if self._includeroots or self._includedirs: | 375 if self._includeroots or self._includedirs: |
394 if (not self._anyincludepats and | 376 if (not self._anyincludepats and |
395 not self._excluderoots and | |
396 dir in self._includeroots): | 377 dir in self._includeroots): |
397 # The condition above is essentially self.prefix() for includes | 378 # The condition above is essentially self.prefix() for includes |
398 return 'all' | 379 return 'all' |
399 if ('.' not in self._includeroots and | 380 if ('.' not in self._includeroots and |
400 dir not in self._includeroots and | 381 dir not in self._includeroots and |
417 | 398 |
418 def isexact(self): | 399 def isexact(self): |
419 return self.matchfn == self.exact | 400 return self.matchfn == self.exact |
420 | 401 |
421 def __repr__(self): | 402 def __repr__(self): |
422 return ('<matcher files=%r, patterns=%r, includes=%r, excludes=%r>' % | 403 return ('<matcher files=%r, patterns=%r, includes=%r>' % |
423 (self._files, self.patternspat, self.includepat, | 404 (self._files, self.patternspat, self.includepat)) |
424 self.excludepat)) | |
425 | 405 |
426 class differencematcher(basematcher): | 406 class differencematcher(basematcher): |
427 '''Composes two matchers by matching if the first matches and the second | 407 '''Composes two matchers by matching if the first matches and the second |
428 does not. Well, almost... If the user provides a pattern like "-X foo foo", | 408 does not. Well, almost... If the user provides a pattern like "-X foo foo", |
429 Mercurial actually does match "foo" against that. That's because exact | 409 Mercurial actually does match "foo" against that. That's because exact |