mercurial/match.py
changeset 27595 9e2d01707e71
parent 27343 c59647c6694d
child 28017 d3f1b7ee5e70
equal deleted inserted replaced
27594:0921caca7703 27595:9e2d01707e71
   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
   689                 break
   693                 break
   690             elif line.startswith(s+':'):
   694             elif line.startswith(s+':'):
   691                 linesyntax = rels
   695                 linesyntax = rels
   692                 line = line[len(s) + 1:]
   696                 line = line[len(s) + 1:]
   693                 break
   697                 break
   694         patterns.append(linesyntax + line)
   698         if sourceinfo:
       
   699             patterns.append((linesyntax + line, lineno, line))
       
   700         else:
       
   701             patterns.append(linesyntax + line)
   695     fp.close()
   702     fp.close()
   696     return patterns
   703     return patterns