[PATCH 2 of 4] match: add optional warn argument
Durham Goode
durham at fb.com
Mon May 18 19:23:19 CDT 2015
# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1431991676 25200
# Mon May 18 16:27:56 2015 -0700
# Node ID b629687156cd44334c09ce5e158038c21039b0fd
# Parent ac291d9afa6f6dbb848cd49070275a584d529592
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.
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -54,7 +54,7 @@ def _kindpatsalwaysmatch(kindpats):
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 @@ class match(object):
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 @@ class match(object):
self._anypats = bool(include or exclude)
self._always = False
self._pathrestricted = bool(include or exclude or patterns)
+ self._warn = warn
matchfns = []
if include:
@@ -534,7 +536,9 @@ def readpatternfile(filepath, warn):
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
More information about the Mercurial-devel
mailing list