779
868
bundle = self.get_valid_bundle('white-3', 'white-4')
781
870
# Now test a complet roll-up
782
bundle = self.get_valid_bundle(None, 'white-4')
871
bundle = self.get_valid_bundle('null:', 'white-4')
784
873
def test_alt_timezone_bundle(self):
785
self.tree1 = self.make_branch_and_tree('b1')
874
self.tree1 = self.make_branch_and_memory_tree('b1')
786
875
self.b1 = self.tree1.branch
876
builder = treebuilder.TreeBuilder()
788
self.build_tree(['b1/newfile'])
789
self.tree1.add(['newfile'])
878
self.tree1.lock_write()
879
builder.start_tree(self.tree1)
880
builder.build(['newfile'])
881
builder.finish_tree()
791
883
# Asia/Colombo offset = 5 hours 30 minutes
792
884
self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
793
885
timezone=19800, timestamp=1152544886.0)
795
bundle = self.get_valid_bundle(None, 'tz-1')
887
bundle = self.get_valid_bundle('null:', 'tz-1')
797
889
rev = bundle.revisions[0]
798
890
self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
799
891
self.assertEqual(19800, rev.timezone)
800
892
self.assertEqual(1152544886.0, rev.timestamp)
803
class MungedBundleTester(TestCaseWithTransport):
895
def test_bundle_root_id(self):
896
self.tree1 = self.make_branch_and_tree('b1')
897
self.b1 = self.tree1.branch
898
self.tree1.commit('message', rev_id='revid1')
899
bundle = self.get_valid_bundle('null:', 'revid1')
900
tree = self.get_bundle_tree(bundle, 'revid1')
901
self.assertEqual('revid1', tree.inventory.root.revision)
903
def test_install_revisions(self):
904
self.tree1 = self.make_branch_and_tree('b1')
905
self.b1 = self.tree1.branch
906
self.tree1.commit('message', rev_id='rev2a')
907
bundle = self.get_valid_bundle('null:', 'rev2a')
908
branch2 = self.make_branch('b2')
909
self.assertFalse(branch2.repository.has_revision('rev2a'))
910
target_revision = bundle.install_revisions(branch2.repository)
911
self.assertTrue(branch2.repository.has_revision('rev2a'))
912
self.assertEqual('rev2a', target_revision)
914
def test_bundle_empty_property(self):
915
"""Test serializing revision properties with an empty value."""
916
tree = self.make_branch_and_memory_tree('tree')
918
self.addCleanup(tree.unlock)
919
tree.add([''], ['TREE_ROOT'])
920
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
921
self.b1 = tree.branch
922
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
923
bundle = read_bundle(bundle_sio)
924
revision_info = bundle.revisions[0]
925
self.assertEqual('rev1', revision_info.revision_id)
926
rev = revision_info.as_revision()
927
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
930
def test_bundle_sorted_properties(self):
931
"""For stability the writer should write properties in sorted order."""
932
tree = self.make_branch_and_memory_tree('tree')
934
self.addCleanup(tree.unlock)
936
tree.add([''], ['TREE_ROOT'])
937
tree.commit('One', rev_id='rev1',
938
revprops={'a':'4', 'b':'3', 'c':'2', 'd':'1'})
939
self.b1 = tree.branch
940
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
941
bundle = read_bundle(bundle_sio)
942
revision_info = bundle.revisions[0]
943
self.assertEqual('rev1', revision_info.revision_id)
944
rev = revision_info.as_revision()
945
self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
946
'd':'1'}, rev.properties)
948
def test_bundle_unicode_properties(self):
949
"""We should be able to round trip a non-ascii property."""
950
tree = self.make_branch_and_memory_tree('tree')
952
self.addCleanup(tree.unlock)
954
tree.add([''], ['TREE_ROOT'])
955
# Revisions themselves do not require anything about revision property
956
# keys, other than that they are a basestring, and do not contain
958
# However, Testaments assert than they are str(), and thus should not
960
tree.commit('One', rev_id='rev1',
961
revprops={'omega':u'\u03a9', 'alpha':u'\u03b1'})
962
self.b1 = tree.branch
963
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
964
bundle = read_bundle(bundle_sio)
965
revision_info = bundle.revisions[0]
966
self.assertEqual('rev1', revision_info.revision_id)
967
rev = revision_info.as_revision()
968
self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
969
'alpha':u'\u03b1'}, rev.properties)
971
def test_bundle_with_ghosts(self):
972
tree = self.make_branch_and_tree('tree')
973
self.b1 = tree.branch
974
self.build_tree_contents([('tree/file', 'content1')])
977
self.build_tree_contents([('tree/file', 'content2')])
978
tree.add_parent_tree_id('ghost')
979
tree.commit('rev2', rev_id='rev2')
980
bundle = self.get_valid_bundle('null:', 'rev2')
982
def make_simple_tree(self, format=None):
983
tree = self.make_branch_and_tree('b1', format=format)
984
self.b1 = tree.branch
985
self.build_tree(['b1/file'])
989
def test_across_serializers(self):
990
tree = self.make_simple_tree('knit')
991
tree.commit('hello', rev_id='rev1')
992
tree.commit('hello', rev_id='rev2')
993
bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
994
repo = self.make_repository('repo', format='dirstate-with-subtree')
995
bundle.install_revisions(repo)
996
inv_text = repo.get_inventory_xml('rev2')
997
self.assertNotContainsRe(inv_text, 'format="5"')
998
self.assertContainsRe(inv_text, 'format="7"')
1000
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)
1007
inv = repo.get_inventory('rev2')
1008
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'])
1013
def test_across_models_incompatible(self):
1014
tree = self.make_simple_tree('dirstate-with-subtree')
1015
tree.commit('hello', rev_id='rev1')
1016
tree.commit('hello', rev_id='rev2')
1018
bundle = read_bundle(self.create_bundle_text('null:', 'rev1')[0])
1019
except errors.IncompatibleBundleFormat:
1020
raise TestSkipped("Format 0.8 doesn't work with knit3")
1021
repo = self.make_repository('repo', format='knit')
1022
bundle.install_revisions(repo)
1024
bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
1025
self.assertRaises(errors.IncompatibleRevision,
1026
bundle.install_revisions, repo)
1028
def test_get_merge_request(self):
1029
tree = self.make_simple_tree()
1030
tree.commit('hello', rev_id='rev1')
1031
tree.commit('hello', rev_id='rev2')
1032
bundle = read_bundle(self.create_bundle_text('null:', 'rev1')[0])
1033
result = bundle.get_merge_request(tree.branch.repository)
1034
self.assertEqual((None, 'rev1', 'inapplicable'), result)
1036
def test_with_subtree(self):
1037
tree = self.make_branch_and_tree('tree',
1038
format='dirstate-with-subtree')
1039
self.b1 = tree.branch
1040
subtree = self.make_branch_and_tree('tree/subtree',
1041
format='dirstate-with-subtree')
1043
tree.commit('hello', rev_id='rev1')
1045
bundle = read_bundle(self.create_bundle_text('null:', 'rev1')[0])
1046
except errors.IncompatibleBundleFormat:
1047
raise TestSkipped("Format 0.8 doesn't work with knit3")
1048
if isinstance(bundle, v09.BundleInfo09):
1049
raise TestSkipped("Format 0.9 doesn't work with subtrees")
1050
repo = self.make_repository('repo', format='knit')
1051
self.assertRaises(errors.IncompatibleRevision,
1052
bundle.install_revisions, repo)
1053
repo2 = self.make_repository('repo2', format='dirstate-with-subtree')
1054
bundle.install_revisions(repo2)
1056
def test_revision_id_with_slash(self):
1057
self.tree1 = self.make_branch_and_tree('tree')
1058
self.b1 = self.tree1.branch
1060
self.tree1.commit('Revision/id/with/slashes', rev_id='rev/id')
1062
raise TestSkipped("Repository doesn't support revision ids with"
1064
bundle = self.get_valid_bundle('null:', 'rev/id')
1067
class V08BundleTester(BundleTester, TestCaseWithTransport):
1071
def test_bundle_empty_property(self):
1072
"""Test serializing revision properties with an empty value."""
1073
tree = self.make_branch_and_memory_tree('tree')
1075
self.addCleanup(tree.unlock)
1076
tree.add([''], ['TREE_ROOT'])
1077
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
1078
self.b1 = tree.branch
1079
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1080
self.assertContainsRe(bundle_sio.getvalue(),
1082
'# branch-nick: tree\n'
1086
bundle = read_bundle(bundle_sio)
1087
revision_info = bundle.revisions[0]
1088
self.assertEqual('rev1', revision_info.revision_id)
1089
rev = revision_info.as_revision()
1090
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
1093
def get_bundle_tree(self, bundle, revision_id):
1094
repository = self.make_repository('repo')
1095
return bundle.revision_tree(repository, 'revid1')
1097
def test_bundle_empty_property_alt(self):
1098
"""Test serializing revision properties with an empty value.
1100
Older readers had a bug when reading an empty property.
1101
They assumed that all keys ended in ': \n'. However they would write an
1102
empty value as ':\n'. This tests make sure that all newer bzr versions
1103
can handle th second form.
1105
tree = self.make_branch_and_memory_tree('tree')
1107
self.addCleanup(tree.unlock)
1108
tree.add([''], ['TREE_ROOT'])
1109
tree.commit('One', revprops={'one':'two', 'empty':''}, rev_id='rev1')
1110
self.b1 = tree.branch
1111
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1112
txt = bundle_sio.getvalue()
1113
loc = txt.find('# empty: ') + len('# empty:')
1114
# Create a new bundle, which strips the trailing space after empty
1115
bundle_sio = StringIO(txt[:loc] + txt[loc+1:])
1117
self.assertContainsRe(bundle_sio.getvalue(),
1119
'# branch-nick: tree\n'
1123
bundle = read_bundle(bundle_sio)
1124
revision_info = bundle.revisions[0]
1125
self.assertEqual('rev1', revision_info.revision_id)
1126
rev = revision_info.as_revision()
1127
self.assertEqual({'branch-nick':'tree', 'empty':'', 'one':'two'},
1130
def test_bundle_sorted_properties(self):
1131
"""For stability the writer should write properties in sorted order."""
1132
tree = self.make_branch_and_memory_tree('tree')
1134
self.addCleanup(tree.unlock)
1136
tree.add([''], ['TREE_ROOT'])
1137
tree.commit('One', rev_id='rev1',
1138
revprops={'a':'4', 'b':'3', 'c':'2', 'd':'1'})
1139
self.b1 = tree.branch
1140
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1141
self.assertContainsRe(bundle_sio.getvalue(),
1145
'# branch-nick: tree\n'
1149
bundle = read_bundle(bundle_sio)
1150
revision_info = bundle.revisions[0]
1151
self.assertEqual('rev1', revision_info.revision_id)
1152
rev = revision_info.as_revision()
1153
self.assertEqual({'branch-nick':'tree', 'a':'4', 'b':'3', 'c':'2',
1154
'd':'1'}, rev.properties)
1156
def test_bundle_unicode_properties(self):
1157
"""We should be able to round trip a non-ascii property."""
1158
tree = self.make_branch_and_memory_tree('tree')
1160
self.addCleanup(tree.unlock)
1162
tree.add([''], ['TREE_ROOT'])
1163
# Revisions themselves do not require anything about revision property
1164
# keys, other than that they are a basestring, and do not contain
1166
# However, Testaments assert than they are str(), and thus should not
1168
tree.commit('One', rev_id='rev1',
1169
revprops={'omega':u'\u03a9', 'alpha':u'\u03b1'})
1170
self.b1 = tree.branch
1171
bundle_sio, revision_ids = self.create_bundle_text('null:', 'rev1')
1172
self.assertContainsRe(bundle_sio.getvalue(),
1174
'# alpha: \xce\xb1\n'
1175
'# branch-nick: tree\n'
1176
'# omega: \xce\xa9\n'
1178
bundle = read_bundle(bundle_sio)
1179
revision_info = bundle.revisions[0]
1180
self.assertEqual('rev1', revision_info.revision_id)
1181
rev = revision_info.as_revision()
1182
self.assertEqual({'branch-nick':'tree', 'omega':u'\u03a9',
1183
'alpha':u'\u03b1'}, rev.properties)
1186
class V09BundleKnit2Tester(V08BundleTester):
1190
def bzrdir_format(self):
1191
format = bzrdir.BzrDirMetaFormat1()
1192
format.repository_format = knitrepo.RepositoryFormatKnit3()
1196
class V09BundleKnit1Tester(V08BundleTester):
1200
def bzrdir_format(self):
1201
format = bzrdir.BzrDirMetaFormat1()
1202
format.repository_format = knitrepo.RepositoryFormatKnit1()
1206
class V4BundleTester(BundleTester, TestCaseWithTransport):
1210
def get_valid_bundle(self, base_rev_id, rev_id, checkout_dir=None):
1211
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1212
Make sure that the text generated is valid, and that it
1213
can be applied against the base, and generate the same information.
1215
:return: The in-memory bundle
1217
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1219
# This should also validate the generated bundle
1220
bundle = read_bundle(bundle_txt)
1221
repository = self.b1.repository
1222
for bundle_rev in bundle.real_revisions:
1223
# These really should have already been checked when we read the
1224
# bundle, since it computes the sha1 hash for the revision, which
1225
# only will match if everything is okay, but lets be explicit about
1227
branch_rev = repository.get_revision(bundle_rev.revision_id)
1228
for a in ('inventory_sha1', 'revision_id', 'parent_ids',
1229
'timestamp', 'timezone', 'message', 'committer',
1230
'parent_ids', 'properties'):
1231
self.assertEqual(getattr(branch_rev, a),
1232
getattr(bundle_rev, a))
1233
self.assertEqual(len(branch_rev.parent_ids),
1234
len(bundle_rev.parent_ids))
1235
self.assertEqual(set(rev_ids),
1236
set([r.revision_id for r in bundle.real_revisions]))
1237
self.valid_apply_bundle(base_rev_id, bundle,
1238
checkout_dir=checkout_dir)
1242
def get_invalid_bundle(self, base_rev_id, rev_id):
1243
"""Create a bundle from base_rev_id -> rev_id in built-in branch.
1244
Munge the text so that it's invalid.
1246
:return: The in-memory bundle
1248
from bzrlib.bundle import serializer
1249
bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1250
new_text = self.get_raw(StringIO(''.join(bundle_txt)))
1251
new_text = new_text.replace('<file file_id="exe-1"',
1252
'<file executable="y" file_id="exe-1"')
1253
new_text = new_text.replace('B372', 'B387')
1254
bundle_txt = StringIO()
1255
bundle_txt.write(serializer._get_bundle_header('4'))
1256
bundle_txt.write('\n')
1257
bundle_txt.write(new_text.encode('bz2'))
1259
bundle = read_bundle(bundle_txt)
1260
self.valid_apply_bundle(base_rev_id, bundle)
1263
def create_bundle_text(self, base_rev_id, rev_id):
1264
bundle_txt = StringIO()
1265
rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
1266
bundle_txt, format=self.format)
1268
self.assertEqual(bundle_txt.readline(),
1269
'# Bazaar revision bundle v%s\n' % self.format)
1270
self.assertEqual(bundle_txt.readline(), '#\n')
1271
rev = self.b1.repository.get_revision(rev_id)
1273
return bundle_txt, rev_ids
1275
def get_bundle_tree(self, bundle, revision_id):
1276
repository = self.make_repository('repo')
1277
bundle.install_revisions(repository)
1278
return repository.revision_tree(revision_id)
1280
def test_creation(self):
1281
tree = self.make_branch_and_tree('tree')
1282
self.build_tree_contents([('tree/file', 'contents1\nstatic\n')])
1283
tree.add('file', 'fileid-2')
1284
tree.commit('added file', rev_id='rev1')
1285
self.build_tree_contents([('tree/file', 'contents2\nstatic\n')])
1286
tree.commit('changed file', rev_id='rev2')
1288
serializer = BundleSerializerV4('1.0')
1289
serializer.write(tree.branch.repository, ['rev1', 'rev2'], {}, s)
1291
tree2 = self.make_branch_and_tree('target')
1292
target_repo = tree2.branch.repository
1293
install_bundle(target_repo, serializer.read(s))
1294
vf = target_repo.weave_store.get_weave('fileid-2',
1295
target_repo.get_transaction())
1296
self.assertEqual('contents1\nstatic\n', vf.get_text('rev1'))
1297
self.assertEqual('contents2\nstatic\n', vf.get_text('rev2'))
1298
rtree = target_repo.revision_tree('rev2')
1299
inventory_vf = target_repo.get_inventory_weave()
1300
self.assertEqual(['rev1'], inventory_vf.get_parents('rev2'))
1301
self.assertEqual('changed file',
1302
target_repo.get_revision('rev2').message)
1305
def get_raw(bundle_file):
1307
line = bundle_file.readline()
1308
line = bundle_file.readline()
1309
lines = bundle_file.readlines()
1310
return ''.join(lines).decode('bz2')
1312
def test_copy_signatures(self):
1313
tree_a = self.make_branch_and_tree('tree_a')
1315
import bzrlib.commit as commit
1316
oldstrategy = bzrlib.gpg.GPGStrategy
1317
branch = tree_a.branch
1318
repo_a = branch.repository
1319
tree_a.commit("base", allow_pointless=True, rev_id='A')
1320
self.failIf(branch.repository.has_signature_for_revision_id('A'))
1322
from bzrlib.testament import Testament
1323
# monkey patch gpg signing mechanism
1324
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
1325
new_config = test_commit.MustSignConfig(branch)
1326
commit.Commit(config=new_config).commit(message="base",
1327
allow_pointless=True,
1329
working_tree=tree_a)
1331
return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
1332
self.assertTrue(repo_a.has_signature_for_revision_id('B'))
1334
bzrlib.gpg.GPGStrategy = oldstrategy
1335
tree_b = self.make_branch_and_tree('tree_b')
1336
repo_b = tree_b.branch.repository
1338
serializer = BundleSerializerV4('4')
1339
serializer.write(tree_a.branch.repository, ['A', 'B'], {}, s)
1341
install_bundle(repo_b, serializer.read(s))
1342
self.assertTrue(repo_b.has_signature_for_revision_id('B'))
1343
self.assertEqual(repo_b.get_signature_text('B'),
1344
repo_a.get_signature_text('B'))
1346
# ensure repeat installs are harmless
1347
install_bundle(repo_b, serializer.read(s))
1350
class V4WeaveBundleTester(V4BundleTester):
1352
def bzrdir_format(self):
1356
class MungedBundleTester(object):
805
1358
def build_test_bundle(self):
806
1359
wt = self.make_branch_and_tree('b1')