~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

Teach CHKInventory with a parent_id_basename index how to load partial index contents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1683
1683
    def children(self):
1684
1684
        """Access the list of children of this inventory.
1685
1685
 
1686
 
        Currently causes a full-load of all the children; a more sophisticated
1687
 
        proxy object is planned.
 
1686
        With a parent_id_basename_to_file_id index, loads all the children,
 
1687
        without loads the entire index. Without is bad. A more sophisticated
 
1688
        proxy object might be nice, to allow partial loading of children as
 
1689
        well when specific names are accessed. (So path traversal can be
 
1690
        written in the obvious way but not examine siblings.).
1688
1691
        """
1689
1692
        if self._children is not None:
1690
1693
            return self._children
 
1694
        if self._chk_inventory.parent_id_basename_to_file_id is None:
 
1695
            # Slow path - read the entire inventory looking for kids.
 
1696
            result = {}
 
1697
            for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
 
1698
                entry = self._chk_inventory._bytes_to_entry(bytes)
 
1699
                if entry.parent_id == self.file_id:
 
1700
                    result[entry.name] = entry
 
1701
            self._children = result
 
1702
            return result
1691
1703
        result = {}
 
1704
        # XXX: Todo - use proxy objects for the children rather than loading
 
1705
        # all when the attribute is referenced.
 
1706
        parent_id_index = self._chk_inventory.parent_id_basename_to_file_id
 
1707
        child_ids = set()
 
1708
        for (parent_id, name_utf8), file_id in parent_id_index.iteritems(
 
1709
            key_filter=[(self.file_id,)]):
 
1710
            child_ids.add((file_id,))
1692
1711
        # populate; todo: do by name
1693
 
        for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
 
1712
        id_to_entry = self._chk_inventory.id_to_entry
 
1713
        for file_id, bytes in id_to_entry.iteritems(child_ids):
1694
1714
            entry = self._chk_inventory._bytes_to_entry(bytes)
1695
 
            if entry.parent_id == self.file_id:
1696
 
                result[entry.name] = entry
 
1715
            result[entry.name] = entry
1697
1716
        self._children = result
1698
1717
        return result
1699
1718