301
290
def test_iteration(self):
302
291
"""Ensure that iteration through ids works properly"""
303
292
btree = self.make_tree_1()[0]
304
self.assertEqual(self.sorted_ids(btree),
305
[inventory.ROOT_ID, 'a', 'b', 'c', 'd'])
293
self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'c', 'd'])
306
294
btree.note_deletion("grandparent/parent/file")
307
295
btree.note_id("e", "grandparent/alt_parent/fool", kind="directory")
308
296
btree.note_last_changed("grandparent/alt_parent/fool",
309
297
"revisionidiguess")
310
self.assertEqual(self.sorted_ids(btree),
311
[inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
314
class BundleTester1(TestCaseWithTransport):
316
def test_mismatched_bundle(self):
317
format = bzrdir.BzrDirMetaFormat1()
318
format.repository_format = knitrepo.RepositoryFormatKnit3()
319
serializer = BundleSerializerV08('0.8')
320
b = self.make_branch('.', format=format)
321
self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
322
b.repository, [], {}, StringIO())
324
def test_matched_bundle(self):
325
"""Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
326
format = bzrdir.BzrDirMetaFormat1()
327
format.repository_format = knitrepo.RepositoryFormatKnit3()
328
serializer = BundleSerializerV09('0.9')
329
b = self.make_branch('.', format=format)
330
serializer.write(b.repository, [], {}, StringIO())
332
def test_mismatched_model(self):
333
"""Try copying a bundle from knit2 to knit1"""
334
format = bzrdir.BzrDirMetaFormat1()
335
format.repository_format = knitrepo.RepositoryFormatKnit3()
336
source = self.make_branch_and_tree('source', format=format)
337
source.commit('one', rev_id='one-id')
338
source.commit('two', rev_id='two-id')
340
write_bundle(source.branch.repository, 'two-id', 'null:', text,
344
format = bzrdir.BzrDirMetaFormat1()
345
format.repository_format = knitrepo.RepositoryFormatKnit1()
346
target = self.make_branch('target', format=format)
347
self.assertRaises(errors.IncompatibleRevision, install_bundle,
348
target.repository, read_bundle(text))
351
class V08BundleTester(TestCaseWithTransport):
355
def bzrdir_format(self):
356
format = bzrdir.BzrDirMetaFormat1()
357
format.repository_format = knitrepo.RepositoryFormatKnit1()
360
def make_branch_and_tree(self, path, format=None):
362
format = self.bzrdir_format()
363
return TestCaseWithTransport.make_branch_and_tree(self, path, format)
365
def make_branch(self, path, format=None):
367
format = self.bzrdir_format()
368
return TestCaseWithTransport.make_branch(self, path, format)
298
self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'd', 'e'])
301
class BundleTester(TestCaseWithTransport):
370
303
def create_bundle_text(self, base_rev_id, rev_id):
371
304
bundle_txt = StringIO()
372
305
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
373
bundle_txt, format=self.format)
374
307
bundle_txt.seek(0)
375
308
self.assertEqual(bundle_txt.readline(),
376
'# Bazaar revision bundle v%s\n' % self.format)
309
'# Bazaar revision bundle v0.8\n')
377
310
self.assertEqual(bundle_txt.readline(), '#\n')
379
312
rev = self.b1.repository.get_revision(rev_id)
681
607
self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
683
609
def test_binary_bundle(self):
684
self.tree1 = self.make_branch_and_tree('b1')
610
self.tree1 = BzrDir.create_standalone_workingtree('b1')
685
611
self.b1 = self.tree1.branch
686
612
tt = TreeTransform(self.tree1)
689
tt.new_file('file', tt.root, '\x00\n\x00\r\x01\n\x02\r\xff', 'binary-1')
690
tt.new_file('file2', tt.root, '\x01\n\x02\r\x03\n\x04\r\xff', 'binary-2')
613
tt.new_file('file', tt.root, '\x00\xff', 'binary-1')
614
tt.new_file('file2', tt.root, '\x00\xff', 'binary-2')
692
616
self.tree1.commit('add binary', rev_id='b@cset-0-1')
693
self.get_valid_bundle('null:', 'b@cset-0-1')
617
self.get_valid_bundle(None, 'b@cset-0-1')
696
618
tt = TreeTransform(self.tree1)
697
619
trans_id = tt.trans_id_tree_file_id('binary-1')
698
620
tt.delete_contents(trans_id)
700
622
self.tree1.commit('delete binary', rev_id='b@cset-0-2')
701
623
self.get_valid_bundle('b@cset-0-1', 'b@cset-0-2')
704
624
tt = TreeTransform(self.tree1)
705
625
trans_id = tt.trans_id_tree_file_id('binary-2')
706
626
tt.adjust_path('file3', tt.root, trans_id)
707
627
tt.delete_contents(trans_id)
708
tt.create_file('file\rcontents\x00\n\x00', trans_id)
628
tt.create_file('filecontents\x00', trans_id)
710
630
self.tree1.commit('rename and modify binary', rev_id='b@cset-0-3')
711
631
self.get_valid_bundle('b@cset-0-2', 'b@cset-0-3')
714
632
tt = TreeTransform(self.tree1)
715
633
trans_id = tt.trans_id_tree_file_id('binary-2')
716
634
tt.delete_contents(trans_id)
717
tt.create_file('\x00file\rcontents', trans_id)
635
tt.create_file('\x00filecontents', trans_id)
719
637
self.tree1.commit('just modify binary', rev_id='b@cset-0-4')
720
638
self.get_valid_bundle('b@cset-0-3', 'b@cset-0-4')
723
self.get_valid_bundle('null:', 'b@cset-0-4')
725
640
def test_last_modified(self):
726
self.tree1 = self.make_branch_and_tree('b1')
641
self.tree1 = BzrDir.create_standalone_workingtree('b1')
727
642
self.b1 = self.tree1.branch
728
643
tt = TreeTransform(self.tree1)
729
644
tt.new_file('file', tt.root, 'file', 'file')
863
767
bundle = self.get_valid_bundle('white-3', 'white-4')
865
769
# Now test a complet roll-up
866
bundle = self.get_valid_bundle('null:', 'white-4')
868
def test_alt_timezone_bundle(self):
869
self.tree1 = self.make_branch_and_memory_tree('b1')
870
self.b1 = self.tree1.branch
871
builder = treebuilder.TreeBuilder()
873
self.tree1.lock_write()
874
builder.start_tree(self.tree1)
875
builder.build(['newfile'])
876
builder.finish_tree()
878
# Asia/Colombo offset = 5 hours 30 minutes
879
self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
880
timezone=19800, timestamp=1152544886.0)
882
bundle = self.get_valid_bundle('null:', 'tz-1')
884
rev = bundle.revisions[0]
885
self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
886
self.assertEqual(19800, rev.timezone)
887
self.assertEqual(1152544886.0, rev.timestamp)
890
def test_bundle_root_id(self):
891
self.tree1 = self.make_branch_and_tree('b1')
892
self.b1 = self.tree1.branch
893
self.tree1.commit('message', rev_id='revid1')
894
bundle = self.get_valid_bundle('null:', 'revid1')
895
tree = bundle.revision_tree(self.b1.repository, 'revid1')
896
self.assertEqual('revid1', tree.inventory.root.revision)
898
def test_install_revisions(self):
899
self.tree1 = self.make_branch_and_tree('b1')
900
self.b1 = self.tree1.branch
901
self.tree1.commit('message', rev_id='rev2a')
902
bundle = self.get_valid_bundle('null:', 'rev2a')
903
branch2 = self.make_branch('b2')
904
self.assertFalse(branch2.repository.has_revision('rev2a'))
905
target_revision = bundle.install_revisions(branch2.repository)
906
self.assertTrue(branch2.repository.has_revision('rev2a'))
907
self.assertEqual('rev2a', target_revision)
909
def test_bundle_empty_property(self):
910
"""Test serializing revision properties with an empty value."""
911
tree = self.make_branch_and_memory_tree('tree')
913
self.addCleanup(tree.unlock)
914
tree.add([''], ['TREE_ROOT'])
915
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
916
self.b1 = tree.branch
917
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
918
self.assertContainsRe(bundle_sio.getvalue(),
920
'# branch-nick: tree\n'
924
bundle = read_bundle(bundle_sio)
925
revision_info = bundle.revisions[0]
926
self.assertEqual('rev1', revision_info.revision_id)
927
rev = revision_info.as_revision()
928
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
931
def test_bundle_empty_property_alt(self):
932
"""Test serializing revision properties with an empty value.
934
Older readers had a bug when reading an empty property.
935
They assumed that all keys ended in ': \n'. However they would write an
936
empty value as ':\n'. This tests make sure that all newer bzr versions
937
can handle th second form.
939
tree = self.make_branch_and_memory_tree('tree')
941
self.addCleanup(tree.unlock)
942
tree.add([''], ['TREE_ROOT'])
943
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
944
self.b1 = tree.branch
945
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
946
txt = bundle_sio.getvalue()
947
loc = txt.find('# empty: ') + len('# empty:')
948
# Create a new bundle, which strips the trailing space after empty
949
bundle_sio = StringIO(txt[:loc] + txt[loc+1:])
951
self.assertContainsRe(bundle_sio.getvalue(),
953
'# branch-nick: tree\n'
957
bundle = read_bundle(bundle_sio)
958
revision_info = bundle.revisions[0]
959
self.assertEqual('rev1', revision_info.revision_id)
960
rev = revision_info.as_revision()
961
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
964
def test_bundle_sorted_properties(self):
965
"""For stability the writer should write properties in sorted order."""
966
tree = self.make_branch_and_memory_tree('tree')
968
self.addCleanup(tree.unlock)
970
tree.add([''], ['TREE_ROOT'])
971
tree.commit('One', rev_id='rev1',
972
revprops={'a':'4', 'b':'3', 'c':'2', 'd':'1'})
973
self.b1 = tree.branch
974
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
975
self.assertContainsRe(bundle_sio.getvalue(),
979
'# branch-nick: tree\n'
983
bundle = read_bundle(bundle_sio)
984
revision_info = bundle.revisions[0]
985
self.assertEqual('rev1', revision_info.revision_id)
986
rev = revision_info.as_revision()
987
self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
988
'd':'1'}, rev.properties)
990
def test_bundle_unicode_properties(self):
991
"""We should be able to round trip a non-ascii property."""
992
tree = self.make_branch_and_memory_tree('tree')
994
self.addCleanup(tree.unlock)
996
tree.add([''], ['TREE_ROOT'])
997
# Revisions themselves do not require anything about revision property
998
# keys, other than that they are a basestring, and do not contain
1000
# However, Testaments assert than they are str(), and thus should not
1002
tree.commit('One', rev_id='rev1',
1003
revprops={'omega':u'\u03a9', 'alpha':u'\u03b1'})
1004
self.b1 = tree.branch
1005
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1006
self.assertContainsRe(bundle_sio.getvalue(),
1008
'# alpha: \xce\xb1\n'
1009
'# branch-nick: tree\n'
1010
'# omega: \xce\xa9\n'
1012
bundle = read_bundle(bundle_sio)
1013
revision_info = bundle.revisions[0]
1014
self.assertEqual('rev1', revision_info.revision_id)
1015
rev = revision_info.as_revision()
1016
self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1017
'alpha':u'\u03b1'}, rev.properties)
1020
class V09BundleKnit2Tester(V08BundleTester):
1024
def bzrdir_format(self):
1025
format = bzrdir.BzrDirMetaFormat1()
1026
format.repository_format = knitrepo.RepositoryFormatKnit3()
1030
class V09BundleKnit1Tester(V08BundleTester):
1034
def bzrdir_format(self):
1035
format = bzrdir.BzrDirMetaFormat1()
1036
format.repository_format = knitrepo.RepositoryFormatKnit1()
770
bundle = self.get_valid_bundle(None, 'white-4')
1040
773
class MungedBundleTester(TestCaseWithTransport):