~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: John Arbash Meinel
  • Date: 2006-05-27 09:06:37 UTC
  • mto: (1711.2.26 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1734.
  • Revision ID: john@arbash-meinel.com-20060527090637-e79e7f56c20f70c3
Switch iter_entries from being a recursive function and using pathjoin

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
ROOT_ID = "TREE_ROOT"
29
29
 
30
30
 
 
31
import collections
31
32
import os.path
32
33
import re
33
34
import sys
827
828
    May also look up by name:
828
829
 
829
830
    >>> [x[0] for x in inv.iter_entries()]
830
 
    ['hello.c']
 
831
    [u'hello.c']
831
832
    >>> inv = Inventory('TREE_ROOT-12345678-12345678')
832
833
    >>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
833
834
    InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678')
880
881
        elif isinstance(from_dir, basestring):
881
882
            from_dir = self._byid[from_dir]
882
883
            
883
 
        kids = from_dir.children.items()
884
 
        kids.sort()
885
 
        for name, ie in kids:
886
 
            yield name, ie
887
 
            if ie.kind == 'directory':
888
 
                for cn, cie in self.iter_entries(from_dir=ie.file_id):
889
 
                    yield pathjoin(name, cn), cie
890
 
 
 
884
        children = from_dir.children.items()
 
885
        children.sort()
 
886
        children = collections.deque(children)
 
887
        stack = [(u'', children)]
 
888
        while stack:
 
889
            from_dir_relpath, children = stack[-1]
 
890
 
 
891
            while children:
 
892
                name, ie = children.popleft()
 
893
 
 
894
                # we know that from_dir_relpath never ends in a slash
 
895
                # and 'f' doesn't begin with one, we can do a string op, rather
 
896
                # than the checks of pathjoin(), though this means that all paths
 
897
                # start with a slash
 
898
                path = from_dir_relpath + '/' + name
 
899
 
 
900
                yield path[1:], ie
 
901
 
 
902
                if ie.kind != 'directory':
 
903
                    continue
 
904
 
 
905
                # But do this child first
 
906
                new_children = ie.children.items()
 
907
                new_children.sort()
 
908
                new_children = collections.deque(new_children)
 
909
                stack.append((path, new_children))
 
910
                # Break out of inner loop, so that we start outer loop with child
 
911
                break
 
912
            else:
 
913
                # if we finished all children, pop it off the stack
 
914
                if not children:
 
915
                    stack.pop()
891
916
 
892
917
    def entries(self):
893
918
        """Return list of (path, ie) for all entries except the root.