[PATCH 1 of 8] match: introduce badmatch() to eliminate long callback chains with subrepos

Matt Harbison mharbison72 at gmail.com
Thu Jun 4 23:00:46 CDT 2015

# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1433467162 14400
#      Thu Jun 04 21:19:22 2015 -0400
# Node ID ee8c63982085a4fadc83b6957d413866d1f21b28
# Parent  51e7acc34b0ab0e540dffdb22127914f2353d5e2
match: introduce badmatch() to eliminate long callback chains with subrepos

Various bit of code replace the bad method on matchers, and then delegate to the
original bad method after doing some custom processing.  At least some of these
forget to restore the original method when the need has passed, and then when
the matcher is passed to the next subrepo (even a sibling), another layer is
added such that the chain looks like:

    bad2 -> bad1 -> original

At best, this is a waste of processing, but sometimes spurious messages can be
emitted (e.g. ccb1623266eb).

The trick with this copy of the matcher is to make sure it is *not* passed to
any subrepo- the original must be passed instead.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
-import re
+import copy, re
 import util, pathutil
 from i18n import _
@@ -305,6 +305,14 @@
 def always(root, cwd):
     return match(root, cwd, [])
+def badmatch(match, badfn):
+    """Make a copy of the given matcher, replacing its bad method with the given
+    one.
+    """
+    m = copy.copy(match)
+    m.bad = badfn
+    return m
 class narrowmatcher(match):
     """Adapt a matcher to work on a subdirectory only.

More information about the Mercurial-devel mailing list