[PATCH 3 of 8] context: replace match.bad() monkey patching with match.badmatch()

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


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1433468279 14400
#      Thu Jun 04 21:37:59 2015 -0400
# Node ID 711bf19ba6c0deae9f46c4ecd3f770ed6c47adc8
# Parent  bc470c4470ea9d80c83b8d0c39cac4cd7a9d29ea
context: replace match.bad() monkey patching with match.badmatch()

No known issues with the previous code since it restored the original method,
but this is cleaner.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -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
@@ -595,19 +595,17 @@
     def walk(self, match):
         '''Generates matching file names.'''
 
-        # Override match.bad method to have message with nodeid
-        match = copy.copy(match)
-        oldbad = match.bad
+        # Wrap match.bad method to have message with nodeid
         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)
 
-        return self._manifest.walk(match)
+        m = matchmod.badmatch(match, bad)
+        return self._manifest.walk(m)
 
     def matches(self, match):
         return self.walk(match)


More information about the Mercurial-devel mailing list