mercurial/match.py
changeset 27595 9e2d01707e71
parent 27343 c59647c6694d
child 28017 d3f1b7ee5e70
--- 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