changeset 25464:504a1f295677

match: add an optional constructor parameter for a bad() override This will be used to eliminate monkey patching of new matcher instances that weren't removed in 5984dd42e140::1a95c57959f6.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 05 Jun 2015 18:56:33 -0400
parents 03af5c2ddf75
children f472228a9e5e
files mercurial/match.py
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Sun Jun 07 09:30:15 2015 +0900
+++ b/mercurial/match.py	Fri Jun 05 18:56:33 2015 -0400
@@ -78,7 +78,7 @@
 class match(object):
     def __init__(self, root, cwd, patterns, include=[], exclude=[],
                  default='glob', exact=False, auditor=None, ctx=None,
-                 listsubrepos=False, warn=None):
+                 listsubrepos=False, warn=None, badfn=None):
         """build an object to match a set of file patterns
 
         arguments:
@@ -90,6 +90,7 @@
         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
+        badfn - optional bad() callback for this matcher instead of the default
 
         a pattern is one of:
         'glob:<glob>' - a glob relative to cwd
@@ -116,6 +117,9 @@
         self._includedirs = set(['.'])
         self._excluderoots = set()
 
+        if badfn is not None:
+            self.bad = badfn
+
         matchfns = []
         if include:
             kindpats = self._normalize(include, 'glob', root, cwd, auditor)
@@ -299,8 +303,8 @@
             kindpats.append((kind, pat, ''))
         return kindpats
 
-def exact(root, cwd, files):
-    return match(root, cwd, files, exact=True)
+def exact(root, cwd, files, badfn=None):
+    return match(root, cwd, files, exact=True, badfn=badfn)
 
 def always(root, cwd):
     return match(root, cwd, [])
@@ -378,12 +382,12 @@
     """
 
     def __init__(self, root, cwd, patterns, include, exclude, default, auditor,
-                 ctx, listsubrepos=False):
+                 ctx, listsubrepos=False, badfn=None):
         init = super(icasefsmatcher, self).__init__
         self._dsnormalize = ctx.repo().dirstate.normalize
 
         init(root, cwd, patterns, include, exclude, default, auditor=auditor,
-             ctx=ctx, listsubrepos=listsubrepos)
+             ctx=ctx, listsubrepos=listsubrepos, badfn=badfn)
 
         # m.exact(file) must be based off of the actual user input, otherwise
         # inexact case matches are treated as exact, and not noted without -v.