~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Martin Pool
  • Date: 2006-08-10 01:16:16 UTC
  • mto: (1904.1.2 0.9)
  • mto: This revision was merged to the branch mainline in revision 1913.
  • Revision ID: mbp@sourcefrog.net-20060810011616-d74881eba696e746
compare_trees is deprecated in 0.9 not 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2004-2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
import sys
20
20
import tempfile
21
21
 
22
 
from bzrlib import (
23
 
    bzrdir,
24
 
    errors,
25
 
    inventory,
26
 
    repository,
27
 
    treebuilder,
28
 
    )
29
 
from bzrlib.builtins import _merge_helper
 
22
from bzrlib import inventory
 
23
from bzrlib.builtins import merge
30
24
from bzrlib.bzrdir import BzrDir
31
25
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
26
from bzrlib.bundle.bundle_data import BundleTree
33
27
from bzrlib.bundle.serializer import write_bundle, read_bundle
34
 
from bzrlib.bundle.serializer.v08 import BundleSerializerV08
35
 
from bzrlib.bundle.serializer.v09 import BundleSerializerV09
36
28
from bzrlib.branch import Branch
37
29
from bzrlib.diff import internal_diff
38
 
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle, 
39
 
                           NoSuchFile,)
 
30
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle, BadBundle
40
31
from bzrlib.merge import Merge3Merger
41
32
from bzrlib.osutils import has_symlinks, sha_file
42
33
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
47
38
 
48
39
class MockTree(object):
49
40
    def __init__(self):
50
 
        from bzrlib.inventory import InventoryDirectory, ROOT_ID
 
41
        from bzrlib.inventory import RootEntry, ROOT_ID
51
42
        object.__init__(self)
52
43
        self.paths = {ROOT_ID: ""}
53
44
        self.ids = {"": ROOT_ID}
54
45
        self.contents = {}
55
 
        self.root = InventoryDirectory(ROOT_ID, '', None)
 
46
        self.root = RootEntry(ROOT_ID)
56
47
 
57
48
    inventory = property(lambda x:x)
58
49
 
309
300
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
310
301
 
311
302
 
312
 
class BundleTester1(TestCaseWithTransport):
313
 
 
314
 
    def test_mismatched_bundle(self):
315
 
        format = bzrdir.BzrDirMetaFormat1()
316
 
        format.repository_format = repository.RepositoryFormatKnit2()
317
 
        serializer = BundleSerializerV08('0.8')
318
 
        b = self.make_branch('.', format=format)
319
 
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write, 
320
 
                          b.repository, [], {}, StringIO())
321
 
 
322
 
    def test_matched_bundle(self):
323
 
        """Don't raise IncompatibleBundleFormat for knit2 and bundle0.9"""
324
 
        format = bzrdir.BzrDirMetaFormat1()
325
 
        format.repository_format = repository.RepositoryFormatKnit2()
326
 
        serializer = BundleSerializerV09('0.9')
327
 
        b = self.make_branch('.', format=format)
328
 
        serializer.write(b.repository, [], {}, StringIO())
329
 
 
330
 
    def test_mismatched_model(self):
331
 
        """Try copying a bundle from knit2 to knit1"""
332
 
        format = bzrdir.BzrDirMetaFormat1()
333
 
        format.repository_format = repository.RepositoryFormatKnit2()
334
 
        source = self.make_branch_and_tree('source', format=format)
335
 
        source.commit('one', rev_id='one-id')
336
 
        source.commit('two', rev_id='two-id')
337
 
        text = StringIO()
338
 
        write_bundle(source.branch.repository, 'two-id', None, text, 
339
 
                     format='0.9')
340
 
        text.seek(0)
341
 
 
342
 
        format = bzrdir.BzrDirMetaFormat1()
343
 
        format.repository_format = repository.RepositoryFormatKnit1()
344
 
        target = self.make_branch('target', format=format)
345
 
        self.assertRaises(errors.IncompatibleRevision, install_bundle, 
346
 
                          target.repository, read_bundle(text))
347
 
 
348
 
 
349
 
class V08BundleTester(TestCaseWithTransport):
350
 
 
351
 
    format = '0.8'
352
 
 
353
 
    def bzrdir_format(self):
354
 
        format = bzrdir.BzrDirMetaFormat1()
355
 
        format.repository_format = repository.RepositoryFormatKnit1()
356
 
        return format
357
 
 
358
 
    def make_branch_and_tree(self, path, format=None):
359
 
        if format is None:
360
 
            format = self.bzrdir_format()
361
 
        return TestCaseWithTransport.make_branch_and_tree(self, path, format)
362
 
 
363
 
    def make_branch(self, path, format=None):
364
 
        if format is None:
365
 
            format = self.bzrdir_format()
366
 
        return TestCaseWithTransport.make_branch(self, path, format)
 
303
class BundleTester(TestCaseWithTransport):
367
304
 
368
305
    def create_bundle_text(self, base_rev_id, rev_id):
369
306
        bundle_txt = StringIO()
370
307
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
371
 
                               bundle_txt, format=self.format)
 
308
                               bundle_txt)
372
309
        bundle_txt.seek(0)
373
310
        self.assertEqual(bundle_txt.readline(), 
374
 
                         '# Bazaar revision bundle v%s\n' % self.format)
 
311
                         '# Bazaar revision bundle v0.8\n')
375
312
        self.assertEqual(bundle_txt.readline(), '#\n')
376
313
 
377
314
        rev = self.b1.repository.get_revision(rev_id)
453
390
        else:
454
391
            if not os.path.exists(checkout_dir):
455
392
                os.mkdir(checkout_dir)
456
 
        tree = self.make_branch_and_tree(checkout_dir)
 
393
        tree = BzrDir.create_standalone_workingtree(checkout_dir)
457
394
        s = StringIO()
458
 
        ancestors = write_bundle(self.b1.repository, rev_id, None, s,
459
 
                                 format=self.format)
 
395
        ancestors = write_bundle(self.b1.repository, rev_id, None, s)
460
396
        s.seek(0)
461
397
        assert isinstance(s.getvalue(), str), (
462
398
            "Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
475
411
            for inventory_id in old:
476
412
                try:
477
413
                    old_file = old.get_file(inventory_id)
478
 
                except NoSuchFile:
 
414
                except:
479
415
                    continue
480
416
                if old_file is None:
481
417
                    continue
495
431
        sure everything matches the builtin branch.
496
432
        """
497
433
        to_tree = self.get_checkout(base_rev_id, checkout_dir=checkout_dir)
498
 
        original_parents = to_tree.get_parent_ids()
499
434
        repository = to_tree.branch.repository
500
 
        original_parents = to_tree.get_parent_ids()
501
435
        self.assertIs(repository.has_revision(base_rev_id), True)
502
436
        for rev in info.real_revisions:
503
437
            self.assert_(not repository.has_revision(rev.revision_id),
513
447
        self.assert_(to_tree.branch.repository.has_revision(info.target))
514
448
        # Do we also want to verify that all the texts have been added?
515
449
 
516
 
        self.assertEqual(original_parents + [info.target],
517
 
            to_tree.get_parent_ids())
 
450
        self.assert_(info.target in to_tree.pending_merges())
 
451
 
518
452
 
519
453
        rev = info.real_revisions[-1]
520
454
        base_tree = self.b1.repository.revision_tree(rev.revision_id)
634
568
                          verbose=False)
635
569
        bundle = self.get_valid_bundle('a@cset-0-5', 'a@cset-0-6')
636
570
        other = self.get_checkout('a@cset-0-5')
637
 
        tree1_inv = self.tree1.branch.repository.get_inventory_xml(
638
 
            'a@cset-0-5')
639
 
        tree2_inv = other.branch.repository.get_inventory_xml('a@cset-0-5')
640
 
        self.assertEqualDiff(tree1_inv, tree2_inv)
641
571
        other.rename_one('sub/dir/nolastnewline.txt', 'sub/nolastnewline.txt')
642
572
        other.commit('rename file', rev_id='a@cset-0-6b')
643
 
        _merge_helper([other.basedir, -1], [None, None],
644
 
                      this_dir=self.tree1.basedir)
 
573
        merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
645
574
        self.tree1.commit(u'Merge', rev_id='a@cset-0-7',
646
575
                          verbose=False)
647
576
        bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
649
578
    def test_symlink_bundle(self):
650
579
        if not has_symlinks():
651
580
            raise TestSkipped("No symlink support")
652
 
        self.tree1 = self.make_branch_and_tree('b1')
 
581
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
653
582
        self.b1 = self.tree1.branch
654
583
        tt = TreeTransform(self.tree1)
655
584
        tt.new_symlink('link', tt.root, 'bar/foo', 'link-1')
679
608
        self.get_valid_bundle('l@cset-0-3', 'l@cset-0-4')
680
609
 
681
610
    def test_binary_bundle(self):
682
 
        self.tree1 = self.make_branch_and_tree('b1')
 
611
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
683
612
        self.b1 = self.tree1.branch
684
613
        tt = TreeTransform(self.tree1)
685
614
        
721
650
        self.get_valid_bundle(None, 'b@cset-0-4')
722
651
 
723
652
    def test_last_modified(self):
724
 
        self.tree1 = self.make_branch_and_tree('b1')
 
653
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
725
654
        self.b1 = self.tree1.branch
726
655
        tt = TreeTransform(self.tree1)
727
656
        tt.new_file('file', tt.root, 'file', 'file')
742
671
        tt.create_file('file2', trans_id)
743
672
        tt.apply()
744
673
        other.commit('modify text in another tree', rev_id='a@lmod-0-2b')
745
 
        _merge_helper([other.basedir, -1], [None, None],
746
 
                      this_dir=self.tree1.basedir)
 
674
        merge([other.basedir, -1], [None, None], this_dir=self.tree1.basedir)
747
675
        self.tree1.commit(u'Merge', rev_id='a@lmod-0-3',
748
676
                          verbose=False)
749
677
        self.tree1.commit(u'Merge', rev_id='a@lmod-0-4')
750
678
        bundle = self.get_valid_bundle('a@lmod-0-2a', 'a@lmod-0-4')
751
679
 
752
680
    def test_hide_history(self):
753
 
        self.tree1 = self.make_branch_and_tree('b1')
 
681
        self.tree1 = BzrDir.create_standalone_workingtree('b1')
754
682
        self.b1 = self.tree1.branch
755
683
 
756
684
        open('b1/one', 'wb').write('one\n')
762
690
        self.tree1.commit('modify', rev_id='a@cset-0-3')
763
691
        bundle_file = StringIO()
764
692
        rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
765
 
                               'a@cset-0-1', bundle_file, format=self.format)
 
693
                               'a@cset-0-1', bundle_file)
766
694
        self.assertNotContainsRe(bundle_file.getvalue(), 'two')
767
695
        self.assertContainsRe(bundle_file.getvalue(), 'one')
768
696
        self.assertContainsRe(bundle_file.getvalue(), 'three')
854
782
        bundle = self.get_valid_bundle(None, 'white-4')
855
783
 
856
784
    def test_alt_timezone_bundle(self):
857
 
        self.tree1 = self.make_branch_and_memory_tree('b1')
 
785
        self.tree1 = self.make_branch_and_tree('b1')
858
786
        self.b1 = self.tree1.branch
859
 
        builder = treebuilder.TreeBuilder()
860
787
 
861
 
        self.tree1.lock_write()
862
 
        builder.start_tree(self.tree1)
863
 
        builder.build(['newfile'])
864
 
        builder.finish_tree()
 
788
        self.build_tree(['b1/newfile'])
 
789
        self.tree1.add(['newfile'])
865
790
 
866
791
        # Asia/Colombo offset = 5 hours 30 minutes
867
792
        self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
873
798
        self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
874
799
        self.assertEqual(19800, rev.timezone)
875
800
        self.assertEqual(1152544886.0, rev.timestamp)
876
 
        self.tree1.unlock()
877
 
 
878
 
    def test_bundle_root_id(self):
879
 
        self.tree1 = self.make_branch_and_tree('b1')
880
 
        self.b1 = self.tree1.branch
881
 
        self.tree1.commit('message', rev_id='revid1')
882
 
        bundle = self.get_valid_bundle(None, 'revid1')
883
 
        tree = bundle.revision_tree(self.b1.repository, 'revid1')
884
 
        self.assertEqual('revid1', tree.inventory.root.revision)
885
 
 
886
 
 
887
 
class V09BundleKnit2Tester(V08BundleTester):
888
 
 
889
 
    format = '0.9'
890
 
 
891
 
    def bzrdir_format(self):
892
 
        format = bzrdir.BzrDirMetaFormat1()
893
 
        format.repository_format = repository.RepositoryFormatKnit2()
894
 
        return format
895
 
 
896
 
 
897
 
class V09BundleKnit1Tester(V08BundleTester):
898
 
 
899
 
    format = '0.9'
900
 
 
901
 
    def bzrdir_format(self):
902
 
        format = bzrdir.BzrDirMetaFormat1()
903
 
        format.repository_format = repository.RepositoryFormatKnit1()
904
 
        return format
905
801
 
906
802
 
907
803
class MungedBundleTester(TestCaseWithTransport):