[PATCH 2 of 5 V2] match: add option to return line and lineno from readpattern
Laurent Charignon
lcharignon at fb.com
Sat Dec 26 21:41:31 CST 2015
# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1451187638 28800
# Sat Dec 26 19:40:38 2015 -0800
# Node ID 6b3004e5fd2b94fbe2397263465ab8d3acf683d1
# Parent 327bb58234a16dacf42ea57ff4dcb2c698f28638
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 --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -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
More information about the Mercurial-devel
mailing list