Rev 4551: Add a custom get_invalid_bundle and allow BadBundle to be in http://bazaar.launchpad.net/~jameinel/bzr/1.18-bundle-and-stack-393349
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 22 22:12:58 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.18-bundle-and-stack-393349
------------------------------------------------------------
revno: 4551
revision-id: john at arbash-meinel.com-20090722211249-jam6coxdb7jnm213
parent: john at arbash-meinel.com-20090722202221-rk5t00spg81b6gpg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-bundle-and-stack-393349
timestamp: Wed 2009-07-22 16:12:49 -0500
message:
Add a custom get_invalid_bundle and allow BadBundle to be
a valid way to handle an invalid bundle.
The code was already checking that applying the mpdiff was giving the
correct sha1sum, and computing a custom value is very difficult.
-------------- next part --------------
=== modified file 'bzrlib/bundle/serializer/v4.py'
--- a/bzrlib/bundle/serializer/v4.py 2009-07-22 19:43:55 +0000
+++ b/bzrlib/bundle/serializer/v4.py 2009-07-22 21:12:49 +0000
@@ -147,7 +147,7 @@
body
"""
- def __init__(self, fileobj, stream_input=True):
+ def __init__(self, fileobj, stream_input=False):
"""Constructor
:param fileobj: a file containing a bzip-encoded container
@@ -377,7 +377,6 @@
self.bundle.add_multiparent_record(text, sha1, parent_ids,
'inventory', revision_id, None)
-
def _add_revision_texts(self, revision_order):
parent_map = self.repository.get_parent_map(revision_order)
revision_to_str = self.repository._serializer.write_revision_to_string
=== modified file 'bzrlib/tests/test_bundle.py'
--- a/bzrlib/tests/test_bundle.py 2009-07-22 20:22:21 +0000
+++ b/bzrlib/tests/test_bundle.py 2009-07-22 21:12:49 +0000
@@ -616,7 +616,8 @@
bundle = self.get_valid_bundle('a at cset-0-2', 'a at cset-0-3')
self.assertRaises((errors.TestamentMismatch,
- errors.VersionedFileInvalidChecksum), self.get_invalid_bundle,
+ errors.VersionedFileInvalidChecksum,
+ errors.BadBundle), self.get_invalid_bundle,
'a at cset-0-2', 'a at cset-0-3')
# Check a rollup bundle
bundle = self.get_valid_bundle('null:', 'a at cset-0-3')
@@ -1434,6 +1435,27 @@
def bzrdir_format(self):
return '2a'
+ def get_invalid_bundle(self, base_rev_id, rev_id):
+ """Create a bundle from base_rev_id -> rev_id in built-in branch.
+ Munge the text so that it's invalid.
+
+ :return: The in-memory bundle
+ """
+ from bzrlib.bundle import serializer
+ bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
+ new_text = self.get_raw(StringIO(''.join(bundle_txt)))
+ new_text = new_text.replace('<file file_id="exe-1"',
+ '<file executable="y" file_id="exe-1"')
+ new_text = new_text.replace('B280', 'B295')
+ bundle_txt = StringIO()
+ bundle_txt.write(serializer._get_bundle_header('4'))
+ bundle_txt.write('\n')
+ bundle_txt.write(new_text.encode('bz2'))
+ bundle_txt.seek(0)
+ bundle = read_bundle(bundle_txt)
+ self.valid_apply_bundle(base_rev_id, bundle)
+ return bundle
+
def make_merged_branch(self):
builder = self.make_branch_builder('source')
builder.start_series()
More information about the bazaar-commits
mailing list