Mercurial > hg
comparison mercurial/match.py @ 32322:23c9a2a71c6e
match: make _fileroots a @propertycache and rename it to _fileset
The files in the set are not necesserily roots of anything. Making it
a @propertycache will help towards extracting a base class for
matchers.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 18 May 2017 09:04:37 -0700 |
parents | 0d6b3572ad92 |
children | 0aa4032a97e1 |
comparison
equal
deleted
inserted
replaced
32321:7df259077d4b | 32322:23c9a2a71c6e |
---|---|
186 if not matchfn(f): | 186 if not matchfn(f): |
187 return False | 187 return False |
188 return True | 188 return True |
189 | 189 |
190 self.matchfn = m | 190 self.matchfn = m |
191 self._fileroots = set(self._files) | |
192 | 191 |
193 def __call__(self, fn): | 192 def __call__(self, fn): |
194 return self.matchfn(fn) | 193 return self.matchfn(fn) |
195 def __iter__(self): | 194 def __iter__(self): |
196 for f in self._files: | 195 for f in self._files: |
233 if not .anypats(): list all files and dirs, | 232 if not .anypats(): list all files and dirs, |
234 else: optimal roots''' | 233 else: optimal roots''' |
235 return self._files | 234 return self._files |
236 | 235 |
237 @propertycache | 236 @propertycache |
237 def _fileset(self): | |
238 return set(self._files) | |
239 | |
240 @propertycache | |
238 def _dirs(self): | 241 def _dirs(self): |
239 return set(util.dirs(self._fileroots)) | {'.'} | 242 return set(util.dirs(self._fileset)) | {'.'} |
240 | 243 |
241 def visitdir(self, dir): | 244 def visitdir(self, dir): |
242 '''Decides whether a directory should be visited based on whether it | 245 '''Decides whether a directory should be visited based on whether it |
243 has potential matches in it or one of its subdirectories. This is | 246 has potential matches in it or one of its subdirectories. This is |
244 based on the match's primary, included, and excluded patterns. | 247 based on the match's primary, included, and excluded patterns. |
248 the given directory should be visited. | 251 the given directory should be visited. |
249 | 252 |
250 This function's behavior is undefined if it has returned False for | 253 This function's behavior is undefined if it has returned False for |
251 one of the dir's parent directories. | 254 one of the dir's parent directories. |
252 ''' | 255 ''' |
253 if self.prefix() and dir in self._fileroots: | 256 if self.prefix() and dir in self._fileset: |
254 return 'all' | 257 return 'all' |
255 if dir in self._excluderoots: | 258 if dir in self._excluderoots: |
256 return False | 259 return False |
257 if ((self._includeroots or self._includedirs) and | 260 if ((self._includeroots or self._includedirs) and |
258 '.' not in self._includeroots and | 261 '.' not in self._includeroots and |
259 dir not in self._includeroots and | 262 dir not in self._includeroots and |
260 dir not in self._includedirs and | 263 dir not in self._includedirs and |
261 not any(parent in self._includeroots | 264 not any(parent in self._includeroots |
262 for parent in util.finddirs(dir))): | 265 for parent in util.finddirs(dir))): |
263 return False | 266 return False |
264 return (not self._fileroots or | 267 return (not self._fileset or |
265 '.' in self._fileroots or | 268 '.' in self._fileset or |
266 dir in self._fileroots or | 269 dir in self._fileset or |
267 dir in self._dirs or | 270 dir in self._dirs or |
268 any(parentdir in self._fileroots | 271 any(parentdir in self._fileset |
269 for parentdir in util.finddirs(dir))) | 272 for parentdir in util.finddirs(dir))) |
270 | 273 |
271 def exact(self, f): | 274 def exact(self, f): |
272 '''Returns True if f is in .files().''' | 275 '''Returns True if f is in .files().''' |
273 return f in self._fileroots | 276 return f in self._fileset |
274 | 277 |
275 def anypats(self): | 278 def anypats(self): |
276 '''Matcher uses patterns or include/exclude.''' | 279 '''Matcher uses patterns or include/exclude.''' |
277 return self._anypats | 280 return self._anypats |
278 | 281 |
397 def visitdir(dir): | 400 def visitdir(dir): |
398 if dir == '.': | 401 if dir == '.': |
399 return matcher.visitdir(self._path) | 402 return matcher.visitdir(self._path) |
400 return matcher.visitdir(self._path + "/" + dir) | 403 return matcher.visitdir(self._path + "/" + dir) |
401 self.visitdir = visitdir | 404 self.visitdir = visitdir |
402 self._fileroots = set(self._files) | |
403 | 405 |
404 def abs(self, f): | 406 def abs(self, f): |
405 return self._matcher.abs(self._path + "/" + f) | 407 return self._matcher.abs(self._path + "/" + f) |
406 | 408 |
407 def bad(self, f, msg): | 409 def bad(self, f, msg): |
426 | 428 |
427 # m.exact(file) must be based off of the actual user input, otherwise | 429 # m.exact(file) must be based off of the actual user input, otherwise |
428 # inexact case matches are treated as exact, and not noted without -v. | 430 # inexact case matches are treated as exact, and not noted without -v. |
429 if self._files: | 431 if self._files: |
430 roots, dirs = _rootsanddirs(self._kp) | 432 roots, dirs = _rootsanddirs(self._kp) |
431 self._fileroots = set(roots) | 433 self._fileset = set(roots) |
432 self._fileroots.update(dirs) | 434 self._fileset.update(dirs) |
433 | 435 |
434 def _normalize(self, patterns, default, root, cwd, auditor): | 436 def _normalize(self, patterns, default, root, cwd, auditor): |
435 self._kp = super(icasefsmatcher, self)._normalize(patterns, default, | 437 self._kp = super(icasefsmatcher, self)._normalize(patterns, default, |
436 root, cwd, auditor) | 438 root, cwd, auditor) |
437 kindpats = [] | 439 kindpats = [] |