Rev 5086: Make the info *just* a serializer. in http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack
John Arbash Meinel
john at arbash-meinel.com
Fri Mar 5 20:02:46 GMT 2010
At http://bzr.arbash-meinel.com/branches/bzr/lp/2.2.0b2-contained-pack
------------------------------------------------------------
revno: 5086
revision-id: john at arbash-meinel.com-20100305200212-8wsj04zltj8r7dba
parent: john at arbash-meinel.com-20100305195926-ehqikk194yyn0v6s
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.2.0b2-contained-pack
timestamp: Fri 2010-03-05 14:02:12 -0600
message:
Make the info *just* a serializer.
-------------- next part --------------
=== modified file 'bzrlib/sack.py'
--- a/bzrlib/sack.py 2010-03-05 19:59:26 +0000
+++ b/bzrlib/sack.py 2010-03-05 20:02:12 +0000
@@ -33,26 +33,20 @@
_VERSION = 1
-class SectionInfo(object):
+class SectionInfoSerializer(object):
"""Track the information about the extra indexes."""
- def __init__(self):
- self._sections = {}
-
- def to_bytes(self):
+ def to_bytes(self, sections):
# TODO: Should this bencode chunk be zlib compressed? I don't expect
# it will be particularly long, but it is ascii, and might
# compress well. (quick testing only showed 67b => 63b, which
# isn't worthwhile)
- return bencode.bencode(self._sections)
+ return bencode.bencode(sections)
- @classmethod
- def from_bytes(cls, bytes):
+ def from_bytes(self, bytes):
sections = bencode.bdecode_as_tuple(bytes)
assert type(sections) is dict
- res = cls()
- res._sections = sections
- return res
+ return sections
class TrailingIndexBuilder(object):
@@ -73,14 +67,14 @@
def __init__(self, start_offset):
self.start_offset = start_offset
self.version = _VERSION
- self._section_info = SectionInfo()
+ self._sections = {}
def add_index_info(self, index_type, start, length):
# Note: bzr-search uses a ContainerWriter to write out the bytes, and
# then adjusts the offsets so that it skips the 'Pack' overhead bytes.
# I guess I don't really see the benefit versus the crufty overhead...
- assert index_type not in self._section_info._sections
- self._section_info._sections[index_type] = (start, length)
+ assert index_type not in self._sections
+ self._sections[index_type] = (start, length)
def finish(self):
# TODO: Perhaps this should be more like BTreeBuilder and return a
@@ -92,7 +86,7 @@
# quite tiny
chunks = []
chunks.append('%s%d\n' % (_HEADER_BASE, self.version))
- chunks.append(self._section_info.to_bytes())
+ chunks.append(SectionInfoSerializer().to_bytes(self._sections))
chunks.append(struct.pack('!QI', self.start_offset, self.version))
return ''.join(chunks)
@@ -106,7 +100,7 @@
def __init__(self, transport, filename):
# Map the name to the start and size of each section
- self._section_info = None
+ self._sections = {}
self._transport = transport
self._filename = filename
@@ -134,7 +128,7 @@
@classmethod
def from_indicies_memo(cls, transport, filename, memo_bytes):
ti = cls(transport, filename)
- ti._section_info = SectionInfo.from_bytes(memo_bytes)
+ ti._sections = SectionInfoSerializer().from_bytes(memo_bytes)
return ti
def get_named_index(self, name, index_class, **kwargs):
@@ -145,7 +139,7 @@
:param **kwargs: Any other named arguments will be passed to the index
constructor
"""
- start, length = self._section_info._sections[name]
+ start, length = self._sections[name]
return index_class(self._transport, self._filename, size=length,
**kwargs)
=== modified file 'bzrlib/tests/test_sack.py'
--- a/bzrlib/tests/test_sack.py 2010-03-05 19:59:26 +0000
+++ b/bzrlib/tests/test_sack.py 2010-03-05 20:02:12 +0000
@@ -109,7 +109,7 @@
t.put_bytes('test.sack', ' '*500 + content)
ti = sack.TrailingIndex.from_transport(t, 'test.sack')
# We skip the 16-byte header at the beginning, and the 12-byte tail
- self.assertEqual({'texts': (150, 350)}, ti._section_info._sections)
+ self.assertEqual({'texts': (150, 350)}, ti._sections)
def test_get_named_index(self):
index_builder = btree_index.BTreeBuilder(0, 1)
@@ -126,7 +126,7 @@
t.put_bytes('test.sack', content)
ti = sack.TrailingIndex.from_transport(t, 'test.sack')
self.assertEqual({'texts': (0, trail_start)},
- ti._section_info._sections)
+ ti._sections)
text_index = ti.get_named_index('texts', btree_index.BTreeGraphIndex)
assert_index_content(self, {('key1',): ('value1',),
('key2',): ('value2',),
More information about the bazaar-commits
mailing list