Patchwork [2,of,4] match: override visitdir() the usual way in subdirmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 18, 2017, 6:03 p.m.
Message ID <c387c5e78c2cbd703c79.1495130624@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20683/
State Accepted
Headers show

Comments

via Mercurial-devel - May 18, 2017, 6:03 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495127877 25200
#      Thu May 18 10:17:57 2017 -0700
# Node ID c387c5e78c2cbd703c791fc8b9515526d1ce6155
# Parent  48275b23f01283fdf1ae6e630c2c63660528edfc
match: override visitdir() the usual way in subdirmatcher

Just override the function instead of replacing it on each instance.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -397,11 +397,6 @@ 
         # from the inputs. Instead, we override matchfn() and visitdir() to
         # call the original matcher with the subdirectory path prepended.
         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)
-        def visitdir(dir):
-            if dir == '.':
-                return matcher.visitdir(self._path)
-            return matcher.visitdir(self._path + "/" + dir)
-        self.visitdir = visitdir
 
     def abs(self, f):
         return self._matcher.abs(self._path + "/" + f)
@@ -412,6 +407,13 @@ 
     def rel(self, f):
         return self._matcher.rel(self._path + "/" + f)
 
+    def visitdir(self, dir):
+        if dir == '.':
+            dir = self._path
+        else:
+            dir = self._path + "/" + dir
+        return self._matcher.visitdir(dir)
+
 class icasefsmatcher(match):
     """A matcher for wdir on case insensitive filesystems, which normalizes the
     given patterns to the case in the filesystem.