~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Aaron Bentley
  • Date: 2006-06-03 16:23:09 UTC
  • mfrom: (1736 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20060603162309-c975ca9ea9fea344
Merge from bzr.dev

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
668
669
 
669
670
    def _read_tree_state(self, path, work_tree):
670
671
        """See InventoryEntry._read_tree_state."""
671
 
        self.text_sha1 = work_tree.get_file_sha1(self.file_id)
672
 
        self.executable = work_tree.is_executable(self.file_id)
 
672
        self.text_sha1 = work_tree.get_file_sha1(self.file_id, path=path)
 
673
        self.executable = work_tree.is_executable(self.file_id, path=path)
673
674
 
674
675
    def _forget_tree_state(self):
675
676
        self.text_sha1 = None
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
        # unrolling the recursive called changed the time from
 
885
        # 440ms/663ms (inline/total) to 116ms/116ms
 
886
        children = from_dir.children.items()
 
887
        children.sort()
 
888
        children = collections.deque(children)
 
889
        stack = [(u'', children)]
 
890
        while stack:
 
891
            from_dir_relpath, children = stack[-1]
 
892
 
 
893
            while children:
 
894
                name, ie = children.popleft()
 
895
 
 
896
                # we know that from_dir_relpath never ends in a slash
 
897
                # and 'f' doesn't begin with one, we can do a string op, rather
 
898
                # than the checks of pathjoin(), though this means that all paths
 
899
                # start with a slash
 
900
                path = from_dir_relpath + '/' + name
 
901
 
 
902
                yield path[1:], ie
 
903
 
 
904
                if ie.kind != 'directory':
 
905
                    continue
 
906
 
 
907
                # But do this child first
 
908
                new_children = ie.children.items()
 
909
                new_children.sort()
 
910
                new_children = collections.deque(new_children)
 
911
                stack.append((path, new_children))
 
912
                # Break out of inner loop, so that we start outer loop with child
 
913
                break
 
914
            else:
 
915
                # if we finished all children, pop it off the stack
 
916
                stack.pop()
891
917
 
892
918
    def entries(self):
893
919
        """Return list of (path, ie) for all entries except the root.