~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

MergeĀ inĀ iter_entries_by_dir().

Show diffs side-by-side

added added

removed removed

Lines of Context:
906
906
                # if we finished all children, pop it off the stack
907
907
                stack.pop()
908
908
 
 
909
    def iter_entries_by_dir(self, from_dir=None):
 
910
        """Iterate over the entries in a directory first order.
 
911
 
 
912
        This returns all entries for a directory before returning
 
913
        the entries for children of a directory. This is not
 
914
        lexicographically sorted order, and is a hybrid between
 
915
        depth-first and breadth-first.
 
916
 
 
917
        :return: This yields (path, entry) pairs
 
918
        """
 
919
        if from_dir == None:
 
920
            assert self.root
 
921
            from_dir = self.root
 
922
        elif isinstance(from_dir, basestring):
 
923
            from_dir = self._byid[from_dir]
 
924
            
 
925
        stack = [(u'', from_dir)]
 
926
        while stack:
 
927
            cur_relpath, cur_dir = stack.pop()
 
928
 
 
929
            child_dirs = []
 
930
            for child_name, child_ie in sorted(cur_dir.children.iteritems()):
 
931
 
 
932
                child_relpath = cur_relpath + child_name
 
933
 
 
934
                yield child_relpath, child_ie
 
935
 
 
936
                if child_ie.kind == 'directory':
 
937
                    child_dirs.append((child_relpath+'/', child_ie))
 
938
            stack.extend(reversed(child_dirs))
 
939
 
909
940
    def entries(self):
910
941
        """Return list of (path, ie) for all entries except the root.
911
942