1624
1624
The result may or may not reference the underlying inventory
1625
1625
so it should be treated as immutable.
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
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
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)
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
1659
interesting_parents.update(self.get_idpath(fileid))
1660
except errors.NoSuchId:
1661
# This fileid is not in the inventory - that's ok
1628
parent_to_children) = self._expand_fileids_to_parents_and_children(
1663
1630
entries = self.iter_entries()
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:
1679
other.add(entry.copy())
1639
if file_id in interesting:
1640
other.add(entry.copy())