~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 15:39:21 UTC
  • mfrom: (1551.9.35 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2239.
  • Revision ID: abentley@panoramicfeedback.com-20070117153921-6pp9ssa2r8n5izoo
Merge bzr.ab, to avoid conflicts submitting

Show diffs side-by-side

added added

removed removed

Lines of Context:
944
944
                # if we finished all children, pop it off the stack
945
945
                stack.pop()
946
946
 
947
 
    def iter_entries_by_dir(self, from_dir=None):
 
947
    def iter_entries_by_dir(self, from_dir=None, specific_file_ids=None):
948
948
        """Iterate over the entries in a directory first order.
949
949
 
950
950
        This returns all entries for a directory before returning
959
959
        if from_dir is None:
960
960
            if self.root is None:
961
961
                return
 
962
            # Optimize a common case
 
963
            if specific_file_ids is not None and len(specific_file_ids) == 1:
 
964
                file_id = list(specific_file_ids)[0]
 
965
                if file_id in self:
 
966
                    yield self.id2path(file_id), self[file_id]
 
967
                return 
962
968
            from_dir = self.root
963
 
            yield '', self.root
 
969
            if (specific_file_ids is None or 
 
970
                self.root.file_id in specific_file_ids):
 
971
                yield '', self.root
964
972
        elif isinstance(from_dir, basestring):
965
973
            from_dir = self._byid[from_dir]
 
974
 
 
975
        if specific_file_ids is not None:
 
976
            parents = set()
 
977
            def add_ancestors(file_id):
 
978
                if file_id not in self:
 
979
                    return
 
980
                parent_id = self[file_id].parent_id
 
981
                if parent_id is None:
 
982
                    return
 
983
                if parent_id not in parents:
 
984
                    parents.add(parent_id)
 
985
                    add_ancestors(parent_id)
 
986
            for file_id in specific_file_ids:
 
987
                add_ancestors(file_id)
 
988
        else:
 
989
            parents = None
966
990
            
967
991
        stack = [(u'', from_dir)]
968
992
        while stack:
973
997
 
974
998
                child_relpath = cur_relpath + child_name
975
999
 
976
 
                yield child_relpath, child_ie
 
1000
                if (specific_file_ids is None or 
 
1001
                    child_ie.file_id in specific_file_ids):
 
1002
                    yield child_relpath, child_ie
977
1003
 
978
1004
                if child_ie.kind == 'directory':
979
 
                    child_dirs.append((child_relpath+'/', child_ie))
 
1005
                    if parents is None or child_ie.file_id in parents:
 
1006
                        child_dirs.append((child_relpath+'/', child_ie))
980
1007
            stack.extend(reversed(child_dirs))
981
1008
 
982
1009
    def entries(self):