~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-01 23:39:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6519.
  • Revision ID: jelmer@samba.org-20120401233957-dz6wuqz41wehv156
Revert bundle serializer code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# But those depend on its position within a particular inventory, and
24
24
# it would be nice not to need to hold the backpointer here.
25
25
 
 
26
from __future__ import absolute_import
 
27
 
26
28
# This should really be an id randomly assigned when the tree is
27
29
# created, but it's not for now.
28
30
ROOT_ID = "TREE_ROOT"
848
850
            descend(self.root, u'')
849
851
        return accum
850
852
 
851
 
    def directories(self):
852
 
        """Return (path, entry) pairs for all directories, including the root.
853
 
        """
854
 
        accum = []
855
 
        def descend(parent_ie, parent_path):
856
 
            accum.append((parent_path, parent_ie))
857
 
 
858
 
            kids = [(ie.name, ie) for ie in parent_ie.children.itervalues() if ie.kind == 'directory']
859
 
            kids.sort()
860
 
 
861
 
            for name, child_ie in kids:
862
 
                child_path = osutils.pathjoin(parent_path, name)
863
 
                descend(child_ie, child_path)
864
 
        descend(self.root, u'')
865
 
        return accum
866
 
 
867
853
    def path2id(self, relpath):
868
854
        """Walk down through directories to return entry of last component.
869
855
 
1490
1476
            if entry.kind == 'directory':
1491
1477
                directories_to_expand.add(entry.file_id)
1492
1478
            interesting.add(entry.parent_id)
1493
 
            children_of_parent_id.setdefault(entry.parent_id, []
1494
 
                                             ).append(entry.file_id)
 
1479
            children_of_parent_id.setdefault(entry.parent_id, set()
 
1480
                                             ).add(entry.file_id)
1495
1481
 
1496
1482
        # Now, interesting has all of the direct parents, but not the
1497
1483
        # parents of those parents. It also may have some duplicates with
1505
1491
            next_parents = set()
1506
1492
            for entry in self._getitems(remaining_parents):
1507
1493
                next_parents.add(entry.parent_id)
1508
 
                children_of_parent_id.setdefault(entry.parent_id, []
1509
 
                                                 ).append(entry.file_id)
 
1494
                children_of_parent_id.setdefault(entry.parent_id, set()
 
1495
                                                 ).add(entry.file_id)
1510
1496
            # Remove any search tips we've already processed
1511
1497
            remaining_parents = next_parents.difference(interesting)
1512
1498
            interesting.update(remaining_parents)
1525
1511
            for entry in self._getitems(next_file_ids):
1526
1512
                if entry.kind == 'directory':
1527
1513
                    directories_to_expand.add(entry.file_id)
1528
 
                children_of_parent_id.setdefault(entry.parent_id, []
1529
 
                                                 ).append(entry.file_id)
 
1514
                children_of_parent_id.setdefault(entry.parent_id, set()
 
1515
                                                 ).add(entry.file_id)
1530
1516
        return interesting, children_of_parent_id
1531
1517
 
1532
1518
    def filter(self, specific_fileids):