~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-17 04:55:38 UTC
  • mfrom: (4449.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090617045538-5mmdqd346tv8q67m
(igc) add recursion control to list_files() API

Show diffs side-by-side

added added

removed removed

Lines of Context:
1748
1748
            if self._transform.final_file_id(trans_id) is None:
1749
1749
                yield self._final_paths._determine_path(trans_id)
1750
1750
 
1751
 
    def _make_inv_entries(self, ordered_entries, specific_file_ids):
 
1751
    def _make_inv_entries(self, ordered_entries, specific_file_ids=None):
1752
1752
        for trans_id, parent_file_id in ordered_entries:
1753
1753
            file_id = self._transform.final_file_id(trans_id)
1754
1754
            if file_id is None:
1791
1791
                                                      specific_file_ids):
1792
1792
            yield unicode(self._final_paths.get_path(trans_id)), entry
1793
1793
 
1794
 
    def list_files(self, include_root=False):
1795
 
        """See Tree.list_files."""
 
1794
    def _iter_entries_for_dir(self, dir_path):
 
1795
        """Return path, entry for items in a directory without recursing down."""
 
1796
        dir_file_id = self.path2id(dir_path)
 
1797
        ordered_ids = []
 
1798
        for file_id in self.iter_children(dir_file_id):
 
1799
            trans_id = self._transform.trans_id_file_id(file_id)
 
1800
            ordered_ids.append((trans_id, file_id))
 
1801
        for entry, trans_id in self._make_inv_entries(ordered_ids):
 
1802
            yield unicode(self._final_paths.get_path(trans_id)), entry
 
1803
 
 
1804
    def list_files(self, include_root=False, from_dir=None, recursive=True):
 
1805
        """See WorkingTree.list_files."""
1796
1806
        # XXX This should behave like WorkingTree.list_files, but is really
1797
1807
        # more like RevisionTree.list_files.
1798
 
        for path, entry in self.iter_entries_by_dir():
1799
 
            if entry.name == '' and not include_root:
1800
 
                continue
1801
 
            yield path, 'V', entry.kind, entry.file_id, entry
 
1808
        if recursive:
 
1809
            prefix = None
 
1810
            if from_dir:
 
1811
                prefix = from_dir + '/'
 
1812
            entries = self.iter_entries_by_dir()
 
1813
            for path, entry in entries:
 
1814
                if entry.name == '' and not include_root:
 
1815
                    continue
 
1816
                if prefix:
 
1817
                    if not path.startswith(prefix):
 
1818
                        continue
 
1819
                    path = path[len(prefix):]
 
1820
                yield path, 'V', entry.kind, entry.file_id, entry
 
1821
        else:
 
1822
            if from_dir is None and include_root is True:
 
1823
                root_entry = inventory.make_entry('directory', '',
 
1824
                    ROOT_PARENT, self.get_root_id())
 
1825
                yield '', 'V', 'directory', root_entry.file_id, root_entry
 
1826
            entries = self._iter_entries_for_dir(from_dir or '')
 
1827
            for path, entry in entries:
 
1828
                yield path, 'V', entry.kind, entry.file_id, entry
1802
1829
 
1803
1830
    def kind(self, file_id):
1804
1831
        trans_id = self._transform.trans_id_file_id(file_id)