899
898
self.tree1 = self.make_branch_and_tree('b1')
900
899
self.b1 = self.tree1.branch
901
900
self.tree1.commit('message', rev_id='rev2a')
902
bundle = self.get_valid_bundle('null:', 'rev2a')
901
bundle = self.get_valid_bundle(None, 'rev2a')
903
902
branch2 = self.make_branch('b2')
904
903
self.assertFalse(branch2.repository.has_revision('rev2a'))
905
904
target_revision = bundle.install_revisions(branch2.repository)
906
905
self.assertTrue(branch2.repository.has_revision('rev2a'))
907
906
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
909
class V09BundleKnit2Tester(V08BundleTester):