# HG changeset patch # User Laurent Charignon # Date 1451187638 28800 # Node ID 9e2d01707e7128af5aa50cb6bffa97269c887a98 # Parent 0921caca7703ec7c86afbb964aa4dc028592cfc9 match: add option to return line and lineno from readpattern This will be used to display the line and linenumber of ignorefile that matched an ignored file (issue4856). diff -r 0921caca7703 -r 9e2d01707e71 mercurial/match.py --- a/mercurial/match.py Wed Dec 23 11:52:54 2015 -0800 +++ b/mercurial/match.py Sat Dec 26 19:40:38 2015 -0800 @@ -632,7 +632,7 @@ _commentre = None -def readpatternfile(filepath, warn): +def readpatternfile(filepath, warn, sourceinfo=False): '''parse a pattern file, returning a list of patterns. These patterns should be given to compile() to be validated and converted into a match function. @@ -648,7 +648,11 @@ syntax: glob # defaults following lines to non-rooted globs re:pattern # non-rooted regular expression glob:pattern # non-rooted glob - pattern # pattern of the current default type''' + pattern # pattern of the current default type + + if sourceinfo is set, returns a list of tuples: + (pattern, lineno, originalline). This is useful to debug ignore patterns. + ''' syntaxes = {'re': 'relre:', 'regexp': 'relre:', 'glob': 'relglob:', 'include': 'include', 'subinclude': 'subinclude'} @@ -656,7 +660,7 @@ patterns = [] fp = open(filepath) - for line in fp: + for lineno, line in enumerate(fp, start=1): if "#" in line: global _commentre if not _commentre: @@ -691,6 +695,9 @@ linesyntax = rels line = line[len(s) + 1:] break - patterns.append(linesyntax + line) + if sourceinfo: + patterns.append((linesyntax + line, lineno, line)) + else: + patterns.append(linesyntax + line) fp.close() return patterns