1470
1470
self._path_to_fileid_cache = {}
1471
1471
self._search_key_name = search_key_name
1473
def __eq__(self, other):
1474
"""Compare two sets by comparing their contents."""
1475
if not isinstance(other, CHKInventory):
1476
return NotImplemented
1478
this_key = self.id_to_entry.key()
1479
other_key = other.id_to_entry.key()
1480
this_pid_key = self.parent_id_basename_to_file_id.key()
1481
other_pid_key = other.parent_id_basename_to_file_id.key()
1482
if None in (this_key, this_pid_key, other_key, other_pid_key):
1484
return this_key == other_key and this_pid_key == other_pid_key
1473
1486
def _entry_to_bytes(self, entry):
1474
1487
"""Serialise entry as a single bytestring.
1716
1729
:param maximum_size: The CHKMap node size limit.
1717
1730
:param search_key_name: The identifier for the search key function
1719
result = CHKInventory(search_key_name)
1732
result = klass(search_key_name)
1720
1733
result.revision_id = inventory.revision_id
1721
1734
result.root_id = inventory.root.file_id
1722
search_key_func = chk_map.search_key_registry.get(search_key_name)
1723
result.id_to_entry = chk_map.CHKMap(chk_store, None, search_key_func)
1724
result.id_to_entry._root_node.set_maximum_size(maximum_size)
1726
result.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store,
1727
None, search_key_func)
1728
result.parent_id_basename_to_file_id._root_node.set_maximum_size(
1730
result.parent_id_basename_to_file_id._root_node._key_width = 2
1731
parent_id_delta = []
1736
entry_to_bytes = result._entry_to_bytes
1737
parent_id_basename_key = result._parent_id_basename_key
1738
id_to_entry_dict = {}
1739
parent_id_basename_dict = {}
1732
1740
for path, entry in inventory.iter_entries():
1733
file_id_delta.append((None, (entry.file_id,),
1734
result._entry_to_bytes(entry)))
1735
parent_id_delta.append(
1736
(None, result._parent_id_basename_key(entry),
1738
result.id_to_entry.apply_delta(file_id_delta)
1739
result.parent_id_basename_to_file_id.apply_delta(parent_id_delta)
1741
id_to_entry_dict[(entry.file_id,)] = entry_to_bytes(entry)
1742
p_id_key = parent_id_basename_key(entry)
1743
parent_id_basename_dict[p_id_key] = entry.file_id
1745
result._populate_from_dicts(chk_store, id_to_entry_dict,
1746
parent_id_basename_dict, maximum_size=maximum_size)
1749
def _populate_from_dicts(self, chk_store, id_to_entry_dict,
1750
parent_id_basename_dict, maximum_size):
1751
search_key_func = chk_map.search_key_registry.get(self._search_key_name)
1752
root_key = chk_map.CHKMap.from_dict(chk_store, id_to_entry_dict,
1753
maximum_size=maximum_size, key_width=1,
1754
search_key_func=search_key_func)
1755
self.id_to_entry = chk_map.CHKMap(chk_store, root_key,
1757
root_key = chk_map.CHKMap.from_dict(chk_store,
1758
parent_id_basename_dict,
1759
maximum_size=maximum_size, key_width=2,
1760
search_key_func=search_key_func)
1761
self.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store,
1762
root_key, search_key_func)
1742
1764
def _parent_id_basename_key(self, entry):
1743
1765
"""Create a key for a entry in a parent_id_basename_to_file_id index."""
1744
1766
if entry.parent_id is not None: