[PATCH 1 of 2 STABLE] context: don't complain about a matcher's subrepo paths in changectx.walk()

Matt Mackall mpm at selenic.com
Tue May 19 08:14:13 CDT 2015


On Mon, 2015-05-18 at 22:14 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1431839170 14400
> #      Sun May 17 01:06:10 2015 -0400
> # Branch stable
> # Node ID 73abecce8140e8c03b215c1b68c2669d44c62d91
> # Parent  91c2278c68a387903c00a7170509c9dd343a7e55
> context: don't complain about a matcher's subrepo paths in changectx.walk()

Here's an alternate solution to the problem of the "bad" callback, let
me know what you think:

diff -r 472a685a4961 mercurial/context.py
--- a/mercurial/context.py	Tue May 19 07:17:57 2015 -0500
+++ b/mercurial/context.py	Tue May 19 08:11:21 2015 -0500
@@ -9,7 +9,7 @@
 from i18n import _
 import mdiff, error, util, scmutil, subrepo, patch, encoding, phases
 import match as matchmod
-import copy, os, errno, stat
+import os, errno, stat
 import obsolete as obsmod
 import repoview
 import fileset
@@ -591,19 +591,16 @@
     def walk(self, match):
         '''Generates matching file names.'''
 
-        # Override match.bad method to have message with nodeid
-        match = copy.copy(match)
-        oldbad = match.bad
         def bad(fn, msg):
             # The manifest doesn't know about subrepos, so don't complain about
             # paths into valid subrepos.
             if any(fn == s or fn.startswith(s + '/')
                    for s in self.substate):
                 return
-            oldbad(fn, _('no such file in rev %s') % self)
-        match.bad = bad
+            match.bad(fn, _('no such file in rev %s') % self)
+        m = matchmod.badmatch(match, bad)
 
-        return self._manifest.walk(match)
+        return self._manifest.walk(m)
 
     def matches(self, match):
         return self.walk(match)
diff -r 472a685a4961 mercurial/match.py
--- a/mercurial/match.py	Tue May 19 07:17:57 2015 -0500
+++ b/mercurial/match.py	Tue May 19 08:11:21 2015 -0500
@@ -234,6 +234,23 @@
 def always(root, cwd):
     return match(root, cwd, [])
 
+class badmatch(match):
+    '''wrap a matcher with a bad() callback'''
+    def __init__(self, matcher, badfn):
+        # copy base object
+        self._root = matcher._root
+        self._cwd = matcher._cwd
+        self._matcher = matcher
+        self._always = matcher._always
+        self._pathrestricted = matcher._pathrestricted
+        self._files = matcher._files
+        self._always = matcher._always
+        self._anypats = matcher._anypats
+        self._fileroots = matcher._fileroots
+        self.matchfn = matcher.matchfn
+        # add callback
+        self.bad = badfn
+
 class narrowmatcher(match):
     """Adapt a matcher to work on a subdirectory only.
 

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list