# HG changeset patch # User Martin von Zweigbergk # Date 1499463599 25200 # Node ID 6f4e5e5940a5d7ae3ae7a1483f241fc2a420fadf # Parent fad6852cf87944f7405bb2cf18fc47424465f61d match: write forceincludematcher using unionmatcher The forceincludematcher is simply a unionmatcher of a includematcher (matching paths recursively) with the given matcher. Since the forceincludematcher is only used by sparse, move it there. I don't have a good sparse repo setup to test performance impact on. Differential Revision: https://phab.mercurial-scm.org/D57 diff -r fad6852cf879 -r 6f4e5e5940a5 mercurial/match.py --- a/mercurial/match.py Wed Jul 12 13:57:03 2017 -0700 +++ b/mercurial/match.py Fri Jul 07 14:39:59 2017 -0700 @@ -647,20 +647,6 @@ return ('' % (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 ('' % - (self._matcher, sorted(self._includes))) - class unionmatcher(basematcher): """A matcher that is the union of several matchers.""" def __init__(self, matchers): diff -r fad6852cf879 -r 6f4e5e5940a5 mercurial/sparse.py --- a/mercurial/sparse.py Wed Jul 12 13:57:03 2017 -0700 +++ b/mercurial/sparse.py Fri Jul 07 14:39:59 2017 -0700 @@ -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