Rev 5108: Another policy object. 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 18:08:01 GMT 2010
At http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack
------------------------------------------------------------
revno: 5108
revision-id: john at arbash-meinel.com-20100309180751-y6i1eub2mbkabjw6
parent: john at arbash-meinel.com-20100309174226-210ezid8ioe8575n
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.2.0b2-contained-pack
timestamp: Tue 2010-03-09 12:07:51 -0600
message:
Another policy object.
I'm worried I'm going a bit overboard, but it is also nice to have the
discrete units of logic self-contained, rather than always being
aggregated into a single class.
-------------- next part --------------
=== modified file 'bzrlib/pack_collection.py'
--- a/bzrlib/pack_collection.py 2010-03-09 17:42:26 +0000
+++ b/bzrlib/pack_collection.py 2010-03-09 18:07:51 +0000
@@ -461,16 +461,29 @@
"""Return a byte string that can be used to initialize indexes."""
raise NotImplementedError(self.get_index_memo)
- @classmethod
- def from_index_memo(cls, collection, name, memo):
- """Return a new Pack instance, initialized from the given index memo.
+
+class PackPolicy(object):
+ """Description of how we want to manage pack files.
+
+ This handles stuff like 'do we write to one directory, and then rename to
+ another (upload/ vs packs/)'. Or do we just use one location, etc.
+ """
+
+ _pack_class = Pack # XXX: ExistingPack?
+
+ def __init__(self):
+ pass
+
+ def open_pack_from_memo(self, name, memo):
+ """Return a Pack instance, initialized from the given index memo.
:param collection: A PackCollection that this pack is associated with
+ :param name: The 'name' associated with this memo (eg, pack filename)
:param memo: A memo that was returned by 'get_index_memo' at some point
previously.
:return: A Pack instance
"""
- raise NotImplementedError(cls.from_index_memo)
+ raise NotImplementedError(self.create_pack_from_memo)
class PackCollection(object):
@@ -484,8 +497,8 @@
# TODO: _new_pack_class
- def __init__(self, memo_tracker, pack_class):
- self._pack_class = pack_class
+ def __init__(self, memo_tracker, pack_policy):
+ self.pack_policy = pack_policy
self.memo_tracker = memo_tracker
self.memo_tracker.update_policy = PackCollectionUpdatePolicy(self)
self._packs = {}
@@ -496,7 +509,7 @@
def _add_pack_from_memo(self, name, value):
assert name not in self._packs
- pack = self._pack_class.from_index_memo(self, name, value)
+ pack = self.pack_policy.open_pack_from_memo(name, value)
self._packs[name] = pack
# TODO: Do something with the aggregate indexes
for name, index in pack.get_indexes().iteritems():
=== modified file 'bzrlib/tests/test_pack_collection.py'
--- a/bzrlib/tests/test_pack_collection.py 2010-03-09 17:42:26 +0000
+++ b/bzrlib/tests/test_pack_collection.py 2010-03-09 18:07:51 +0000
@@ -431,23 +431,24 @@
], policy.log)
-class TestPack(pack_collection.Pack):
- """A class which defines a couple indexes, and exposes them."""
+class SingleTransportPackPolicy(pack_collection.PackPolicy):
+ """Packs are created and finished in a single transport location.
+
+ Indexes are also located in the same transport.
+ """
_index_class = btree_index.BTreeGraphIndex
- def get_index_memo(self):
- return bencode.bencode(self._index_info)
+ def __init__(self, transport):
+ self.transport = transport
- @classmethod
- def from_index_memo(cls, collection, name, memo):
+ def open_pack_from_memo(self, name, memo):
info = bencode.bdecode(memo)
assert isinstance(info, dict)
- p = cls(name)
+ p = pack_collection.Pack(name)
for index_name, info in info.iteritems():
size, = info
- trans = collection.memo_tracker.index_policy.transport
- index = cls._index_class(trans, name, size=size)
+ index = self._index_class(self.transport, name, size=size)
p._indexes[index_name] = index
p._index_info = info
return p
@@ -463,7 +464,8 @@
def test_init_from_empty_tracker(self):
tracker = self.make_tracker()
- collection = pack_collection.PackCollection(tracker, TestPack)
+ collection = pack_collection.PackCollection(tracker,
+ SingleTransportPackPolicy(self.get_transport()))
self.assertEqual({}, collection._packs)
self.assertEqual({}, collection._aggregate_indexes)
@@ -471,5 +473,6 @@
memo = bencode.bencode({'t_index': (1024,)})
tracker = self.make_tracker()
tracker.add_memo('t-pack', memo)
- collection = pack_collection.PackCollection(tracker, TestPack)
+ collection = pack_collection.PackCollection(tracker,
+ SingleTransportPackPolicy(self.get_transport()))
self.assertEqual(['t-pack'], sorted(collection._packs.keys()))
More information about the bazaar-commits
mailing list