[PATCH] match: make subinclude construction lazy
Durham Goode
durham at fb.com
Wed May 3 17:34:10 UTC 2017
# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1493832657 25200
# Wed May 03 10:30:57 2017 -0700
# Node ID 69fee32d094c234b30114977b0dcce1b45401f5a
# Parent 6cacc271ee0a9385be483314dc73be176a13c891
match: make subinclude construction lazy
The matcher subinclude functionality allows us to have .hgignore files that
include subdirectory hgignore files. Today it parses the entire repo at once,
even if we only need to test a file in one subdirectory. This patch makes the
subinclude tree creation lazy, which speeds up matcher creation significantly in
large repos with very large trees of ignore patterns.
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -64,12 +64,12 @@ def _expandsubinclude(kindpats, root):
path = pathutil.join(sourceroot, pat)
newroot = pathutil.dirname(path)
- relmatcher = match(newroot, '', [], ['include:%s' % path])
+ matcherargs = (newroot, '', [], ['include:%s' % path])
prefix = pathutil.canonpath(root, root, newroot)
if prefix:
prefix += '/'
- relmatchers.append((prefix, relmatcher))
+ relmatchers.append((prefix, matcherargs))
else:
other.append((kind, pat, source))
@@ -584,10 +584,17 @@ def _buildmatch(ctx, kindpats, globsuffi
subincludes, kindpats = _expandsubinclude(kindpats, root)
if subincludes:
+ submatchers = {}
def matchsubinclude(f):
- for prefix, mf in subincludes:
- if f.startswith(prefix) and mf(f[len(prefix):]):
- return True
+ for prefix, matcherargs in subincludes:
+ if f.startswith(prefix):
+ mf = submatchers.get(prefix)
+ if mf is None:
+ mf = match(*matcherargs)
+ submatchers[prefix] = mf
+
+ if mf(f[len(prefix):]):
+ return True
return False
matchfuncs.append(matchsubinclude)
More information about the Mercurial-devel
mailing list