1365
def __init__(self, search_key_name):
1366
1366
CommonInventory.__init__(self)
1367
1367
self._entry_cache = {}
1368
self._search_key_name = search_key_name
1369
1370
def _entry_to_bytes(self, entry):
1370
1371
"""Serialise entry as a single bytestring.
1447
1448
:param new_revision_id: The revision id of the resulting CHKInventory.
1448
1449
:return: The new CHKInventory.
1450
result = CHKInventory()
1451
result = CHKInventory(self._search_key_name)
1452
search_key_func = chk_map.search_key_registry.get(self._search_key_name)
1451
1453
result.revision_id = new_revision_id
1452
1454
result.id_to_entry = chk_map.CHKMap(
1453
1455
self.id_to_entry._store,
1454
self.id_to_entry._root_node)
1456
self.id_to_entry._root_node,
1457
search_key_func=search_key_func)
1455
1458
if self.parent_id_basename_to_file_id is not None:
1456
1459
result.parent_id_basename_to_file_id = chk_map.CHKMap(
1457
1460
self.parent_id_basename_to_file_id._store,
1458
self.parent_id_basename_to_file_id._root_node)
1461
self.parent_id_basename_to_file_id._root_node,
1462
search_key_func=search_key_func)
1459
1463
parent_id_basename_delta = []
1461
1465
result.parent_id_basename_to_file_id = None
1510
1514
:return: A CHKInventory
1512
result = CHKInventory()
1513
1516
lines = bytes.splitlines()
1514
1517
if lines[0] != 'chkinventory:':
1515
1518
raise ValueError("not a serialised CHKInventory: %r" % bytes)
1516
result.revision_id = lines[1][13:]
1517
result.root_id = lines[2][9:]
1518
if lines[3].startswith('parent_id_basename_to_file_id:'):
1519
revision_id = lines[1][13:]
1520
root_id = lines[2][9:]
1521
if lines[3].startswith('search_key_name:'):
1522
search_key_name = lines[3][17:]
1520
result.parent_id_basename_to_file_id = chk_map.CHKMap(
1521
chk_store, (lines[3][31:],))
1525
search_key_name = 'plain'
1527
result = CHKInventory(search_key_name)
1528
result.revision_id = revision_id
1529
result.root_id = root_id
1530
search_key_func = chk_map.search_key_registry.get(
1531
result._search_key_name)
1532
if lines[next].startswith('parent_id_basename_to_file_id:'):
1533
result.parent_id_basename_to_file_id = chk_map.CHKMap(
1534
chk_store, (lines[next][31:],),
1535
search_key_func=search_key_func)
1524
1538
result.parent_id_basename_to_file_id = None
1525
result.id_to_entry = chk_map.CHKMap(chk_store, (lines[next][13:],))
1540
result.id_to_entry = chk_map.CHKMap(chk_store, (lines[next][13:],),
1541
search_key_func=search_key_func)
1526
1542
if (result.revision_id,) != expected_revision_id:
1527
1543
raise ValueError("Mismatched revision id and expected: %r, %r" %
1528
1544
(result.revision_id, expected_revision_id))
1532
1548
def from_inventory(klass, chk_store, inventory, maximum_size=0,
1533
parent_id_basename_index=False):
1549
parent_id_basename_index=False, search_key_name='plain'):
1534
1550
"""Create a CHKInventory from an existing inventory.
1536
1552
The content of inventory is copied into the chk_store, and a
1541
1557
:param maximum_size: The CHKMap node size limit.
1542
1558
:param parent_id_basename_index: If True create and use a
1543
1559
parent_id,basename->file_id index.
1560
:param search_key_name: The identifier for the search key function
1545
result = CHKInventory()
1562
result = CHKInventory(search_key_name)
1546
1563
result.revision_id = inventory.revision_id
1547
1564
result.root_id = inventory.root.file_id
1548
result.id_to_entry = chk_map.CHKMap(chk_store, None)
1565
search_key_func = chk_map.search_key_registry.get(search_key_name)
1566
result.id_to_entry = chk_map.CHKMap(chk_store, None, search_key_func)
1549
1567
result.id_to_entry._root_node.set_maximum_size(maximum_size)
1550
1568
file_id_delta = []
1551
1569
if parent_id_basename_index:
1552
result.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store, None)
1570
result.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store,
1571
None, search_key_func)
1553
1572
result.parent_id_basename_to_file_id._root_node.set_maximum_size(
1555
1574
result.parent_id_basename_to_file_id._root_node._key_width = 2
1745
1764
lines = ["chkinventory:\n"]
1746
1765
lines.append("revision_id: %s\n" % self.revision_id)
1747
1766
lines.append("root_id: %s\n" % self.root_id)
1767
if self._search_key_name != 'plain':
1768
lines.append('search_key_name: %s\n' % (self._search_key_name,))
1748
1769
if self.parent_id_basename_to_file_id is not None:
1749
1770
lines.append('parent_id_basename_to_file_id: %s\n' %
1750
1771
self.parent_id_basename_to_file_id.key())