changeset 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
files mercurial/match.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Sat May 16 15:51:03 2015 -0700
+++ b/mercurial/match.py	Mon May 18 16:27:56 2015 -0700
@@ -54,7 +54,7 @@
 class match(object):
     def __init__(self, root, cwd, patterns, include=[], exclude=[],
                  default='glob', exact=False, auditor=None, ctx=None,
-                 listsubrepos=False):
+                 listsubrepos=False, warn=None):
         """build an object to match a set of file patterns
 
         arguments:
@@ -65,6 +65,7 @@
         exclude - patterns to exclude (even if they are included)
         default - if a pattern in patterns has no explicit type, assume this one
         exact - patterns are actually filenames (include/exclude still apply)
+        warn - optional function used for printing warnings
 
         a pattern is one of:
         'glob:<glob>' - a glob relative to cwd
@@ -83,6 +84,7 @@
         self._anypats = bool(include or exclude)
         self._always = False
         self._pathrestricted = bool(include or exclude or patterns)
+        self._warn = warn
 
         matchfns = []
         if include:
@@ -536,7 +538,9 @@
             try:
                 syntax = syntaxes[s]
             except KeyError:
-                warn(_("%s: ignoring invalid syntax '%s'\n") % (filepath, s))
+                if warn:
+                    warn(_("%s: ignoring invalid syntax '%s'\n") %
+                         (filepath, s))
             continue
 
         linesyntax = syntax