13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
from cStringIO import StringIO
22
22
from bzrlib import (
27
29
revision as _mod_revision,
30
from bzrlib.bzrdir import BzrDir
33
from bzrlib.bundle import read_mergeable_from_url
31
34
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
35
from bzrlib.bundle.bundle_data import BundleTree
36
from bzrlib.directory_service import directories
33
37
from bzrlib.bundle.serializer import write_bundle, read_bundle, v09, v4
34
38
from bzrlib.bundle.serializer.v08 import BundleSerializerV08
35
39
from bzrlib.bundle.serializer.v09 import BundleSerializerV09
36
40
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
37
from bzrlib.branch import Branch
38
from bzrlib.diff import internal_diff
39
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle,
41
from bzrlib.merge import Merge3Merger
42
41
from bzrlib.repofmt import knitrepo
43
from bzrlib.osutils import has_symlinks, sha_file
44
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
45
TestCase, TestSkipped, test_commit)
42
from bzrlib.tests import (
46
48
from bzrlib.transform import TreeTransform
47
from bzrlib.workingtree import WorkingTree
51
def get_text(vf, key):
52
"""Get the fulltext for a given revision id that is present in the vf"""
53
stream = vf.get_record_stream([key], 'unordered', True)
54
record = stream.next()
55
return record.get_bytes_as('fulltext')
58
def get_inventory_text(repo, revision_id):
59
"""Get the fulltext for the inventory at revision id"""
62
return get_text(repo.inventories, (revision_id,))
50
67
class MockTree(object):
51
69
def __init__(self):
52
70
from bzrlib.inventory import InventoryDirectory, ROOT_ID
53
71
object.__init__(self)
204
235
self.assertEqual(btree.path2id("grandparent2/parent2"), "b")
205
236
self.assertEqual(btree.path2id("grandparent2/parent2/file2"), "c")
207
assert btree.path2id("grandparent2/parent2/file") is None
238
self.assertTrue(btree.path2id("grandparent2/parent2/file") is None)
209
240
def test_moves(self):
210
241
"""Ensure that file moves have the proper effect on children"""
211
242
btree = self.make_tree_1()[0]
212
btree.note_rename("grandparent/parent/file",
243
btree.note_rename("grandparent/parent/file",
213
244
"grandparent/alt_parent/file")
214
245
self.assertEqual(btree.id2path("c"), "grandparent/alt_parent/file")
215
246
self.assertEqual(btree.path2id("grandparent/alt_parent/file"), "c")
216
assert btree.path2id("grandparent/parent/file") is None
247
self.assertTrue(btree.path2id("grandparent/parent/file") is None)
218
249
def unified_diff(self, old, new):
220
internal_diff("old", old, "new", new, out)
251
diff.internal_diff("old", old, "new", new, out)
222
253
return out.read()
224
255
def make_tree_2(self):
225
256
btree = self.make_tree_1()[0]
226
btree.note_rename("grandparent/parent/file",
257
btree.note_rename("grandparent/parent/file",
227
258
"grandparent/alt_parent/file")
228
assert btree.id2path("e") is None
229
assert btree.path2id("grandparent/parent/file") is None
259
self.assertTrue(btree.id2path("e") is None)
260
self.assertTrue(btree.path2id("grandparent/parent/file") is None)
230
261
btree.note_id("e", "grandparent/parent/file")
415
447
def get_invalid_bundle(self, base_rev_id, rev_id):
416
448
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
417
449
Munge the text so that it's invalid.
419
451
:return: The in-memory bundle
421
453
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
422
new_text = bundle_txt.getvalue().replace('executable:no',
454
new_text = bundle_txt.getvalue().replace('executable:no',
423
455
'executable:yes')
424
456
bundle_txt = StringIO(new_text)
425
457
bundle = read_bundle(bundle_txt)
426
458
self.valid_apply_bundle(base_rev_id, bundle)
429
461
def test_non_bundle(self):
430
self.assertRaises(NotABundle, read_bundle, StringIO('#!/bin/sh\n'))
462
self.assertRaises(errors.NotABundle,
463
read_bundle, StringIO('#!/bin/sh\n'))
432
465
def test_malformed(self):
433
self.assertRaises(BadBundle, read_bundle,
466
self.assertRaises(errors.BadBundle, read_bundle,
434
467
StringIO('# Bazaar revision bundle v'))
436
469
def test_crlf_bundle(self):
438
471
read_bundle(StringIO('# Bazaar revision bundle v0.8\r\n'))
472
except errors.BadBundle:
440
473
# It is currently permitted for bundles with crlf line endings to
441
474
# make read_bundle raise a BadBundle, but this should be fixed.
442
475
# Anything else, especially NotABundle, is an error.
456
489
ancestors = write_bundle(self.b1.repository, rev_id, 'null:', s,
457
490
format=self.format)
459
assert isinstance(s.getvalue(), str), (
460
"Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
492
self.assertIsInstance(s.getvalue(), str)
461
493
install_bundle(tree.branch.repository, read_bundle(s))
462
494
for ancestor in ancestors:
463
495
old = self.b1.repository.revision_tree(ancestor)
464
496
new = tree.branch.repository.revision_tree(ancestor)
466
# Check that there aren't any inventory level changes
467
delta = new.changes_from(old)
468
self.assertFalse(delta.has_changed(),
469
'Revision %s not copied correctly.'
472
# Now check that the file contents are all correct
473
for inventory_id in old:
475
old_file = old.get_file(inventory_id)
480
self.assertEqual(old_file.read(),
481
new.get_file(inventory_id).read())
500
# Check that there aren't any inventory level changes
501
delta = new.changes_from(old)
502
self.assertFalse(delta.has_changed(),
503
'Revision %s not copied correctly.'
506
# Now check that the file contents are all correct
507
for inventory_id in old.all_file_ids():
509
old_file = old.get_file(inventory_id)
510
except errors.NoSuchFile:
514
self.assertEqual(old_file.read(),
515
new.get_file(inventory_id).read())
482
519
if not _mod_revision.is_null(rev_id):
483
rh = self.b1.revision_history()
484
tree.branch.set_revision_history(rh[:rh.index(rev_id)+1])
520
tree.branch.generate_revision_history(rev_id)
486
522
delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
487
523
self.assertFalse(delta.has_changed(),
642
688
bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
644
def test_symlink_bundle(self):
645
if not has_symlinks():
646
raise TestSkipped("No symlink support")
690
def _test_symlink_bundle(self, link_name, link_target, new_link_target):
693
self.requireFeature(features.SymlinkFeature)
647
694
self.tree1 = self.make_branch_and_tree('b1')
648
695
self.b1 = self.tree1.branch
649
697
tt = TreeTransform(self.tree1)
650
tt.new_symlink('link', tt.root, 'bar/foo', 'link-1')
698
tt.new_symlink(link_name, tt.root, link_target, link_id)
652
700
self.tree1.commit('add symlink', rev_id='l@cset-0-1')
653
self.get_valid_bundle('null:', 'l@cset-0-1')
701
bundle = self.get_valid_bundle('null:', 'l@cset-0-1')
702
if getattr(bundle ,'revision_tree', None) is not None:
703
# Not all bundle formats supports revision_tree
704
bund_tree = bundle.revision_tree(self.b1.repository, 'l@cset-0-1')
705
self.assertEqual(link_target, bund_tree.get_symlink_target(link_id))
654
707
tt = TreeTransform(self.tree1)
655
trans_id = tt.trans_id_tree_file_id('link-1')
708
trans_id = tt.trans_id_tree_file_id(link_id)
656
709
tt.adjust_path('link2', tt.root, trans_id)
657
710
tt.delete_contents(trans_id)
658
tt.create_symlink('mars', trans_id)
711
tt.create_symlink(new_link_target, trans_id)
660
713
self.tree1.commit('rename and change symlink', rev_id='l@cset-0-2')
661
self.get_valid_bundle('l@cset-0-1', 'l@cset-0-2')
714
bundle = self.get_valid_bundle('l@cset-0-1', 'l@cset-0-2')
715
if getattr(bundle ,'revision_tree', None) is not None:
716
# Not all bundle formats supports revision_tree
717
bund_tree = bundle.revision_tree(self.b1.repository, 'l@cset-0-2')
718
self.assertEqual(new_link_target,
719
bund_tree.get_symlink_target(link_id))
662
721
tt = TreeTransform(self.tree1)
663
trans_id = tt.trans_id_tree_file_id('link-1')
722
trans_id = tt.trans_id_tree_file_id(link_id)
664
723
tt.delete_contents(trans_id)
665
724
tt.create_symlink('jupiter', trans_id)
667
726
self.tree1.commit('just change symlink target', rev_id='l@cset-0-3')
668
self.get_valid_bundle('l@cset-0-2', 'l@cset-0-3')
727
bundle = self.get_valid_bundle('l@cset-0-2', 'l@cset-0-3')
669
729
tt = TreeTransform(self.tree1)
670
trans_id = tt.trans_id_tree_file_id('link-1')
730
trans_id = tt.trans_id_tree_file_id(link_id)
671
731
tt.delete_contents(trans_id)
673
733
self.tree1.commit('Delete symlink', rev_id='l@cset-0-4')
674
self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
734
bundle = self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
736
def test_symlink_bundle(self):
737
self._test_symlink_bundle('link', 'bar/foo', 'mars')
739
def test_unicode_symlink_bundle(self):
740
self.requireFeature(features.UnicodeFilenameFeature)
741
self._test_symlink_bundle(u'\N{Euro Sign}link',
742
u'bar/\N{Euro Sign}foo',
743
u'mars\N{Euro Sign}')
676
745
def test_binary_bundle(self):
677
746
self.tree1 = self.make_branch_and_tree('b1')
678
747
self.b1 = self.tree1.branch
679
748
tt = TreeTransform(self.tree1)
682
751
tt.new_file('file', tt.root, '\x00\n\x00\r\x01\n\x02\r\xff', 'binary-1')
683
752
tt.new_file('file2', tt.root, '\x01\n\x02\r\x03\n\x04\r\xff',
790
857
u'William Dod\xe9\n').encode('utf-8'))
793
self.tree1.add([u'with Dod\xe9'], ['withdod-id'])
860
self.tree1.add([u'with Dod\N{Euro Sign}'], ['withdod-id'])
794
861
self.tree1.commit(u'i18n commit from William Dod\xe9',
795
862
rev_id='i18n-1', committer=u'William Dod\xe9')
797
if sys.platform == 'darwin':
798
# On Mac the '\xe9' gets changed to 'e\u0301'
799
self.assertEqual([u'.bzr', u'with Dode\u0301'],
800
sorted(os.listdir(u'b1')))
801
delta = self.tree1.changes_from(self.tree1.basis_tree())
802
self.assertEqual([(u'with Dod\xe9', 'withdod-id', 'file')],
804
self.knownFailure("Mac OSX doesn't preserve unicode"
805
" combining characters.")
808
865
bundle = self.get_valid_bundle('null:', 'i18n-1')
811
f = open(u'b1/with Dod\xe9', 'wb')
868
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
812
869
f.write(u'Modified \xb5\n'.encode('utf8'))
814
871
self.tree1.commit(u'modified', rev_id='i18n-2')
816
873
bundle = self.get_valid_bundle('i18n-1', 'i18n-2')
819
self.tree1.rename_one(u'with Dod\xe9', u'B\xe5gfors')
876
self.tree1.rename_one(u'with Dod\N{Euro Sign}', u'B\N{Euro Sign}gfors')
820
877
self.tree1.commit(u'renamed, the new i18n man', rev_id='i18n-3',
821
878
committer=u'Erik B\xe5gfors')
823
880
bundle = self.get_valid_bundle('i18n-2', 'i18n-3')
826
self.tree1.remove([u'B\xe5gfors'])
883
self.tree1.remove([u'B\N{Euro Sign}gfors'])
827
884
self.tree1.commit(u'removed', rev_id='i18n-4')
829
886
bundle = self.get_valid_bundle('i18n-3', 'i18n-4')
993
1051
bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
994
1052
repo = self.make_repository('repo', format='dirstate-with-subtree')
995
1053
bundle.install_revisions(repo)
996
inv_text = repo.get_inventory_xml('rev2')
1054
inv_text = repo._get_inventory_xml('rev2')
997
1055
self.assertNotContainsRe(inv_text, 'format="5"')
998
1056
self.assertContainsRe(inv_text, 'format="7"')
1058
def make_repo_with_installed_revisions(self):
1059
tree = self.make_simple_tree('knit')
1060
tree.commit('hello', rev_id='rev1')
1061
tree.commit('hello', rev_id='rev2')
1062
bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
1063
repo = self.make_repository('repo', format='dirstate-with-subtree')
1064
bundle.install_revisions(repo)
1000
1067
def test_across_models(self):
1001
tree = self.make_simple_tree('knit')
1002
tree.commit('hello', rev_id='rev1')
1003
tree.commit('hello', rev_id='rev2')
1004
bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
1005
repo = self.make_repository('repo', format='dirstate-with-subtree')
1006
bundle.install_revisions(repo)
1068
repo = self.make_repo_with_installed_revisions()
1007
1069
inv = repo.get_inventory('rev2')
1008
1070
self.assertEqual('rev2', inv.root.revision)
1009
root_vf = repo.weave_store.get_weave(inv.root.file_id,
1010
repo.get_transaction())
1011
self.assertEqual(root_vf.versions(), ['rev1', 'rev2'])
1071
root_id = inv.root.file_id
1073
self.addCleanup(repo.unlock)
1074
self.assertEqual({(root_id, 'rev1'):(),
1075
(root_id, 'rev2'):((root_id, 'rev1'),)},
1076
repo.texts.get_parent_map([(root_id, 'rev1'), (root_id, 'rev2')]))
1078
def test_inv_hash_across_serializers(self):
1079
repo = self.make_repo_with_installed_revisions()
1080
recorded_inv_sha1 = repo.get_revision('rev2').inventory_sha1
1081
xml = repo._get_inventory_xml('rev2')
1082
self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
1013
1084
def test_across_models_incompatible(self):
1014
1085
tree = self.make_simple_tree('dirstate-with-subtree')
1318
1389
tree2 = self.make_branch_and_tree('target')
1319
1390
target_repo = tree2.branch.repository
1320
1391
install_bundle(target_repo, serializer.read(s))
1321
vf = target_repo.weave_store.get_weave('fileid-2',
1322
target_repo.get_transaction())
1323
self.assertEqual('contents1\nstatic\n', vf.get_text('rev1'))
1324
self.assertEqual('contents2\nstatic\n', vf.get_text('rev2'))
1392
target_repo.lock_read()
1393
self.addCleanup(target_repo.unlock)
1394
# Turn the 'iterators_of_bytes' back into simple strings for comparison
1395
repo_texts = dict((i, ''.join(content)) for i, content
1396
in target_repo.iter_files_bytes(
1397
[('fileid-2', 'rev1', '1'),
1398
('fileid-2', 'rev2', '2')]))
1399
self.assertEqual({'1':'contents1\nstatic\n',
1400
'2':'contents2\nstatic\n'},
1325
1402
rtree = target_repo.revision_tree('rev2')
1326
inventory_vf = target_repo.get_inventory_weave()
1327
self.assertEqual(['rev1'], inventory_vf.get_parents('rev2'))
1403
inventory_vf = target_repo.inventories
1404
# If the inventory store has a graph, it must match the revision graph.
1406
[inventory_vf.get_parent_map([('rev2',)])[('rev2',)]],
1407
[None, (('rev1',),)])
1328
1408
self.assertEqual('changed file',
1329
1409
target_repo.get_revision('rev2').message)
1374
1454
install_bundle(repo_b, serializer.read(s))
1377
class V4WeaveBundleTester(V4BundleTester):
1457
class V4_2aBundleTester(V4BundleTester):
1379
1459
def bzrdir_format(self):
1462
def get_invalid_bundle(self, base_rev_id, rev_id):
1463
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1464
Munge the text so that it's invalid.
1466
:return: The in-memory bundle
1468
from bzrlib.bundle import serializer
1469
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1470
new_text = self.get_raw(StringIO(''.join(bundle_txt)))
1471
# We are going to be replacing some text to set the executable bit on a
1472
# file. Make sure the text replacement actually works correctly.
1473
self.assertContainsRe(new_text, '(?m)B244\n\ni 1\n<inventory')
1474
new_text = new_text.replace('<file file_id="exe-1"',
1475
'<file executable="y" file_id="exe-1"')
1476
new_text = new_text.replace('B244', 'B259')
1477
bundle_txt = StringIO()
1478
bundle_txt.write(serializer._get_bundle_header('4'))
1479
bundle_txt.write('\n')
1480
bundle_txt.write(new_text.encode('bz2'))
1482
bundle = read_bundle(bundle_txt)
1483
self.valid_apply_bundle(base_rev_id, bundle)
1486
def make_merged_branch(self):
1487
builder = self.make_branch_builder('source')
1488
builder.start_series()
1489
builder.build_snapshot('a@cset-0-1', None, [
1490
('add', ('', 'root-id', 'directory', None)),
1491
('add', ('file', 'file-id', 'file', 'original content\n')),
1493
builder.build_snapshot('a@cset-0-2a', ['a@cset-0-1'], [
1494
('modify', ('file-id', 'new-content\n')),
1496
builder.build_snapshot('a@cset-0-2b', ['a@cset-0-1'], [
1497
('add', ('other-file', 'file2-id', 'file', 'file2-content\n')),
1499
builder.build_snapshot('a@cset-0-3', ['a@cset-0-2a', 'a@cset-0-2b'], [
1500
('add', ('other-file', 'file2-id', 'file', 'file2-content\n')),
1502
builder.finish_series()
1503
self.b1 = builder.get_branch()
1505
self.addCleanup(self.b1.unlock)
1507
def make_bundle_just_inventories(self, base_revision_id,
1511
writer = v4.BundleWriteOperation(base_revision_id, target_revision_id,
1512
self.b1.repository, sio)
1513
writer.bundle.begin()
1514
writer._add_inventory_mpdiffs_from_serializer(revision_ids)
1519
def test_single_inventory_multiple_parents_as_xml(self):
1520
self.make_merged_branch()
1521
sio = self.make_bundle_just_inventories('a@cset-0-1', 'a@cset-0-3',
1523
reader = v4.BundleReader(sio, stream_input=False)
1524
records = list(reader.iter_records())
1525
self.assertEqual(1, len(records))
1526
(bytes, metadata, repo_kind, revision_id,
1527
file_id) = records[0]
1528
self.assertIs(None, file_id)
1529
self.assertEqual('a@cset-0-3', revision_id)
1530
self.assertEqual('inventory', repo_kind)
1531
self.assertEqual({'parents': ['a@cset-0-2a', 'a@cset-0-2b'],
1532
'sha1': '09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1533
'storage_kind': 'mpdiff',
1535
# We should have an mpdiff that takes some lines from both parents.
1536
self.assertEqualDiff(
1538
'<inventory format="10" revision_id="a@cset-0-3">\n'
1541
'c 1 3 3 2\n', bytes)
1543
def test_single_inv_no_parents_as_xml(self):
1544
self.make_merged_branch()
1545
sio = self.make_bundle_just_inventories('null:', 'a@cset-0-1',
1547
reader = v4.BundleReader(sio, stream_input=False)
1548
records = list(reader.iter_records())
1549
self.assertEqual(1, len(records))
1550
(bytes, metadata, repo_kind, revision_id,
1551
file_id) = records[0]
1552
self.assertIs(None, file_id)
1553
self.assertEqual('a@cset-0-1', revision_id)
1554
self.assertEqual('inventory', repo_kind)
1555
self.assertEqual({'parents': [],
1556
'sha1': 'a13f42b142d544aac9b085c42595d304150e31a2',
1557
'storage_kind': 'mpdiff',
1559
# We should have an mpdiff that takes some lines from both parents.
1560
self.assertEqualDiff(
1562
'<inventory format="10" revision_id="a@cset-0-1">\n'
1563
'<directory file_id="root-id" name=""'
1564
' revision="a@cset-0-1" />\n'
1565
'<file file_id="file-id" name="file" parent_id="root-id"'
1566
' revision="a@cset-0-1"'
1567
' text_sha1="09c2f8647e14e49e922b955c194102070597c2d1"'
1568
' text_size="17" />\n'
1572
def test_multiple_inventories_as_xml(self):
1573
self.make_merged_branch()
1574
sio = self.make_bundle_just_inventories('a@cset-0-1', 'a@cset-0-3',
1575
['a@cset-0-2a', 'a@cset-0-2b', 'a@cset-0-3'])
1576
reader = v4.BundleReader(sio, stream_input=False)
1577
records = list(reader.iter_records())
1578
self.assertEqual(3, len(records))
1579
revision_ids = [rev_id for b, m, k, rev_id, f in records]
1580
self.assertEqual(['a@cset-0-2a', 'a@cset-0-2b', 'a@cset-0-3'],
1582
metadata_2a = records[0][1]
1583
self.assertEqual({'parents': ['a@cset-0-1'],
1584
'sha1': '1e105886d62d510763e22885eec733b66f5f09bf',
1585
'storage_kind': 'mpdiff',
1587
metadata_2b = records[1][1]
1588
self.assertEqual({'parents': ['a@cset-0-1'],
1589
'sha1': 'f03f12574bdb5ed2204c28636c98a8547544ccd8',
1590
'storage_kind': 'mpdiff',
1592
metadata_3 = records[2][1]
1593
self.assertEqual({'parents': ['a@cset-0-2a', 'a@cset-0-2b'],
1594
'sha1': '09c53b0c4de0895e11a2aacc34fef60a6e70865c',
1595
'storage_kind': 'mpdiff',
1597
bytes_2a = records[0][0]
1598
self.assertEqualDiff(
1600
'<inventory format="10" revision_id="a@cset-0-2a">\n'
1604
'<file file_id="file-id" name="file" parent_id="root-id"'
1605
' revision="a@cset-0-2a"'
1606
' text_sha1="50f545ff40e57b6924b1f3174b267ffc4576e9a9"'
1607
' text_size="12" />\n'
1609
'c 0 3 3 1\n', bytes_2a)
1610
bytes_2b = records[1][0]
1611
self.assertEqualDiff(
1613
'<inventory format="10" revision_id="a@cset-0-2b">\n'
1617
'<file file_id="file2-id" name="other-file" parent_id="root-id"'
1618
' revision="a@cset-0-2b"'
1619
' text_sha1="b46c0c8ea1e5ef8e46fc8894bfd4752a88ec939e"'
1620
' text_size="14" />\n'
1622
'c 0 3 4 1\n', bytes_2b)
1623
bytes_3 = records[2][0]
1624
self.assertEqualDiff(
1626
'<inventory format="10" revision_id="a@cset-0-3">\n'
1629
'c 1 3 3 2\n', bytes_3)
1631
def test_creating_bundle_preserves_chk_pages(self):
1632
self.make_merged_branch()
1633
target = self.b1.bzrdir.sprout('target',
1634
revision_id='a@cset-0-2a').open_branch()
1635
bundle_txt, rev_ids = self.create_bundle_text('a@cset-0-2a',
1637
self.assertEqual(['a@cset-0-2b', 'a@cset-0-3'], rev_ids)
1638
bundle = read_bundle(bundle_txt)
1640
self.addCleanup(target.unlock)
1641
install_bundle(target.repository, bundle)
1642
inv1 = self.b1.repository.inventories.get_record_stream([
1643
('a@cset-0-3',)], 'unordered',
1644
True).next().get_bytes_as('fulltext')
1645
inv2 = target.repository.inventories.get_record_stream([
1646
('a@cset-0-3',)], 'unordered',
1647
True).next().get_bytes_as('fulltext')
1648
self.assertEqualDiff(inv1, inv2)
1383
1651
class MungedBundleTester(object):
1543
1811
record = record_iter.next()
1544
1812
self.assertEqual((None, {'foo': 'bar', 'storage_kind': 'header'},
1545
1813
'info', None, None), record)
1546
self.assertRaises(BadBundle, record_iter.next)
1814
self.assertRaises(errors.BadBundle, record_iter.next)
1817
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
1819
def test_read_mergeable_skips_local(self):
1820
"""A local bundle named like the URL should not be read.
1822
out, wt = test_read_bundle.create_bundle_file(self)
1823
class FooService(object):
1824
"""A directory service that always returns source"""
1826
def look_up(self, name, url):
1828
directories.register('foo:', FooService, 'Testing directory service')
1829
self.addCleanup(directories.remove, 'foo:')
1830
self.build_tree_contents([('./foo:bar', out.getvalue())])
1831
self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1834
def test_infinite_redirects_are_not_a_bundle(self):
1835
"""If a URL causes TooManyRedirections then NotABundle is raised.
1837
from bzrlib.tests.blackbox.test_push import RedirectingMemoryServer
1838
server = RedirectingMemoryServer()
1839
self.start_server(server)
1840
url = server.get_url() + 'infinite-loop'
1841
self.assertRaises(errors.NotABundle, read_mergeable_from_url, url)
1843
def test_smart_server_connection_reset(self):
1844
"""If a smart server connection fails during the attempt to read a
1845
bundle, then the ConnectionReset error should be propagated.
1847
# Instantiate a server that will provoke a ConnectionReset
1848
sock_server = DisconnectingServer()
1849
self.start_server(sock_server)
1850
# We don't really care what the url is since the server will close the
1851
# connection without interpreting it
1852
url = sock_server.get_url()
1853
self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1856
class DisconnectingHandler(SocketServer.BaseRequestHandler):
1857
"""A request handler that immediately closes any connection made to it."""
1860
self.request.close()
1863
class DisconnectingServer(test_server.TestingTCPServerInAThread):
1866
super(DisconnectingServer, self).__init__(
1868
test_server.TestingTCPServer,
1869
DisconnectingHandler)
1872
"""Return the url of the server"""
1873
return "bzr://%s:%d/" % self.server.server_address