Mercurial > hg
comparison mercurial/match.py @ 25214:08703b10c3ae
match: add optional warn argument
Occasionally the matcher will want to print warning messages instead of throwing
exceptions (like if it encounters a bad syntax parameter when parsing files).
Let's add an optional warn argument that can provide this. The next patch will
actually use this argument.
author | Durham Goode <durham@fb.com> |
---|---|
date | Mon, 18 May 2015 16:27:56 -0700 |
parents | 08a8e9da0ae7 |
children | 4040e06e9b99 |
comparison
equal
deleted
inserted
replaced
25213:08a8e9da0ae7 | 25214:08703b10c3ae |
---|---|
52 return True | 52 return True |
53 | 53 |
54 class match(object): | 54 class match(object): |
55 def __init__(self, root, cwd, patterns, include=[], exclude=[], | 55 def __init__(self, root, cwd, patterns, include=[], exclude=[], |
56 default='glob', exact=False, auditor=None, ctx=None, | 56 default='glob', exact=False, auditor=None, ctx=None, |
57 listsubrepos=False): | 57 listsubrepos=False, warn=None): |
58 """build an object to match a set of file patterns | 58 """build an object to match a set of file patterns |
59 | 59 |
60 arguments: | 60 arguments: |
61 root - the canonical root of the tree you're matching against | 61 root - the canonical root of the tree you're matching against |
62 cwd - the current working directory, if relevant | 62 cwd - the current working directory, if relevant |
63 patterns - patterns to find | 63 patterns - patterns to find |
64 include - patterns to include (unless they are excluded) | 64 include - patterns to include (unless they are excluded) |
65 exclude - patterns to exclude (even if they are included) | 65 exclude - patterns to exclude (even if they are included) |
66 default - if a pattern in patterns has no explicit type, assume this one | 66 default - if a pattern in patterns has no explicit type, assume this one |
67 exact - patterns are actually filenames (include/exclude still apply) | 67 exact - patterns are actually filenames (include/exclude still apply) |
68 warn - optional function used for printing warnings | |
68 | 69 |
69 a pattern is one of: | 70 a pattern is one of: |
70 'glob:<glob>' - a glob relative to cwd | 71 'glob:<glob>' - a glob relative to cwd |
71 're:<regexp>' - a regular expression | 72 're:<regexp>' - a regular expression |
72 'path:<path>' - a path relative to repository root | 73 'path:<path>' - a path relative to repository root |
81 self._cwd = cwd | 82 self._cwd = cwd |
82 self._files = [] # exact files and roots of patterns | 83 self._files = [] # exact files and roots of patterns |
83 self._anypats = bool(include or exclude) | 84 self._anypats = bool(include or exclude) |
84 self._always = False | 85 self._always = False |
85 self._pathrestricted = bool(include or exclude or patterns) | 86 self._pathrestricted = bool(include or exclude or patterns) |
87 self._warn = warn | |
86 | 88 |
87 matchfns = [] | 89 matchfns = [] |
88 if include: | 90 if include: |
89 kindpats = self._normalize(include, 'glob', root, cwd, auditor) | 91 kindpats = self._normalize(include, 'glob', root, cwd, auditor) |
90 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', | 92 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', |
534 if line.startswith('syntax:'): | 536 if line.startswith('syntax:'): |
535 s = line[7:].strip() | 537 s = line[7:].strip() |
536 try: | 538 try: |
537 syntax = syntaxes[s] | 539 syntax = syntaxes[s] |
538 except KeyError: | 540 except KeyError: |
539 warn(_("%s: ignoring invalid syntax '%s'\n") % (filepath, s)) | 541 if warn: |
542 warn(_("%s: ignoring invalid syntax '%s'\n") % | |
543 (filepath, s)) | |
540 continue | 544 continue |
541 | 545 |
542 linesyntax = syntax | 546 linesyntax = syntax |
543 for s, rels in syntaxes.iteritems(): | 547 for s, rels in syntaxes.iteritems(): |
544 if line.startswith(rels): | 548 if line.startswith(rels): |