~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: John Arbash Meinel
  • Date: 2009-09-23 22:14:34 UTC
  • mto: (4634.52.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4716.
  • Revision ID: john@arbash-meinel.com-20090923221434-nxjx0is3chbh37do
(broken) Start working on actually writing a permutation for per_inventory.

For now, we'll do something similar to the per-tree code. Where we create a regular
Inventory object to do mutation, and then snapshot it into a final representation for testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1624
1624
        The result may or may not reference the underlying inventory
1625
1625
        so it should be treated as immutable.
1626
1626
        """
1627
 
        interesting_parents = set()
1628
 
        # TODO: Pre-pass over the list of fileids to see if anything is already
1629
 
        #       deserialized in self._fileid_to_entry_cache
1630
 
 
1631
 
        directories_to_expand = set()
1632
 
        children_of_parent_id = {}
1633
 
        # It is okay if some of the fileids are missing
1634
 
        bytes_to_entry = self._bytes_to_entry
1635
 
        for file_id, value in self.id_to_entry.iteritems(specific_fileids): 
1636
 
            entry = bytes_to_entry(bytes)
1637
 
            if entry.kind == 'directory':
1638
 
                directories_to_expand.add(file_id)
1639
 
            interesting_parents.add(entry.parent_id)
1640
 
            children_of_parent_id.setdefault(entry.parent_id, []).append(entry)
1641
 
        # Now, interesting_parents has all of the direct parents, but not the
1642
 
        # parents of those parents. It also may have some duplicates with
1643
 
        # specific_fileids
1644
 
        remaining_parents = interesting_parents.difference(specific_fileids)
1645
 
        while remaining_parents:
1646
 
            next_parents = set()
1647
 
            for file_id, value in self.id_to_entry.iteritems(remaining_parents):
1648
 
                entry = bytes_to_entry(bytes)
1649
 
                next_parents.add(entry.parent_id)
1650
 
            # Remove any search tips we've already processed
1651
 
            remaining_parents = next_parents.difference(interesting_parents)
1652
 
 
1653
 
        # So at this point, we know all the specific_fileids that are
1654
 
        # directories, and we know all of the parent ids which need to be
1655
 
        # included, but not recursed
1656
 
        for fileid in specific_fileids:
1657
 
            ie = self.id_to_entry
1658
 
            try:
1659
 
                interesting_parents.update(self.get_idpath(fileid))
1660
 
            except errors.NoSuchId:
1661
 
                # This fileid is not in the inventory - that's ok
1662
 
                pass
 
1627
        (interesting,
 
1628
         parent_to_children) = self._expand_fileids_to_parents_and_children(
 
1629
                                specific_fileids)
1663
1630
        entries = self.iter_entries()
1664
1631
        # TODO: ???
1665
 
        if self.root is None:
1666
 
            return Inventory(root_id=None)
 
1632
        # if self.root is None:
 
1633
        return Inventory(root_id=None)
1667
1634
        other = Inventory(entries.next()[1].file_id)
1668
1635
        other.root.revision = self.root.revision
1669
1636
        other.revision_id = self.revision_id
1670
 
        directories_to_expand = set()
1671
1637
        for path, entry in entries:
1672
1638
            file_id = entry.file_id
1673
 
            if (file_id in specific_fileids
1674
 
                or entry.parent_id in directories_to_expand):
1675
 
                if entry.kind == 'directory':
1676
 
                    directories_to_expand.add(file_id)
1677
 
            elif file_id not in interesting_parents:
1678
 
                continue
1679
 
            other.add(entry.copy())
 
1639
            if file_id in interesting:
 
1640
                other.add(entry.copy())
1680
1641
        return other
1681
1642
 
1682
1643
    @staticmethod