[Differential] [Closed] D57: match: write forceincludematcher using unionmatcher

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Jul 14 13:25:50 EDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6f4e5e5940a5: match: write forceincludematcher using unionmatcher (authored by martinvonz).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D57?vs=128&id=145

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

AFFECTED FILES
  mercurial/match.py
  mercurial/sparse.py

CHANGE DETAILS

Index: mercurial/sparse.py
===================================================================
--- mercurial/sparse.py
+++ mercurial/sparse.py
@@ -242,6 +242,13 @@
             'sparse checkout\n')
     repo.ui.status(msg % len(tempincludes))
 
+def forceincludematcher(matcher, includes):
+    """Returns a matcher that returns true for any of the forced includes
+    before testing against the actual matcher."""
+    kindpats = [('path', include, '') for include in includes]
+    includematcher = matchmod.includematcher('', '', kindpats)
+    return matchmod.unionmatcher([includematcher, matcher])
+
 def matcher(repo, revs=None, includetemp=True):
     """Obtain a matcher for sparse working directories for the given revs.
 
@@ -289,7 +296,7 @@
                                          include=includes, exclude=excludes,
                                          default='relpath')
                 if subdirs:
-                    matcher = matchmod.forceincludematcher(matcher, subdirs)
+                    matcher = forceincludematcher(matcher, subdirs)
                 matchers.append(matcher)
         except IOError:
             pass
@@ -303,7 +310,7 @@
 
     if includetemp:
         tempincludes = readtemporaryincludes(repo)
-        result = matchmod.forceincludematcher(result, tempincludes)
+        result = forceincludematcher(result, tempincludes)
 
     repo._sparsematchercache[key] = result
 
Index: mercurial/match.py
===================================================================
--- mercurial/match.py
+++ mercurial/match.py
@@ -647,20 +647,6 @@
         return ('<subdirmatcher path=%r, matcher=%r>' %
                 (self._path, self._matcher))
 
-class forceincludematcher(basematcher):
-    """A matcher that returns true for any of the forced includes before testing
-    against the actual matcher."""
-    def __init__(self, matcher, includes):
-        self._matcher = matcher
-        self._includes = includes
-
-    def matchfn(self, f):
-        return f in self._includes or self._matcher(f)
-
-    def __repr__(self):
-        return ('<forceincludematcher matcher=%r, includes=%r>' %
-                (self._matcher, sorted(self._includes)))
-
 class unionmatcher(basematcher):
     """A matcher that is the union of several matchers."""
     def __init__(self, matchers):


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

To: martinvonz, dsp, #hg-reviewers
Cc: durham, dsp, mercurial-devel


More information about the Mercurial-devel mailing list