~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-17 00:59:30 UTC
  • mfrom: (1551.15.4 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20070417005930-rofskshyjsfzrahh
Fix ftp transport with servers that don't support atomic rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    errors,
25
25
    inventory,
26
26
    repository,
27
 
    revision as _mod_revision,
28
27
    treebuilder,
29
28
    )
30
29
from bzrlib.builtins import _merge_helper
337
336
        source.commit('one', rev_id='one-id')
338
337
        source.commit('two', rev_id='two-id')
339
338
        text = StringIO()
340
 
        write_bundle(source.branch.repository, 'two-id', 'null:', text,
 
339
        write_bundle(source.branch.repository, 'two-id', None, text, 
341
340
                     format='0.9')
342
341
        text.seek(0)
343
342
 
457
456
                os.mkdir(checkout_dir)
458
457
        tree = self.make_branch_and_tree(checkout_dir)
459
458
        s = StringIO()
460
 
        ancestors = write_bundle(self.b1.repository, rev_id, 'null:', s,
 
459
        ancestors = write_bundle(self.b1.repository, rev_id, None, s,
461
460
                                 format=self.format)
462
461
        s.seek(0)
463
462
        assert isinstance(s.getvalue(), str), (
483
482
                    continue
484
483
                self.assertEqual(old_file.read(),
485
484
                                 new.get_file(inventory_id).read())
486
 
        if not _mod_revision.is_null(rev_id):
 
485
        if rev_id is not None:
487
486
            rh = self.b1.revision_history()
488
487
            tree.branch.set_revision_history(rh[:rh.index(rev_id)+1])
489
488
            tree.update()
550
549
        self.tree1.add('one')
551
550
        self.tree1.commit('add one', rev_id='a@cset-0-1')
552
551
 
553
 
        bundle = self.get_valid_bundle('null:', 'a@cset-0-1')
 
552
        bundle = self.get_valid_bundle(None, 'a@cset-0-1')
554
553
        # FIXME: The current write_bundle api no longer supports
555
554
        #        setting a custom summary message
556
555
        #        We should re-introduce the ability, and update
592
591
        bundle = self.get_valid_bundle('a@cset-0-1', 'a@cset-0-2')
593
592
 
594
593
        # Check a rollup bundle 
595
 
        bundle = self.get_valid_bundle('null:', 'a@cset-0-2')
 
594
        bundle = self.get_valid_bundle(None, 'a@cset-0-2')
596
595
 
597
596
        # Now delete entries
598
597
        self.tree1.remove(
610
609
        self.assertRaises(TestamentMismatch, self.get_invalid_bundle, 
611
610
                          'a@cset-0-2', 'a@cset-0-3')
612
611
        # Check a rollup bundle 
613
 
        bundle = self.get_valid_bundle('null:', 'a@cset-0-3')
 
612
        bundle = self.get_valid_bundle(None, 'a@cset-0-3')
614
613
 
615
614
        # Now move the directory
616
615
        self.tree1.rename_one('dir', 'sub/dir')
618
617
 
619
618
        bundle = self.get_valid_bundle('a@cset-0-3', 'a@cset-0-4')
620
619
        # Check a rollup bundle 
621
 
        bundle = self.get_valid_bundle('null:', 'a@cset-0-4')
 
620
        bundle = self.get_valid_bundle(None, 'a@cset-0-4')
622
621
 
623
622
        # Modified files
624
623
        open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n')
657
656
        tt.new_symlink('link', tt.root, 'bar/foo', 'link-1')
658
657
        tt.apply()
659
658
        self.tree1.commit('add symlink', rev_id='l@cset-0-1')
660
 
        self.get_valid_bundle('null:', 'l@cset-0-1')
 
659
        self.get_valid_bundle(None, 'l@cset-0-1')
661
660
        tt = TreeTransform(self.tree1)
662
661
        trans_id = tt.trans_id_tree_file_id('link-1')
663
662
        tt.adjust_path('link2', tt.root, trans_id)
690
689
        tt.new_file('file2', tt.root, '\x01\n\x02\r\x03\n\x04\r\xff', 'binary-2')
691
690
        tt.apply()
692
691
        self.tree1.commit('add binary', rev_id='b@cset-0-1')
693
 
        self.get_valid_bundle('null:', 'b@cset-0-1')
 
692
        self.get_valid_bundle(None, 'b@cset-0-1')
694
693
 
695
694
        # Delete
696
695
        tt = TreeTransform(self.tree1)
720
719
        self.get_valid_bundle('b@cset-0-3', 'b@cset-0-4')
721
720
 
722
721
        # Rollup
723
 
        self.get_valid_bundle('null:', 'b@cset-0-4')
 
722
        self.get_valid_bundle(None, 'b@cset-0-4')
724
723
 
725
724
    def test_last_modified(self):
726
725
        self.tree1 = self.make_branch_and_tree('b1')
800
799
                              " combining characters.")
801
800
 
802
801
        # Add
803
 
        bundle = self.get_valid_bundle('null:', 'i18n-1')
 
802
        bundle = self.get_valid_bundle(None, 'i18n-1')
804
803
 
805
804
        # Modified
806
805
        f = open(u'b1/with Dod\xe9', 'wb')
824
823
        bundle = self.get_valid_bundle('i18n-3', 'i18n-4')
825
824
 
826
825
        # Rollup
827
 
        bundle = self.get_valid_bundle('null:', 'i18n-4')
 
826
        bundle = self.get_valid_bundle(None, 'i18n-4')
828
827
 
829
828
 
830
829
    def test_whitespace_bundle(self):
842
841
        # Added
843
842
        self.tree1.commit('funky whitespace', rev_id='white-1')
844
843
 
845
 
        bundle = self.get_valid_bundle('null:', 'white-1')
 
844
        bundle = self.get_valid_bundle(None, 'white-1')
846
845
 
847
846
        # Modified
848
847
        open('b1/trailing space ', 'ab').write('add some text\n')
863
862
        bundle = self.get_valid_bundle('white-3', 'white-4')
864
863
        
865
864
        # Now test a complet roll-up
866
 
        bundle = self.get_valid_bundle('null:', 'white-4')
 
865
        bundle = self.get_valid_bundle(None, 'white-4')
867
866
 
868
867
    def test_alt_timezone_bundle(self):
869
868
        self.tree1 = self.make_branch_and_memory_tree('b1')
879
878
        self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
880
879
                          timezone=19800, timestamp=1152544886.0)
881
880
 
882
 
        bundle = self.get_valid_bundle('null:', 'tz-1')
 
881
        bundle = self.get_valid_bundle(None, 'tz-1')
883
882
        
884
883
        rev = bundle.revisions[0]
885
884
        self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
891
890
        self.tree1 = self.make_branch_and_tree('b1')
892
891
        self.b1 = self.tree1.branch
893
892
        self.tree1.commit('message', rev_id='revid1')
894
 
        bundle = self.get_valid_bundle('null:', 'revid1')
 
893
        bundle = self.get_valid_bundle(None, 'revid1')
895
894
        tree = bundle.revision_tree(self.b1.repository, 'revid1')
896
895
        self.assertEqual('revid1', tree.inventory.root.revision)
897
896
 
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)
908
907
 
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')
912
 
        tree.lock_write()
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(),
919
 
                              '# properties:\n'
920
 
                              '#   branch-nick: tree\n'
921
 
                              '#   empty: \n'
922
 
                              '#   one: two\n'
923
 
                             )
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'},
929
 
                         rev.properties)
930
 
 
931
 
    def test_bundle_empty_property_alt(self):
932
 
        """Test serializing revision properties with an empty value.
933
 
 
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.
938
 
        """
939
 
        tree = self.make_branch_and_memory_tree('tree')
940
 
        tree.lock_write()
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:])
950
 
 
951
 
        self.assertContainsRe(bundle_sio.getvalue(),
952
 
                              '# properties:\n'
953
 
                              '#   branch-nick: tree\n'
954
 
                              '#   empty:\n'
955
 
                              '#   one: two\n'
956
 
                             )
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'},
962
 
                         rev.properties)
963
 
 
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')
967
 
        tree.lock_write()
968
 
        self.addCleanup(tree.unlock)
969
 
 
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(),
976
 
                              '# properties:\n'
977
 
                              '#   a: 4\n'
978
 
                              '#   b: 3\n'
979
 
                              '#   branch-nick: tree\n'
980
 
                              '#   c: 2\n'
981
 
                              '#   d: 1\n'
982
 
                             )
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)
989
 
 
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')
993
 
        tree.lock_write()
994
 
        self.addCleanup(tree.unlock)
995
 
 
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
999
 
        # whitespace.
1000
 
        # However, Testaments assert than they are str(), and thus should not
1001
 
        # be Unicode.
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(),
1007
 
                              '# properties:\n'
1008
 
                              '#   alpha: \xce\xb1\n'
1009
 
                              '#   branch-nick: tree\n'
1010
 
                              '#   omega: \xce\xa9\n'
1011
 
                             )
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)
1018
 
 
1019
908
 
1020
909
class V09BundleKnit2Tester(V08BundleTester):
1021
910