Rev 3355: Create adapters from plain compressed knit content. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files
Robert Collins
robertc at robertcollins.net
Wed Apr 23 03:44:41 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/versioned_files
------------------------------------------------------------
revno: 3355
revision-id: robertc at robertcollins.net-20080423024436-2z78i674q9b8s09d
parent: robertc at robertcollins.net-20080418050245-07ltcfhagcw3xhnb
committer: Robert Collins <robertc at robertcollins.net>
branch nick: data_stream_revamp
timestamp: Wed 2008-04-23 12:44:36 +1000
message:
Create adapters from plain compressed knit content.
modified:
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2008-04-18 05:02:45 +0000
+++ b/bzrlib/knit.py 2008-04-23 02:44:36 +0000
@@ -212,6 +212,42 @@
return ''.join(basis_content.text())
+class FTPlainToFullText(KnitAdapter):
+ """An adapter from FT plain knits to unannotated ones."""
+
+ def get_bytes(self, factory, compressed_bytes):
+ rec, contents = \
+ self._data._parse_record_unchecked(compressed_bytes)
+ content, delta = self._plain_factory.parse_record(factory.key[0],
+ contents, factory._build_details, None)
+ return ''.join(content.text())
+
+
+class DeltaPlainToFullText(KnitAdapter):
+ """An adapter for deltas from annotated to unannotated."""
+
+ def __init__(self, basis_vf):
+ """Create an adapter which accesses full texts from basis_vf.
+
+ :param basis_vf: A versioned file to access basis texts of deltas from.
+ """
+ KnitAdapter.__init__(self)
+ self._basis_vf = basis_vf
+
+ def get_bytes(self, factory, compressed_bytes):
+ rec, contents = \
+ self._data._parse_record_unchecked(compressed_bytes)
+ delta = self._plain_factory.parse_line_delta(contents, rec[1])
+ compression_parent = factory.parents[0][0]
+ basis_lines = self._basis_vf.get_lines(compression_parent)
+ basis_content = PlainKnitContent(basis_lines, compression_parent)
+ # Manually apply the delta because we have one annotated content and
+ # one plain.
+ content, _ = self._plain_factory.parse_record(rec[1], contents,
+ factory._build_details, basis_content)
+ return ''.join(content.text())
+
+
class KnitContentFactory(ContentFactory):
"""Content factory for streaming from knits.
@@ -618,8 +654,6 @@
"""Factory to create a KnitVersionedFile for a .knit/.kndx file pair."""
if factory is None:
factory = KnitAnnotateFactory()
- else:
- factory = KnitPlainFactory()
if get_scope is None:
get_scope = lambda:None
index = _KnitIndex(transport, name + INDEX_SUFFIX,
=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py 2008-04-18 05:02:45 +0000
+++ b/bzrlib/tests/test_versionedfile.py 2008-04-23 02:44:36 +0000
@@ -1368,9 +1368,13 @@
"""Test that selecting an adaptor works."""
# self.assertEqual(versionedfile.
- def get_knit(self):
+ def get_knit(self, annotated=True):
+ if annotated:
+ factory = KnitAnnotateFactory()
+ else:
+ factory = KnitPlainFactory()
return make_file_knit('knit', self.get_transport('.'), delta=True,
- create=True)
+ create=True, factory=factory)
def helpGetBytes(self, f, ft_adapter, delta_adapter):
"""grab the interested adapted texts for tests."""
@@ -1446,3 +1450,21 @@
self.assertEqual('origin\n', ft_data)
self.assertEqual('base\nleft\nright\nmerged\n', delta_data)
self.assertEqual([('get_lines', 'left')], logged_vf.calls)
+
+ def test_unannotated_to_fulltext(self):
+ """Test adapting unannotated knits to full texts.
+
+ This is used for -> weaves, and for -> annotated knits.
+ """
+ # we need a full text, and a delta
+ f, parents = get_diamond_vf(self.get_knit(annotated=False))
+ # Reconstructing a full text requires a backing versioned file, and it
+ # must have the base lines requested from it.
+ logged_vf = versionedfile.RecordingVersionedFileDecorator(f)
+ ft_data, delta_data = self.helpGetBytes(f,
+ _mod_knit.FTPlainToFullText(),
+ _mod_knit.DeltaPlainToFullText(logged_vf))
+ self.assertEqual('origin\n', ft_data)
+ self.assertEqual('base\nleft\nright\nmerged\n', delta_data)
+ self.assertEqual([('get_lines', 'left')], logged_vf.calls)
+
More information about the bazaar-commits
mailing list