Rev 3777: Make the parent_id_basename index be updated during CHKInventory.apply_delta. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Fri Nov 14 02:13:16 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 3777
revision-id: robertc at robertcollins.net-20081114021312-bis8oebl2q385qz0
parent: robertc at robertcollins.net-20081114012840-thsjm2g2xvtkk397
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Fri 2008-11-14 13:13:12 +1100
message:
Make the parent_id_basename index be updated during CHKInventory.apply_delta.
modified:
bzrlib/chk_map.py chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/tests/test_inv.py testinv.py-20050722220913-1dc326138d1a5892
bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2008-11-14 00:11:52 +0000
+++ b/bzrlib/chk_map.py 2008-11-14 02:13:12 +0000
@@ -55,7 +55,7 @@
if root_key is None:
self._root_node = LeafNode()
else:
- self._root_node = root_key
+ self._root_node = self._node_key(root_key)
def apply_delta(self, delta):
"""Apply a delta to the map.
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2008-11-14 01:28:40 +0000
+++ b/bzrlib/inventory.py 2008-11-14 02:13:12 +0000
@@ -1384,11 +1384,20 @@
"""
result = CHKInventory()
result.revision_id = new_revision_id
- result.id_to_entry = chk_map.CHKMap(self.id_to_entry._store,
+ result.id_to_entry = chk_map.CHKMap(
+ self.id_to_entry._store,
self.id_to_entry._root_node)
+ if self.parent_id_basename_to_file_id is not None:
+ result.parent_id_basename_to_file_id = chk_map.CHKMap(
+ self.parent_id_basename_to_file_id._store,
+ self.parent_id_basename_to_file_id._root_node)
+ parent_id_basename_delta = []
+ else:
+ result.parent_id_basename_to_file_id = None
result.root_id = self.root_id
id_to_entry_delta = []
for old_path, new_path, file_id, entry in inventory_delta:
+ # file id changes
if new_path == '':
result.root_id = file_id
if new_path is None:
@@ -1403,7 +1412,26 @@
else:
old_key = (file_id,)
id_to_entry_delta.append((old_key, new_key, new_value))
+ if result.parent_id_basename_to_file_id is not None:
+ # parent_id, basename changes
+ if old_path is None:
+ old_key = None
+ else:
+ old_entry = self[file_id]
+ old_key = self._parent_id_basename_key(old_entry)
+ if new_path is None:
+ new_key = None
+ new_value = None
+ else:
+ new_key = self._parent_id_basename_key(entry)
+ new_value = file_id
+ if old_key != new_key:
+ # If the two keys are the same, the value will be unchanged
+ # as its always the file id.
+ parent_id_basename_delta.append((old_key, new_key, new_value))
result.id_to_entry.apply_delta(id_to_entry_delta)
+ if result.parent_id_basename_to_file_id is not None:
+ result.parent_id_basename_to_file_id.apply_delta(parent_id_basename_delta)
return result
@classmethod
@@ -1422,13 +1450,13 @@
raise ValueError("not a serialised CHKInventory: %r" % bytes)
result.revision_id = lines[1][13:]
result.root_id = lines[2][9:]
- if lines[3].startswith('parent_id_to_basename:'):
+ if lines[3].startswith('parent_id_basename_to_file_id:'):
next = 4
- result.parent_id_to_basename = chk_map.CHKMap(
- chk_store, (lines[3][23:],))
+ result.parent_id_basename_to_file_id = chk_map.CHKMap(
+ chk_store, (lines[3][31:],))
else:
next = 3
- result.parent_id_to_basename = None
+ result.parent_id_basename_to_file_id = None
result.id_to_entry = chk_map.CHKMap(chk_store, (lines[next][13:],))
if (result.revision_id,) != expected_revision_id:
raise ValueError("Mismatched revision id and expected: %r, %r" %
@@ -1456,29 +1484,33 @@
result.id_to_entry._root_node.set_maximum_size(maximum_size)
file_id_delta = []
if parent_id_basename_index:
- result.parent_id_to_basename = chk_map.CHKMap(chk_store, None)
- result.parent_id_to_basename._root_node.set_maximum_size(
+ result.parent_id_basename_to_file_id = chk_map.CHKMap(chk_store, None)
+ result.parent_id_basename_to_file_id._root_node.set_maximum_size(
maximum_size)
- result.parent_id_to_basename._root_node._key_width = 2
+ result.parent_id_basename_to_file_id._root_node._key_width = 2
parent_id_delta = []
else:
- result.parent_id_to_basename = None
+ result.parent_id_basename_to_file_id = None
for path, entry in inventory.iter_entries():
file_id_delta.append((None, (entry.file_id,),
result._entry_to_bytes(entry)))
if parent_id_basename_index:
- if entry.parent_id is not None:
- parent_id = entry.parent_id
- else:
- parent_id = ''
- parent_id_delta.append((None,
- (parent_id, entry.name.encode('utf8')), entry.file_id))
+ parent_id_delta.append(
+ (None, result._parent_id_basename_key(entry),
+ entry.file_id))
result.id_to_entry.apply_delta(file_id_delta)
if parent_id_basename_index:
- result.parent_id_to_basename.apply_delta(parent_id_delta)
- result.id_to_entry._save()
+ result.parent_id_basename_to_file_id.apply_delta(parent_id_delta)
return result
+ def _parent_id_basename_key(self, entry):
+ """Create a key for a entry in a parent_id_basename_to_file_id index."""
+ if entry.parent_id is not None:
+ parent_id = entry.parent_id
+ else:
+ parent_id = ''
+ return parent_id, entry.name.encode('utf8')
+
def __getitem__(self, file_id):
"""map a single file_id -> InventoryEntry."""
try:
@@ -1612,9 +1644,9 @@
lines = ["chkinventory:\n"]
lines.append("revision_id: %s\n" % self.revision_id)
lines.append("root_id: %s\n" % self.root_id)
- if self.parent_id_to_basename is not None:
- lines.append('parent_id_to_basename: %s\n' %
- self.parent_id_to_basename.key())
+ if self.parent_id_basename_to_file_id is not None:
+ lines.append('parent_id_basename_to_file_id: %s\n' %
+ self.parent_id_basename_to_file_id.key())
lines.append("id_to_entry: %s\n" % self.id_to_entry.key())
return lines
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2008-11-14 01:28:40 +0000
+++ b/bzrlib/tests/test_inv.py 2008-11-14 02:13:12 +0000
@@ -404,6 +404,32 @@
self.assertEqual(reference_inv.id_to_entry._root_node._key,
new_inv.id_to_entry._root_node._key)
+ def test_create_by_apply_delta_empty_add_child_updates_parent_id(self):
+ inv = Inventory()
+ inv.revision_id = "revid"
+ inv.root.revision = "rootrev"
+ chk_bytes = self.get_chk_bytes()
+ base_inv = CHKInventory.from_inventory(chk_bytes, inv,
+ parent_id_basename_index=True)
+ a_entry = InventoryFile("A-id", "A", inv.root.file_id)
+ a_entry.revision = "filerev"
+ a_entry.executable = True
+ a_entry.text_sha1 = "ffff"
+ a_entry.text_size = 1
+ inv.add(a_entry)
+ inv.revision_id = "expectedid"
+ reference_inv = CHKInventory.from_inventory(chk_bytes, inv,
+ parent_id_basename_index=True)
+ delta = [(None, "A", "A-id", a_entry)]
+ new_inv = base_inv.create_by_apply_delta(delta, "expectedid")
+ # new_inv should be the same as reference_inv.
+ self.assertEqual(reference_inv.revision_id, new_inv.revision_id)
+ self.assertEqual(reference_inv.root_id, new_inv.root_id)
+ self.assertEqual(reference_inv.id_to_entry._root_node._key,
+ new_inv.id_to_entry._root_node._key)
+ self.assertEqual(reference_inv.parent_id_basename_to_file_id._root_node._key,
+ new_inv.parent_id_basename_to_file_id._root_node._key)
+
def test_iter_changes(self):
# Low level bootstrapping smoke test; comprehensive generic tests via
# InterTree are coming.
@@ -436,15 +462,15 @@
(False, True))],
list(inv_1.iter_changes(inv_2)))
- def test_parent_id_to_basename_index_off_by_default(self):
+ def test_parent_id_basename_to_file_id_index_off_by_default(self):
inv = Inventory()
inv.revision_id = "revid"
inv.root.revision = "rootrev"
chk_bytes = self.get_chk_bytes()
chk_inv = CHKInventory.from_inventory(chk_bytes, inv)
- self.assertEqual(None, chk_inv.parent_id_to_basename)
+ self.assertEqual(None, chk_inv.parent_id_basename_to_file_id)
- def test_parent_id_to_basename_index_enabled(self):
+ def test_parent_id_basename_to_file_id_index_enabled(self):
inv = Inventory()
inv.revision_id = "revid"
inv.root.revision = "rootrev"
@@ -459,7 +485,7 @@
parent_id_basename_index=True)
bytes = ''.join(tmp_inv.to_lines())
chk_inv = CHKInventory.deserialise(chk_bytes, bytes, ("revid",))
- self.assertIsInstance(chk_inv.parent_id_to_basename, chk_map.CHKMap)
+ self.assertIsInstance(chk_inv.parent_id_basename_to_file_id, chk_map.CHKMap)
self.assertEqual(
{('', ''): 'TREE_ROOT', ('TREE_ROOT', 'file'): 'fileid'},
- dict(chk_inv.parent_id_to_basename.iteritems()))
+ dict(chk_inv.parent_id_basename_to_file_id.iteritems()))
=== modified file 'bzrlib/tests/test_repository.py'
--- a/bzrlib/tests/test_repository.py 2008-11-14 01:28:40 +0000
+++ b/bzrlib/tests/test_repository.py 2008-11-14 02:13:12 +0000
@@ -698,12 +698,12 @@
tree.lock_read()
self.addCleanup(tree.unlock)
inv = tree.branch.repository.get_inventory(revid)
- self.assertNotEqual(None, inv.parent_id_to_basename)
- inv.parent_id_to_basename._ensure_root()
+ self.assertNotEqual(None, inv.parent_id_basename_to_file_id)
+ inv.parent_id_basename_to_file_id._ensure_root()
inv.id_to_entry._ensure_root()
self.assertEqual(4096, inv.id_to_entry._root_node.maximum_size)
self.assertEqual(4096,
- inv.parent_id_to_basename._root_node.maximum_size)
+ inv.parent_id_basename_to_file_id._root_node.maximum_size)
class TestDevelopment3FindRevisionOutsideSet(TestCaseWithTransport):
More information about the bazaar-commits
mailing list