comparison mercurial/match.py @ 33306:a9808bd1449e

match: minor cleanups to patternmatcher and includematcher The "patterns"/"include" in "patternspat"/"includepat" is redundant, so drop it. Also a "_" prefix since it's "private". Inline the "pm"/"im" variables.
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 08 Jun 2017 22:49:21 -0700
parents 3e8eb6d84a5c
children 3c84591e7321
comparison
equal deleted inserted replaced
33305:aaa1f8f514cf 33306:a9808bd1449e
356 badfn=None): 356 badfn=None):
357 super(patternmatcher, self).__init__(root, cwd, badfn) 357 super(patternmatcher, self).__init__(root, cwd, badfn)
358 358
359 self._files = _explicitfiles(kindpats) 359 self._files = _explicitfiles(kindpats)
360 self._anypats = _anypats(kindpats) 360 self._anypats = _anypats(kindpats)
361 self.patternspat, pm = _buildmatch(ctx, kindpats, '$', listsubrepos, 361 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos,
362 root) 362 root)
363 self.matchfn = pm
364 363
365 @propertycache 364 @propertycache
366 def _dirs(self): 365 def _dirs(self):
367 return set(util.dirs(self._fileset)) | {'.'} 366 return set(util.dirs(self._fileset)) | {'.'}
368 367
377 376
378 def anypats(self): 377 def anypats(self):
379 return self._anypats 378 return self._anypats
380 379
381 def __repr__(self): 380 def __repr__(self):
382 return ('<patternmatcher patterns=%r>' % self.patternspat) 381 return ('<patternmatcher patterns=%r>' % self._pats)
383 382
384 class includematcher(basematcher): 383 class includematcher(basematcher):
385 384
386 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, 385 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
387 badfn=None): 386 badfn=None):
388 super(includematcher, self).__init__(root, cwd, badfn) 387 super(includematcher, self).__init__(root, cwd, badfn)
389 388
390 self.includepat, im = _buildmatch(ctx, kindpats, '(?:/|$)', 389 self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)',
391 listsubrepos, root) 390 listsubrepos, root)
392 self._anypats = _anypats(kindpats) 391 self._anypats = _anypats(kindpats)
393 roots, dirs = _rootsanddirs(kindpats) 392 roots, dirs = _rootsanddirs(kindpats)
394 # roots are directories which are recursively included. 393 # roots are directories which are recursively included.
395 self._roots = set(roots) 394 self._roots = set(roots)
396 # dirs are directories which are non-recursively included. 395 # dirs are directories which are non-recursively included.
397 self._dirs = set(dirs) 396 self._dirs = set(dirs)
398 self.matchfn = im
399 397
400 def visitdir(self, dir): 398 def visitdir(self, dir):
401 if not self._anypats and dir in self._roots: 399 if not self._anypats and dir in self._roots:
402 # The condition above is essentially self.prefix() for includes 400 # The condition above is essentially self.prefix() for includes
403 return 'all' 401 return 'all'
409 407
410 def anypats(self): 408 def anypats(self):
411 return True 409 return True
412 410
413 def __repr__(self): 411 def __repr__(self):
414 return ('<includematcher includes=%r>' % self.includepat) 412 return ('<includematcher includes=%r>' % self._pats)
415 413
416 class exactmatcher(basematcher): 414 class exactmatcher(basematcher):
417 '''Matches the input files exactly. They are interpreted as paths, not 415 '''Matches the input files exactly. They are interpreted as paths, not
418 patterns (so no kind-prefixes). 416 patterns (so no kind-prefixes).
419 ''' 417 '''