Rev 5110: Hook up some of the add and remove functionality. in http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack
John Arbash Meinel
john at arbash-meinel.com
Tue Mar 9 21:35:48 GMT 2010
At http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack
------------------------------------------------------------
revno: 5110
revision-id: john at arbash-meinel.com-20100309213536-gjyg2idv2b4sdnn3
parent: john at arbash-meinel.com-20100309181742-l81zsib6fbtx5yju
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.2.0b2-contained-pack
timestamp: Tue 2010-03-09 15:35:36 -0600
message:
Hook up some of the add and remove functionality.
-------------- next part --------------
=== modified file 'bzrlib/pack_collection.py'
--- a/bzrlib/pack_collection.py 2010-03-09 18:17:42 +0000
+++ b/bzrlib/pack_collection.py 2010-03-09 21:35:36 +0000
@@ -458,9 +458,9 @@
return self._indexes
# TODO: This should only be needed for NewPack...
- def get_index_memo(self):
- """Return a byte string that can be used to initialize indexes."""
- raise NotImplementedError(self.get_index_memo)
+ #def get_index_memo(self):
+ # """Return a byte string that can be used to initialize indexes."""
+ # raise NotImplementedError(self.get_index_memo)
class PackPolicy(object):
@@ -557,17 +557,17 @@
# del self.combined_index._indices[:]
# self.add_callback = None
- # def remove_index(self, index):
- # """Remove index from the indices used to answer queries.
+ def remove_index(self, index):
+ """Remove index from the indices used to answer queries.
- # :param index: An index from the pack parameter.
- # """
- # del self.index_to_pack[index]
- # self.combined_index._indices.remove(index)
- # if (self.add_callback is not None and
- # getattr(index, 'add_nodes', None) == self.add_callback):
- # self.add_callback = None
- # self.data_access.set_writer(None, None, (None, None))
+ :param index: An index from the pack parameter.
+ """
+ # del self.index_to_pack[index]
+ self.combined_index._indices.remove(index)
+ # if (self.add_callback is not None and
+ # getattr(index, 'add_nodes', None) == self.add_callback):
+ # self.add_callback = None
+ # self.data_access.set_writer(None, None, (None, None))
class PackCollection(object):
@@ -608,8 +608,11 @@
def _remove_pack_from_memo(self, name, value):
pack = self._packs.pop(name)
assert pack.name == name
- assert pack.get_index_memo() == value
+ #assert pack.get_index_memo() == value
# TODO: Do something with the aggregate indexes
+ for index_name, index in pack.get_indexes().iteritems():
+ agg_index = self._aggregate_indexes[index_name]
+ agg_index.remove_index(index)
class PackCollectionUpdatePolicy(UpdatePolicy):
=== modified file 'bzrlib/tests/test_pack_collection.py'
--- a/bzrlib/tests/test_pack_collection.py 2010-03-09 18:17:42 +0000
+++ b/bzrlib/tests/test_pack_collection.py 2010-03-09 21:35:36 +0000
@@ -462,10 +462,13 @@
pack_collection.GraphIndexPolicy(self.get_transport(), 'meta',
btree_index.BTreeBuilder, btree_index.BTreeGraphIndex))
+ def make_collection(self):
+ tracker = self.make_tracker()
+ return pack_collection.PackCollection(tracker,
+ SingleTransportPackPolicy(self.get_transport()))
+
def test_init_from_empty_tracker(self):
- tracker = self.make_tracker()
- collection = pack_collection.PackCollection(tracker,
- SingleTransportPackPolicy(self.get_transport()))
+ collection = self.make_collection()
self.assertEqual({}, collection._packs)
self.assertEqual({}, collection._aggregate_indexes)
@@ -478,3 +481,30 @@
self.assertEqual(['t-pack'], sorted(collection._packs.keys()))
# We should also have the aggregate index created.
self.assertEqual(['t_index'], sorted(collection._aggregate_indexes))
+
+ def test__add_pack(self):
+ collection = self.make_collection()
+ memo = bencode.bencode({'t_index': (1024,)})
+ # Adding an item to the tracker should trigger _add_pack_from_memo
+ collection.memo_tracker.add_memo('t-pack', memo)
+ self.assertEqual(['t-pack'], sorted(collection._packs.keys()))
+ # We should also have the aggregate index created.
+ self.assertEqual(['t_index'], sorted(collection._aggregate_indexes))
+ agg_index = collection._aggregate_indexes['t_index']
+ self.assertEqual(1, len(agg_index.combined_index._indices))
+
+ def test__remove_pack(self):
+ collection = self.make_collection()
+ memo = bencode.bencode({'t_index': (1024,)})
+ collection.memo_tracker.add_memo('t-pack', memo)
+ self.assertEqual(['t-pack'], sorted(collection._packs.keys()))
+ # We should also have the aggregate index created.
+ self.assertEqual(['t_index'], sorted(collection._aggregate_indexes))
+ agg_index = collection._aggregate_indexes['t_index']
+ self.assertEqual(1, len(agg_index.combined_index._indices))
+ # removing an item to the tracker should trigger _remove_pack_from_memo
+ collection.memo_tracker.remove_memo('t-pack', memo)
+ self.assertEqual([], sorted(collection._packs.keys()))
+ self.assertEqual(['t_index'], sorted(collection._aggregate_indexes))
+ agg_index = collection._aggregate_indexes['t_index']
+ self.assertEqual(0, len(agg_index.combined_index._indices))
More information about the bazaar-commits
mailing list