Rev 3851: Add a test which ensures that insert_record_stream properly re-compresses in http://bzr.arbash-meinel.com/branches/bzr/1.10-dev/300177_record_stream_compression_parent
John Arbash Meinel
john at arbash-meinel.com
Fri Feb 6 21:42:35 GMT 2009
At http://bzr.arbash-meinel.com/branches/bzr/1.10-dev/300177_record_stream_compression_parent
------------------------------------------------------------
revno: 3851
revision-id: john at arbash-meinel.com-20090206214226-175csp8f33bxotjv
parent: john at arbash-meinel.com-20081216233307-z9ejmqds2308t5q4
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 300177_record_stream_compression_parent
timestamp: Fri 2009-02-06 15:42:26 -0600
message:
Add a test which ensures that insert_record_stream properly re-compresses
entries which have a non-lhs compression parent.
-------------- next part --------------
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2008-12-16 23:17:12 +0000
+++ b/bzrlib/knit.py 2009-02-06 21:42:26 +0000
@@ -1888,9 +1888,6 @@
if parents is None:
# kndx indices cannot be parentless.
parents = ()
- # if c_parent is not None and c_parent != parents[0]:
- # raise AssertionError('Kndx files do not support'
- # ' non-left-hand compression parents.')
line = "\n%s %s %s %s %s :" % (
key[-1], ','.join(options), pos, size,
self._dictionary_compress(parents))
@@ -2330,7 +2327,9 @@
if len(compression_parents) > 1 or len(parents) < 1:
return False
# XXX: restore this to allow pack compression parents to be
- # non-left-hand
+ # non-left-hand. This probably requires a repository format bump,
+ # so that we don't allow old clients that cannot support it, to
+ # accidentally access repositories using this feature.
# if compression_parents[0] in parents:
if compression_parents[0] == parents[0]:
return True
=== modified file 'bzrlib/tests/interrepository_implementations/test_fetch.py'
--- a/bzrlib/tests/interrepository_implementations/test_fetch.py 2008-12-16 15:15:08 +0000
+++ b/bzrlib/tests/interrepository_implementations/test_fetch.py 2009-02-06 21:42:26 +0000
@@ -26,6 +26,7 @@
from bzrlib.errors import (
NoSuchRevision,
)
+from bzrlib.repofmt import weaverepo
from bzrlib.revision import (
NULL_REVISION,
Revision,
@@ -192,17 +193,73 @@
self.assertEqual(computed_inv_sha1, recorded_inv_sha1)
def test_get_and_insert_record_stream(self):
- builder = self.make_branch_builder('test',
+ # Blacklist Weave repositories, because we know they return fulltexts
+ # for get_record_stream()
+ if self.repository_format.__class__ in (weaverepo.RepositoryFormat5,
+ weaverepo.RepositoryFormat7):
+ raise TestNotApplicable("Weave repos don't transmit line-deltas.")
+ builder = self.make_branch_builder('from',
format=self.repository_format._matchingbzrdir)
builder.start_series()
+ content_A = ('content A\nhas quite a bit\nof text\nso that we\n'
+ 'want to write deltas\n')
builder.build_snapshot('A', None, [
('add', ('', 'TREE_ROOT', 'directory', None)),
- ('add', ('file', 'f-id', 'file', 'content A\n'))])
+ ('add', ('file', 'f-id', 'file', content_A))])
builder.build_snapshot('B', ['A'], [
- ('modify', ('f-id', 'content-A\ncontent-B\n'))])
+ ('modify', ('f-id', 'content A\ncontent B\n'))])
builder.finish_series()
b = builder.get_branch()
self.assertEqual(b.repository._format, self.repository_format)
+ # Fetch these two revisions into the target repository
+ new_repo = self.make_to_repository('to')
+ new_repo.lock_write()
+ self.addCleanup(new_repo.unlock)
+ new_repo.fetch(b.repository, 'A')
+ new_repo.fetch(b.repository, 'B')
+
+ # We add a text with 'B' as the first parent, so that the delta will
+ # be against 'B'
+ b.lock_write()
+ b.repository.start_write_group()
+ b.repository.texts.add_lines(('f-id', 'C'),
+ [('f-id', 'B'), ('f-id', 'A')],
+ ['content A\n', 'content C\n', 'content B\n'])
+ b.repository.commit_write_group()
+ b.unlock()
+ b.lock_read()
+ self.addCleanup(b.unlock)
+
+ # At this point we cheat (a lot) and fudge the record. We leave the
+ # delta against B, but we change the parents so that it looks like B is
+ # the right-hand parent
+ record = b.repository.texts.get_record_stream([('f-id', 'C')],
+ 'unordered', False).next()
+ # Start with this
+ self.assertEqual((('f-id', 'B'),), record.compression_parents)
+ self.assertEqual((('f-id', 'B'), ('f-id', 'A')), record.parents)
+ # Now munge the record
+ record.parents = (('f-id', 'A'), ('f-id', 'B'))
+
+ # Insert this in the target repository
+ new_repo.start_write_group()
+ new_repo.texts.insert_record_stream([record])
+ new_repo.commit_write_group()
+ # The insert_record_stream should notice the non-left-hand parent, and
+ # properly extract and then turn around and change the compression
+ # parent
+ # When we have a target repository format that can handle non-lhs
+ # parents as the compression parent, this test will need to be updated
+ record = new_repo.texts.get_record_stream([('f-id', 'C')], 'unordered',
+ False).next()
+ self.assertEqual((('f-id', 'A'),), record.compression_parents)
+ self.assertEqual((('f-id', 'A'), ('f-id', 'B')), record.parents)
+ # And we should also be able to get the text compeletely
+ record = new_repo.texts.get_record_stream([('f-id', 'C')], 'unordered',
+ True).next()
+ self.assertEqualDiff('content A\ncontent C\ncontent B\n',
+ record.get_bytes_as('fulltext'))
+
class TestFetchDependentData(TestCaseWithInterRepository):
More information about the bazaar-commits
mailing list