[PATCH 1 of 7] match: add an optional constructor parameter for a bad() override

Matt Harbison mharbison72 at gmail.com
Fri Jun 5 22:54:20 CDT 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1433544993 14400
#      Fri Jun 05 18:56:33 2015 -0400
# Node ID d40991e9e4e5b2f45ede19a76909515c1a9d07fd
# Parent  6fabde6ef4453ee6c2aa964184f6cf2c54483621
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.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -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.


More information about the Mercurial-devel mailing list