Mercurial > hg
comparison mercurial/manifest.py @ 24685:b3d78d82d84c
manifestdict: extract condition for _intersectfiles() and use for walk()
The condition on which manifestdict.matches() and manifestdict.walk()
take the fast path of iterating over files instead of the manifest, is
slightly different. Specifically, walk() does not take the fast path
for exact matchers and it does not avoid taking the fast path when
there are more than 100 files. Let's extract the condition so we don't
have to maintain it in two places and so walk() can gain these two
missing pieces of the condition (although there seems to be no current
caller of walk() with an exact matcher).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 08 Apr 2015 09:38:09 -0700 |
parents | ff7badaf3158 |
children | 32b268cbff00 |
comparison
equal
deleted
inserted
replaced
24684:ff7badaf3158 | 24685:b3d78d82d84c |
---|---|
212 return self._dirs | 212 return self._dirs |
213 | 213 |
214 def hasdir(self, dir): | 214 def hasdir(self, dir): |
215 return dir in self._dirs | 215 return dir in self._dirs |
216 | 216 |
217 def _filesfastpath(self, match): | |
218 '''Checks whether we can correctly and quickly iterate over matcher | |
219 files instead of over manifest files.''' | |
220 files = match.files() | |
221 return (len(files) < 100 and (match.isexact() or | |
222 (not match.anypats() and util.all(fn in self for fn in files)))) | |
223 | |
217 def walk(self, match): | 224 def walk(self, match): |
218 '''Generates matching file names. | 225 '''Generates matching file names. |
219 | 226 |
220 Equivalent to manifest.matches(match).iterkeys(), but without creating | 227 Equivalent to manifest.matches(match).iterkeys(), but without creating |
221 an entirely new manifest. | 228 an entirely new manifest. |
228 return | 235 return |
229 | 236 |
230 fset = set(match.files()) | 237 fset = set(match.files()) |
231 | 238 |
232 # avoid the entire walk if we're only looking for specific files | 239 # avoid the entire walk if we're only looking for specific files |
233 if not match.anypats() and util.all(fn in self for fn in fset): | 240 if self._filesfastpath(match): |
234 for fn in sorted(fset): | 241 for fn in sorted(fset): |
235 yield fn | 242 yield fn |
236 return | 243 return |
237 | 244 |
238 for fn in self: | 245 for fn in self: |
253 def matches(self, match): | 260 def matches(self, match): |
254 '''generate a new manifest filtered by the match argument''' | 261 '''generate a new manifest filtered by the match argument''' |
255 if match.always(): | 262 if match.always(): |
256 return self.copy() | 263 return self.copy() |
257 | 264 |
258 files = match.files() | 265 if self._filesfastpath(match): |
259 if (len(files) < 100 and (match.isexact() or | |
260 (not match.anypats() and util.all(fn in self for fn in files)))): | |
261 m = manifestdict() | 266 m = manifestdict() |
262 lm = self._lm | 267 lm = self._lm |
263 for fn in match.files(): | 268 for fn in match.files(): |
264 if fn in lm: | 269 if fn in lm: |
265 m._lm[fn] = lm[fn] | 270 m._lm[fn] = lm[fn] |