Show More
@@ -563,6 +563,36 b' class predicatematcher(basematcher):' | |||
|
563 | 563 | return b'<predicatenmatcher pred=%s>' % s |
|
564 | 564 | |
|
565 | 565 | |
|
566 | def path_or_parents_in_set(path, prefix_set): | |
|
567 | """Returns True if `path` (or any parent of `path`) is in `prefix_set`.""" | |
|
568 | l = len(prefix_set) | |
|
569 | if l == 0: | |
|
570 | return False | |
|
571 | if path in prefix_set: | |
|
572 | return True | |
|
573 | # If there's more than 5 paths in prefix_set, it's *probably* quicker to | |
|
574 | # "walk up" the directory hierarchy instead, with the assumption that most | |
|
575 | # directory hierarchies are relatively shallow and hash lookup is cheap. | |
|
576 | if l > 5: | |
|
577 | return any( | |
|
578 | parentdir in prefix_set for parentdir in pathutil.finddirs(path) | |
|
579 | ) | |
|
580 | ||
|
581 | # FIXME: Ideally we'd never get to this point if this is the case - we'd | |
|
582 | # recognize ourselves as an 'always' matcher and skip this. | |
|
583 | if b'' in prefix_set: | |
|
584 | return True | |
|
585 | ||
|
586 | if pycompat.ispy3: | |
|
587 | sl = ord(b'/') | |
|
588 | else: | |
|
589 | sl = '/' | |
|
590 | ||
|
591 | # We already checked that path isn't in prefix_set exactly, so | |
|
592 | # `path[len(pf)] should never raise IndexError. | |
|
593 | return any(path.startswith(pf) and path[len(pf)] == sl for pf in prefix_set) | |
|
594 | ||
|
595 | ||
|
566 | 596 | class patternmatcher(basematcher): |
|
567 | 597 | r"""Matches a set of (kind, pat, source) against a 'root' directory. |
|
568 | 598 | |
@@ -611,12 +641,8 b' class patternmatcher(basematcher):' | |||
|
611 | 641 | if self._prefix and dir in self._fileset: |
|
612 | 642 | return b'all' |
|
613 | 643 | return ( |
|
614 |
dir in self._ |
|
|
615 |
or dir |
|
|
616 | or any( | |
|
617 | parentdir in self._fileset | |
|
618 | for parentdir in pathutil.finddirs(dir) | |
|
619 | ) | |
|
644 | dir in self._dirs | |
|
645 | or path_or_parents_in_set(dir, self._fileset) | |
|
620 | 646 | ) |
|
621 | 647 | |
|
622 | 648 | def visitchildrenset(self, dir): |
@@ -698,12 +724,9 b' class includematcher(basematcher):' | |||
|
698 | 724 | if self._prefix and dir in self._roots: |
|
699 | 725 | return b'all' |
|
700 | 726 | return ( |
|
701 |
dir in self._r |
|
|
702 | or dir in self._dirs | |
|
727 | dir in self._dirs | |
|
703 | 728 | or dir in self._parents |
|
704 | or any( | |
|
705 | parentdir in self._roots for parentdir in pathutil.finddirs(dir) | |
|
706 | ) | |
|
729 | or path_or_parents_in_set(dir, self._roots) | |
|
707 | 730 | ) |
|
708 | 731 | |
|
709 | 732 | @propertycache |
@@ -726,11 +749,8 b' class includematcher(basematcher):' | |||
|
726 | 749 | # visitdir, that's handled below. |
|
727 | 750 | if ( |
|
728 | 751 | b'' in self._roots |
|
729 | or dir in self._roots | |
|
730 | 752 | or dir in self._dirs |
|
731 | or any( | |
|
732 | parentdir in self._roots for parentdir in pathutil.finddirs(dir) | |
|
733 | ) | |
|
753 | or path_or_parents_in_set(dir, self._roots) | |
|
734 | 754 | ): |
|
735 | 755 | return b'this' |
|
736 | 756 |
General Comments 0
You need to be logged in to leave comments.
Login now