Mercurial > hg
comparison mercurial/manifest.py @ 24647:fb446c57f8f9
treemanifest: refactor treemanifest.walk()
This refactor is a preparation for an optimization in the next commit. This
introduces a recursive element that recurses each submanifest. By using a
recursive function, the next commit can avoid walking over some subdirectories
altogether.
author | Drew Gottlieb <drgott@google.com> |
---|---|
date | Tue, 07 Apr 2015 15:18:52 -0700 |
parents | 5693c834bcb4 |
children | ea4a7c8909ae |
comparison
equal
deleted
inserted
replaced
24646:5693c834bcb4 | 24647:fb446c57f8f9 |
---|---|
621 if util.all(fn in self for fn in fset): | 621 if util.all(fn in self for fn in fset): |
622 for fn in sorted(fset): | 622 for fn in sorted(fset): |
623 yield fn | 623 yield fn |
624 raise StopIteration | 624 raise StopIteration |
625 | 625 |
626 for fn in self: | 626 for fn in self._walk(match): |
627 if fn in fset: | 627 if fn in fset: |
628 # specified pattern is the exact name | 628 # specified pattern is the exact name |
629 fset.remove(fn) | 629 fset.remove(fn) |
630 if match(fn): | 630 yield fn |
631 yield fn | |
632 | 631 |
633 # for dirstate.walk, files=['.'] means "walk the whole tree". | 632 # for dirstate.walk, files=['.'] means "walk the whole tree". |
634 # follow that here, too | 633 # follow that here, too |
635 fset.discard('.') | 634 fset.discard('.') |
636 | 635 |
637 for fn in sorted(fset): | 636 for fn in sorted(fset): |
638 if not self.hasdir(fn): | 637 if not self.hasdir(fn): |
639 match.bad(fn, None) | 638 match.bad(fn, None) |
639 | |
640 def _walk(self, match): | |
641 '''Recursively generates matching file names for walk().''' | |
642 | |
643 # yield this dir's files and walk its submanifests | |
644 for p in sorted(self._dirs.keys() + self._files.keys()): | |
645 if p in self._files: | |
646 fullp = self._subpath(p) | |
647 if match(fullp): | |
648 yield fullp | |
649 else: | |
650 for f in self._dirs[p]._walk(match): | |
651 yield f | |
640 | 652 |
641 def matches(self, match): | 653 def matches(self, match): |
642 '''generate a new manifest filtered by the match argument''' | 654 '''generate a new manifest filtered by the match argument''' |
643 if match.always(): | 655 if match.always(): |
644 return self.copy() | 656 return self.copy() |