Rev 2751: Move responsibility for adding split inventories to the repository onto the inventory in http://sourcefrog.net/bzr/inv-split
Martin Pool
mbp at sourcefrog.net
Wed Sep 19 03:56:02 BST 2007
At http://sourcefrog.net/bzr/inv-split
------------------------------------------------------------
revno: 2751
revision-id: mbp at sourcefrog.net-20070919025601-g1tilzi11huhtbw0
parent: mbp at sourcefrog.net-20070906061446-b62sn8lc3wqj8y2l
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: inv-split
timestamp: Wed 2007-09-19 12:56:01 +1000
message:
Move responsibility for adding split inventories to the repository onto the inventory
modified:
bzrlib/inventory_split.py inventory_lazy.py-20070822123225-v3guzmdkesxlfesa-1
bzrlib/repofmt/pack_repo.py pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
bzrlib/tests/test_pack_repository.py test_pack_repository-20070828111851-nof5soh31tidz2dq-1
=== modified file 'bzrlib/inventory_split.py'
--- a/bzrlib/inventory_split.py 2007-08-29 08:08:54 +0000
+++ b/bzrlib/inventory_split.py 2007-09-19 02:56:01 +0000
@@ -69,6 +69,20 @@
inv._repository = repo
return inv
+ def _add_to_repository(self, repo):
+ """Add a SplitInventory part by part into the repository.
+
+ This must be called with the repository in a write group.
+ """
+ index_additions = []
+ for dir_hash, dir_bytes in self._iter_serialized_parts():
+ # TODO: look in the existing index; if this text is in there then
+ # don't write it again.
+ repo._add_bytes_by_hashes([(dir_hash, dir_bytes)])
+ # return the last hash, which should be the root - this will fail if
+ # absolutely nothing was written, which is reasonable.
+ return dir_hash
+
def _ensure_loaded(self):
"""Load the inventory data from the repository.
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py 2007-09-06 06:14:46 +0000
+++ b/bzrlib/repofmt/pack_repo.py 2007-09-19 02:56:01 +0000
@@ -437,6 +437,9 @@
for revision_count, pack_details in pack_operations:
self._obsolete_packs(pack_details)
+ def _get_bytes_by_hash(self, h):
+ return self._get_bytes_by_hashes([h])[h]
+
def _get_bytes_by_hashes(self, hashes):
"""Look up objects by hash.
@@ -1302,40 +1305,6 @@
osutils.split_lines(inv_text))
return inv_sha1
- def _add_split_inventory(self, split_inventory):
- """Add a SplitInventory part by part into the repository.
-
- This must be called in a write group.
- """
- index_additions = []
- for dir_hash, dir_bytes in split_inventory._iter_serialized_parts():
- # TODO: look in the existing index; if this text is in there then
- # don't write it again.
- self._add_bytes_by_hashes([(dir_hash, dir_bytes)])
- # return the last hash, which should be the root - this will fail if
- # absolutely nothing was written, which is reasonable.
- return dir_hash
-
-## def _make_rev_pack_map(self, suffix):
-## """Return information on existing indexes.
-##
-## :param suffix: Index suffix added to pack name.
-##
-## :returns: (pack_map, indices) where indices is a list of GraphIndex
-## objects, and pack_map is a mapping from those objects to the
-## pack tuple they describe.
-## """
-## indices = []
-## pack_map = {}
-## self._packs.ensure_loaded()
-## for name in self._packs.names():
-## # TODO: maybe this should expose size to us to allow
-## # sorting of the indices for better performance ?
-## index_name = name + suffix
-## indices.append(GraphIndex(self._index_transport, index_name))
-## pack_map[indices[-1]] = (self._pack_tuple(name))
-## return pack_map, indices
-##
def _start_write_group(self):
random_name = self.control_files._lock.nonce
self._open_pack_tuple = (self._upload_transport, random_name + '.pack')
@@ -1493,6 +1462,7 @@
# delegated to the pack collection:
self._add_bytes_by_hashes = self._packs._add_bytes_by_hashes
self._get_bytes_by_hashes = self._packs._get_bytes_by_hashes
+ self._get_bytes_by_hash = self._packs._get_bytes_by_hash
def _pack_tuple(self, name):
"""Return a tuple with the transport and file name for a pack name."""
=== modified file 'bzrlib/tests/test_pack_repository.py'
--- a/bzrlib/tests/test_pack_repository.py 2007-09-06 06:13:55 +0000
+++ b/bzrlib/tests/test_pack_repository.py 2007-09-19 02:56:01 +0000
@@ -50,7 +50,7 @@
self.assertIsInstance(repo, pack_repo.GraphKnitRepository3)
repo.lock_write()
repo.start_write_group()
- root_hash = repo._add_split_inventory(inv)
+ root_hash = inv._add_to_repository(repo)
repo.commit_write_group()
# check that it was stored
repo.unlock()
@@ -58,8 +58,23 @@
self.assertEquals(40, len(root_hash))
# check we can retrieve it, and that it looks like a plausible
# inventory
- root_bytes = repo._get_bytes_by_hashes([root_hash])
- ## root_obs = bdecode(root_bytes)
+ root_bytes = repo._get_bytes_by_hash(root_hash)
+ self.assertIsInstance(root_bytes, str)
+ root_obs = bdecode(root_bytes)
+
+ def _add_split_inventory(self, split_inventory):
+ """Add a SplitInventory part by part into the repository.
+
+ This must be called in a write group.
+ """
+ index_additions = []
+ for dir_hash, dir_bytes in split_inventory._iter_serialized_parts():
+ # TODO: look in the existing index; if this text is in there then
+ # don't write it again.
+ self._add_bytes_by_hashes([(dir_hash, dir_bytes)])
+ # return the last hash, which should be the root - this will fail if
+ # absolutely nothing was written, which is reasonable.
+ return dir_hash
class TestHashStorage(TestCaseWithTransport):
More information about the bazaar-commits
mailing list