~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 17:25:29 UTC
  • mfrom: (6499 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6501.
  • Revision ID: v.ladeuil+lp@free.fr-20120313172529-i0suyjnepsor25i7
Merge trunk

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):
2125
2111
    def path2id(self, relpath):
2126
2112
        """See CommonInventory.path2id()."""
2127
2113
        # TODO: perhaps support negative hits?
 
2114
        if isinstance(relpath, basestring):
 
2115
            names = osutils.splitpath(relpath)
 
2116
        else:
 
2117
            names = relpath
 
2118
            if relpath == []:
 
2119
                relpath = [""]
 
2120
            relpath = osutils.pathjoin(*relpath)
2128
2121
        result = self._path_to_fileid_cache.get(relpath, None)
2129
2122
        if result is not None:
2130
2123
            return result
2131
 
        if isinstance(relpath, basestring):
2132
 
            names = osutils.splitpath(relpath)
2133
 
        else:
2134
 
            names = relpath
2135
2124
        current_id = self.root_id
2136
2125
        if current_id is None:
2137
2126
            return None