Mercurial > hg
comparison mercurial/match.py @ 33405:6aa643762641
match: inverse _anypats(), making it _prefix()
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 11 Jul 2017 09:42:32 -0700 |
parents | 892d255ec2a1 |
children | 6f4e5e5940a5 |
comparison
equal
deleted
inserted
replaced
33404:0d5afd360e9e | 33405:6aa643762641 |
---|---|
371 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, | 371 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, |
372 badfn=None): | 372 badfn=None): |
373 super(patternmatcher, self).__init__(root, cwd, badfn) | 373 super(patternmatcher, self).__init__(root, cwd, badfn) |
374 | 374 |
375 self._files = _explicitfiles(kindpats) | 375 self._files = _explicitfiles(kindpats) |
376 self._anypats = _anypats(kindpats) | 376 self._prefix = _prefix(kindpats) |
377 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos, | 377 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos, |
378 root) | 378 root) |
379 | 379 |
380 @propertycache | 380 @propertycache |
381 def _dirs(self): | 381 def _dirs(self): |
382 return set(util.dirs(self._fileset)) | {'.'} | 382 return set(util.dirs(self._fileset)) | {'.'} |
383 | 383 |
384 def visitdir(self, dir): | 384 def visitdir(self, dir): |
385 if self.prefix() and dir in self._fileset: | 385 if self._prefix and dir in self._fileset: |
386 return 'all' | 386 return 'all' |
387 return ('.' in self._fileset or | 387 return ('.' in self._fileset or |
388 dir in self._fileset or | 388 dir in self._fileset or |
389 dir in self._dirs or | 389 dir in self._dirs or |
390 any(parentdir in self._fileset | 390 any(parentdir in self._fileset |
391 for parentdir in util.finddirs(dir))) | 391 for parentdir in util.finddirs(dir))) |
392 | 392 |
393 def prefix(self): | 393 def prefix(self): |
394 return not self._anypats | 394 return self._prefix |
395 | 395 |
396 def __repr__(self): | 396 def __repr__(self): |
397 return ('<patternmatcher patterns=%r>' % self._pats) | 397 return ('<patternmatcher patterns=%r>' % self._pats) |
398 | 398 |
399 class includematcher(basematcher): | 399 class includematcher(basematcher): |
402 badfn=None): | 402 badfn=None): |
403 super(includematcher, self).__init__(root, cwd, badfn) | 403 super(includematcher, self).__init__(root, cwd, badfn) |
404 | 404 |
405 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)', | 405 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)', |
406 listsubrepos, root) | 406 listsubrepos, root) |
407 self._anypats = _anypats(kindpats) | 407 self._prefix = _prefix(kindpats) |
408 roots, dirs = _rootsanddirs(kindpats) | 408 roots, dirs = _rootsanddirs(kindpats) |
409 # roots are directories which are recursively included. | 409 # roots are directories which are recursively included. |
410 self._roots = set(roots) | 410 self._roots = set(roots) |
411 # dirs are directories which are non-recursively included. | 411 # dirs are directories which are non-recursively included. |
412 self._dirs = set(dirs) | 412 self._dirs = set(dirs) |
413 | 413 |
414 def visitdir(self, dir): | 414 def visitdir(self, dir): |
415 if not self._anypats and dir in self._roots: | 415 if self._prefix and dir in self._roots: |
416 # The condition above is essentially self.prefix() for includes | |
417 return 'all' | 416 return 'all' |
418 return ('.' in self._roots or | 417 return ('.' in self._roots or |
419 dir in self._roots or | 418 dir in self._roots or |
420 dir in self._dirs or | 419 dir in self._dirs or |
421 any(parentdir in self._roots | 420 any(parentdir in self._roots |
946 # Keep only the pattern kinds where one can specify filenames (vs only | 945 # Keep only the pattern kinds where one can specify filenames (vs only |
947 # directory names). | 946 # directory names). |
948 filable = [kp for kp in kindpats if kp[0] not in ('rootfilesin',)] | 947 filable = [kp for kp in kindpats if kp[0] not in ('rootfilesin',)] |
949 return _roots(filable) | 948 return _roots(filable) |
950 | 949 |
951 def _anypats(kindpats): | 950 def _prefix(kindpats): |
951 '''Whether all the patterns match a prefix (i.e. recursively)''' | |
952 for kind, pat, source in kindpats: | 952 for kind, pat, source in kindpats: |
953 if kind in ('glob', 're', 'relglob', 'relre', 'set', 'rootfilesin'): | 953 if kind not in ('path', 'relpath'): |
954 return True | 954 return False |
955 return True | |
955 | 956 |
956 _commentre = None | 957 _commentre = None |
957 | 958 |
958 def readpatternfile(filepath, warn, sourceinfo=False): | 959 def readpatternfile(filepath, warn, sourceinfo=False): |
959 '''parse a pattern file, returning a list of | 960 '''parse a pattern file, returning a list of |