[PATCH 2 of 5] match: add option to return line and lineno from readpattern

Laurent Charignon lcharignon at fb.com
Sat Dec 26 21:40:28 CST 2015


Ok, I am sending a V2.

Thanks,

Laurent

> On Dec 25, 2015, at 9:21 AM, Gilles Moris <gilles.moris at free.fr> wrote:
> 
> 
> 
> Le 23/12/2015 21:42, Laurent Charignon a écrit :
>> # HG changeset patch
>> # User Laurent Charignon <lcharignon at fb.com>
>> # Date 1450900540 28800
>> #      Wed Dec 23 11:55:40 2015 -0800
>> # Node ID 391510022f76e3fc135b78b4cb14dec73a3761cb
>> # 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):
> Conventionally, line numbers start at 1, so may be enumerate(fp, start=1)
> 
> Regards.
> Gilles.
> 
>>          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
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel at selenic.com
>> https://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list