[Differential] [Request, 20 lines] D58: match: make unionmatcher a proper matcher

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed Jul 12 00:01:56 UTC 2017


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.

REVISION SUMMARY
  unionmatcher is currently used where only a limited subset of its
  functions will be called. Specifically, visitdir() is never
  called. The next patch will pass it to dirstate.walk() where it will
  matter that visitdir() is correctly implemented, so let's fix
  that. Also add the explicitdir etc that will also be assumed by
  dirstate.walk() to exist on a matcher.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D58

AFFECTED FILES
  mercurial/match.py

CHANGE DETAILS

Index: mercurial/match.py
===================================================================
--- mercurial/match.py
+++ mercurial/match.py
@@ -649,16 +649,34 @@
                 (self._path, self._matcher))
 
 class unionmatcher(basematcher):
-    """A matcher that is the union of several matchers."""
+    """A matcher that is the union of several matchers.
+
+    The non-matching-attributes (root, cwd, bad, explicitdir, traversedir) are
+    taken from the first matcher.
+    """
+
     def __init__(self, matchers):
+        m1 = matchers[0]
+        super(unionmatcher, self).__init__(m1._root, m1._cwd)
+        self.explicitdir = m1.explicitdir
+        self.traversedir = m1.traversedir
         self._matchers = matchers
 
     def matchfn(self, f):
         for match in self._matchers:
             if match(f):
                 return True
         return False
 
+    def visitdir(self, dir):
+        r = False
+        for m in self._matchers:
+            v = m.visitdir(dir)
+            if v == 'all':
+                return v
+            r |= v
+        return r
+
     def __repr__(self):
         return ('<unionmatcher matchers=%r>' % self._matchers)
 


EMAIL PREFERENCES
  https://phab.mercurial-scm.org/settings/panel/emailpreferences/

To: martinvonz
Cc: mercurial-devel, indygreg


More information about the Mercurial-devel mailing list