Mercurial > public > mercurial-scm > hg
comparison mercurial/fileset.py @ 38691:370ff3e34160
fileset: remove subset and unused filtering functions from matchctx
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 09 Jun 2018 22:35:21 +0900 |
parents | 5d9749c598f0 |
children | 3700564c63fe |
comparison
equal
deleted
inserted
replaced
38690:5d9749c598f0 | 38691:370ff3e34160 |
---|---|
551 'not': notmatch, | 551 'not': notmatch, |
552 'func': func, | 552 'func': func, |
553 } | 553 } |
554 | 554 |
555 class matchctx(object): | 555 class matchctx(object): |
556 def __init__(self, ctx, subset, status=None, badfn=None): | 556 def __init__(self, ctx, status=None, badfn=None): |
557 self.ctx = ctx | 557 self.ctx = ctx |
558 self.subset = subset | |
559 self._status = status | 558 self._status = status |
560 self._badfn = badfn | 559 self._badfn = badfn |
561 | 560 |
562 def status(self): | 561 def status(self): |
563 return self._status | 562 return self._status |
609 """Create a matcher to select nothing""" | 608 """Create a matcher to select nothing""" |
610 repo = self.ctx.repo() | 609 repo = self.ctx.repo() |
611 return matchmod.nevermatcher(repo.root, repo.getcwd(), | 610 return matchmod.nevermatcher(repo.root, repo.getcwd(), |
612 badfn=self._badfn) | 611 badfn=self._badfn) |
613 | 612 |
614 def filter(self, files): | |
615 return [f for f in files if f in self.subset] | |
616 | |
617 def switch(self, ctx, status=None): | 613 def switch(self, ctx, status=None): |
618 subset = self.filter(_buildsubset(ctx, status)) | 614 return matchctx(ctx, status, self._badfn) |
619 return matchctx(ctx, subset, status, self._badfn) | |
620 | 615 |
621 class fullmatchctx(matchctx): | 616 class fullmatchctx(matchctx): |
622 """A match context where any files in any revisions should be valid""" | 617 """A match context where any files in any revisions should be valid""" |
623 | 618 |
624 def __init__(self, ctx, status=None, badfn=None): | 619 def __init__(self, ctx, status=None, badfn=None): |
625 subset = _buildsubset(ctx, status) | 620 super(fullmatchctx, self).__init__(ctx, status, badfn) |
626 super(fullmatchctx, self).__init__(ctx, subset, status, badfn) | |
627 def switch(self, ctx, status=None): | 621 def switch(self, ctx, status=None): |
628 return fullmatchctx(ctx, status, self._badfn) | 622 return fullmatchctx(ctx, status, self._badfn) |
629 | 623 |
630 # filesets using matchctx.switch() | 624 # filesets using matchctx.switch() |
631 _switchcallers = [ | 625 _switchcallers = [ |
644 for s in tree[1:]: | 638 for s in tree[1:]: |
645 if _intree(funcs, s): | 639 if _intree(funcs, s): |
646 return True | 640 return True |
647 return False | 641 return False |
648 | 642 |
649 def _buildsubset(ctx, status): | |
650 if status: | |
651 subset = [] | |
652 for c in status: | |
653 subset.extend(c) | |
654 return subset | |
655 else: | |
656 return list(ctx.walk(ctx.match([]))) | |
657 | |
658 def match(ctx, expr, badfn=None): | 643 def match(ctx, expr, badfn=None): |
659 """Create a matcher for a single fileset expression""" | 644 """Create a matcher for a single fileset expression""" |
660 tree = parse(expr) | 645 tree = parse(expr) |
661 mctx = fullmatchctx(ctx, _buildstatus(ctx, tree), badfn=badfn) | 646 mctx = fullmatchctx(ctx, _buildstatus(ctx, tree), badfn=badfn) |
662 return getmatch(mctx, tree) | 647 return getmatch(mctx, tree) |