Mercurial > hg
comparison mercurial/match.py @ 38580:9f9ffe5f687c
match: compose 'set:' pattern as matcher
Baby step towards porting fileset to matcher composition.
We can't use the exactmatcher since it would provide a computed set as exact
paths. That's why we use the predicatematcher with fset.__contains__. This
will be cleaned up later.
The test change in test-glog.t means that the "set:copied()" pattern is no
longer be processed as a slow path. That's because the fset is empty. This
will also change in future patches.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 16:08:58 +0900 |
parents | ec0cee4c1fff |
children | 6467286b829c |
comparison
equal
deleted
inserted
replaced
38579:ec0cee4c1fff | 38580:9f9ffe5f687c |
---|---|
92 """ | 92 """ |
93 for kind, pat, source in kindpats: | 93 for kind, pat, source in kindpats: |
94 if pat != '' or kind not in ['relpath', 'glob']: | 94 if pat != '' or kind not in ['relpath', 'glob']: |
95 return False | 95 return False |
96 return True | 96 return True |
97 | |
98 def _buildkindpatsmatcher(matchercls, root, cwd, kindpats, ctx=None, | |
99 listsubrepos=False, badfn=None): | |
100 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) | |
101 matchers = [] | |
102 if kindpats: | |
103 m = matchercls(root, cwd, kindpats, ctx=ctx, listsubrepos=listsubrepos, | |
104 badfn=badfn) | |
105 matchers.append(m) | |
106 if fset: | |
107 m = predicatematcher(root, cwd, fset.__contains__, | |
108 predrepr='fileset', badfn=badfn) | |
109 matchers.append(m) | |
110 if not matchers: | |
111 return nevermatcher(root, cwd, badfn=badfn) | |
112 if len(matchers) == 1: | |
113 return matchers[0] | |
114 return unionmatcher(matchers) | |
97 | 115 |
98 def match(root, cwd, patterns=None, include=None, exclude=None, default='glob', | 116 def match(root, cwd, patterns=None, include=None, exclude=None, default='glob', |
99 exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None, | 117 exact=False, auditor=None, ctx=None, listsubrepos=False, warn=None, |
100 badfn=None, icasefs=False): | 118 badfn=None, icasefs=False): |
101 """build an object to match a set of file patterns | 119 """build an object to match a set of file patterns |
157 elif patterns: | 175 elif patterns: |
158 kindpats = normalize(patterns, default, root, cwd, auditor, warn) | 176 kindpats = normalize(patterns, default, root, cwd, auditor, warn) |
159 if _kindpatsalwaysmatch(kindpats): | 177 if _kindpatsalwaysmatch(kindpats): |
160 m = alwaysmatcher(root, cwd, badfn, relativeuipath=True) | 178 m = alwaysmatcher(root, cwd, badfn, relativeuipath=True) |
161 else: | 179 else: |
162 m = patternmatcher(root, cwd, kindpats, ctx=ctx, | 180 m = _buildkindpatsmatcher(patternmatcher, root, cwd, kindpats, |
163 listsubrepos=listsubrepos, badfn=badfn) | 181 ctx=ctx, listsubrepos=listsubrepos, |
182 badfn=badfn) | |
164 else: | 183 else: |
165 # It's a little strange that no patterns means to match everything. | 184 # It's a little strange that no patterns means to match everything. |
166 # Consider changing this to match nothing (probably using nevermatcher). | 185 # Consider changing this to match nothing (probably using nevermatcher). |
167 m = alwaysmatcher(root, cwd, badfn) | 186 m = alwaysmatcher(root, cwd, badfn) |
168 | 187 |
169 if include: | 188 if include: |
170 kindpats = normalize(include, 'glob', root, cwd, auditor, warn) | 189 kindpats = normalize(include, 'glob', root, cwd, auditor, warn) |
171 im = includematcher(root, cwd, kindpats, ctx=ctx, | 190 im = _buildkindpatsmatcher(includematcher, root, cwd, kindpats, ctx=ctx, |
172 listsubrepos=listsubrepos, badfn=None) | 191 listsubrepos=listsubrepos, badfn=None) |
173 m = intersectmatchers(m, im) | 192 m = intersectmatchers(m, im) |
174 if exclude: | 193 if exclude: |
175 kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn) | 194 kindpats = normalize(exclude, 'glob', root, cwd, auditor, warn) |
176 em = includematcher(root, cwd, kindpats, ctx=ctx, | 195 em = _buildkindpatsmatcher(includematcher, root, cwd, kindpats, ctx=ctx, |
177 listsubrepos=listsubrepos, badfn=None) | 196 listsubrepos=listsubrepos, badfn=None) |
178 m = differencematcher(m, em) | 197 m = differencematcher(m, em) |
179 return m | 198 return m |
180 | 199 |
181 def exact(root, cwd, files, badfn=None): | 200 def exact(root, cwd, files, badfn=None): |
182 return exactmatcher(root, cwd, files, badfn=badfn) | 201 return exactmatcher(root, cwd, files, badfn=badfn) |
826 def _buildmatch(ctx, kindpats, globsuffix, listsubrepos, root): | 845 def _buildmatch(ctx, kindpats, globsuffix, listsubrepos, root): |
827 '''Return regexp string and a matcher function for kindpats. | 846 '''Return regexp string and a matcher function for kindpats. |
828 globsuffix is appended to the regexp of globs.''' | 847 globsuffix is appended to the regexp of globs.''' |
829 matchfuncs = [] | 848 matchfuncs = [] |
830 | 849 |
831 fset, kindpats = _expandsets(kindpats, ctx, listsubrepos) | |
832 if fset: | |
833 matchfuncs.append(fset.__contains__) | |
834 | |
835 subincludes, kindpats = _expandsubinclude(kindpats, root) | 850 subincludes, kindpats = _expandsubinclude(kindpats, root) |
836 if subincludes: | 851 if subincludes: |
837 submatchers = {} | 852 submatchers = {} |
838 def matchsubinclude(f): | 853 def matchsubinclude(f): |
839 for prefix, matcherargs in subincludes: | 854 for prefix, matcherargs in subincludes: |