630 if kind in ('glob', 're', 'relglob', 'relre', 'set'): |
630 if kind in ('glob', 're', 'relglob', 'relre', 'set'): |
631 return True |
631 return True |
632 |
632 |
633 _commentre = None |
633 _commentre = None |
634 |
634 |
635 def readpatternfile(filepath, warn): |
635 def readpatternfile(filepath, warn, sourceinfo=False): |
636 '''parse a pattern file, returning a list of |
636 '''parse a pattern file, returning a list of |
637 patterns. These patterns should be given to compile() |
637 patterns. These patterns should be given to compile() |
638 to be validated and converted into a match function. |
638 to be validated and converted into a match function. |
639 |
639 |
640 trailing white space is dropped. |
640 trailing white space is dropped. |
646 |
646 |
647 syntax: regexp # defaults following lines to non-rooted regexps |
647 syntax: regexp # defaults following lines to non-rooted regexps |
648 syntax: glob # defaults following lines to non-rooted globs |
648 syntax: glob # defaults following lines to non-rooted globs |
649 re:pattern # non-rooted regular expression |
649 re:pattern # non-rooted regular expression |
650 glob:pattern # non-rooted glob |
650 glob:pattern # non-rooted glob |
651 pattern # pattern of the current default type''' |
651 pattern # pattern of the current default type |
|
652 |
|
653 if sourceinfo is set, returns a list of tuples: |
|
654 (pattern, lineno, originalline). This is useful to debug ignore patterns. |
|
655 ''' |
652 |
656 |
653 syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:', |
657 syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:', |
654 'include': 'include', 'subinclude': 'subinclude'} |
658 'include': 'include', 'subinclude': 'subinclude'} |
655 syntax = 'relre:' |
659 syntax = 'relre:' |
656 patterns = [] |
660 patterns = [] |
657 |
661 |
658 fp = open(filepath) |
662 fp = open(filepath) |
659 for line in fp: |
663 for lineno, line in enumerate(fp, start=1): |
660 if "#" in line: |
664 if "#" in line: |
661 global _commentre |
665 global _commentre |
662 if not _commentre: |
666 if not _commentre: |
663 _commentre = util.re.compile(r'((?:^|[^\\])(?:\\\\)*)#.*') |
667 _commentre = util.re.compile(r'((?:^|[^\\])(?:\\\\)*)#.*') |
664 # remove comments prefixed by an even number of escapes |
668 # remove comments prefixed by an even number of escapes |