~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
673
673
        self.assertFalse(repo._format.supports_external_lookups)
674
674
 
675
675
 
676
 
class Test2a(TestCaseWithTransport):
677
 
 
678
 
    def test_format_pack_compresses_True(self):
679
 
        repo = self.make_repository('repo', format='2a')
680
 
        self.assertTrue(repo._format.pack_compresses)
 
676
class TestDevelopment6(TestCaseWithTransport):
681
677
 
682
678
    def test_inventories_use_chk_map_with_parent_base_dict(self):
683
 
        tree = self.make_branch_and_tree('repo', format="2a")
 
679
        tree = self.make_branch_and_tree('repo', format="development6-rich-root")
684
680
        revid = tree.commit("foo")
685
681
        tree.lock_read()
686
682
        self.addCleanup(tree.unlock)
692
688
        self.assertEqual(65536,
693
689
            inv.parent_id_basename_to_file_id._root_node.maximum_size)
694
690
 
695
 
    def test_autopack_unchanged_chk_nodes(self):
696
 
        # at 20 unchanged commits, chk pages are packed that are split into
697
 
        # two groups such that the new pack being made doesn't have all its
698
 
        # pages in the source packs (though they are in the repository).
699
 
        tree = self.make_branch_and_tree('tree', format='2a')
700
 
        for pos in range(20):
701
 
            tree.commit(str(pos))
702
 
 
703
 
    def test_pack_with_hint(self):
704
 
        tree = self.make_branch_and_tree('tree', format='2a')
705
 
        # 1 commit to leave untouched
706
 
        tree.commit('1')
707
 
        to_keep = tree.branch.repository._pack_collection.names()
708
 
        # 2 to combine
709
 
        tree.commit('2')
710
 
        tree.commit('3')
711
 
        all = tree.branch.repository._pack_collection.names()
712
 
        combine = list(set(all) - set(to_keep))
713
 
        self.assertLength(3, all)
714
 
        self.assertLength(2, combine)
715
 
        tree.branch.repository.pack(hint=combine)
716
 
        final = tree.branch.repository._pack_collection.names()
717
 
        self.assertLength(2, final)
718
 
        self.assertFalse(combine[0] in final)
719
 
        self.assertFalse(combine[1] in final)
720
 
        self.assertSubset(to_keep, final)
721
 
 
722
691
    def test_stream_source_to_gc(self):
723
 
        source = self.make_repository('source', format='2a')
724
 
        target = self.make_repository('target', format='2a')
 
692
        source = self.make_repository('source', format='development6-rich-root')
 
693
        target = self.make_repository('target', format='development6-rich-root')
725
694
        stream = source._get_source(target._format)
726
695
        self.assertIsInstance(stream, groupcompress_repo.GroupCHKStreamSource)
727
696
 
728
697
    def test_stream_source_to_non_gc(self):
729
 
        source = self.make_repository('source', format='2a')
 
698
        source = self.make_repository('source', format='development6-rich-root')
730
699
        target = self.make_repository('target', format='rich-root-pack')
731
700
        stream = source._get_source(target._format)
732
701
        # We don't want the child GroupCHKStreamSource
734
703
 
735
704
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
736
705
        source_builder = self.make_branch_builder('source',
737
 
                            format='2a')
 
706
                            format='development6-rich-root')
738
707
        # We have to build a fairly large tree, so that we are sure the chk
739
708
        # pages will have split into multiple pages.
740
709
        entries = [('add', ('', 'a-root-id', 'directory', None))]
757
726
        source_branch = source_builder.get_branch()
758
727
        source_branch.lock_read()
759
728
        self.addCleanup(source_branch.unlock)
760
 
        target = self.make_repository('target', format='2a')
 
729
        target = self.make_repository('target', format='development6-rich-root')
761
730
        source = source_branch.repository._get_source(target._format)
762
731
        self.assertIsInstance(source, groupcompress_repo.GroupCHKStreamSource)
763
732
 
797
766
        self.assertEqual(257, len(full_chk_records))
798
767
        self.assertSubset(simple_chk_records, full_chk_records)
799
768
 
800
 
    def test_inconsistency_fatal(self):
801
 
        repo = self.make_repository('repo', format='2a')
802
 
        self.assertTrue(repo.revisions._index._inconsistency_fatal)
803
 
        self.assertFalse(repo.texts._index._inconsistency_fatal)
804
 
        self.assertFalse(repo.inventories._index._inconsistency_fatal)
805
 
        self.assertFalse(repo.signatures._index._inconsistency_fatal)
806
 
        self.assertFalse(repo.chk_bytes._index._inconsistency_fatal)
807
 
 
808
769
 
809
770
class TestKnitPackStreamSource(tests.TestCaseWithMemoryTransport):
810
771
 
1393
1354
        self.assertTrue(new_pack.inventory_index._optimize_for_size)
1394
1355
        self.assertTrue(new_pack.text_index._optimize_for_size)
1395
1356
        self.assertTrue(new_pack.signature_index._optimize_for_size)
1396
 
 
1397
 
 
1398
 
class TestCrossFormatPacks(TestCaseWithTransport):
1399
 
 
1400
 
    def log_pack(self, hint=None):
1401
 
        self.calls.append(('pack', hint))
1402
 
        self.orig_pack(hint=hint)
1403
 
        if self.expect_hint:
1404
 
            self.assertTrue(hint)
1405
 
 
1406
 
    def run_stream(self, src_fmt, target_fmt, expect_pack_called):
1407
 
        self.expect_hint = expect_pack_called
1408
 
        self.calls = []
1409
 
        source_tree = self.make_branch_and_tree('src', format=src_fmt)
1410
 
        source_tree.lock_write()
1411
 
        self.addCleanup(source_tree.unlock)
1412
 
        tip = source_tree.commit('foo')
1413
 
        target = self.make_repository('target', format=target_fmt)
1414
 
        target.lock_write()
1415
 
        self.addCleanup(target.unlock)
1416
 
        source = source_tree.branch.repository._get_source(target._format)
1417
 
        self.orig_pack = target.pack
1418
 
        target.pack = self.log_pack
1419
 
        search = target.search_missing_revision_ids(
1420
 
            source_tree.branch.repository, tip)
1421
 
        stream = source.get_stream(search)
1422
 
        from_format = source_tree.branch.repository._format
1423
 
        sink = target._get_sink()
1424
 
        sink.insert_stream(stream, from_format, [])
1425
 
        if expect_pack_called:
1426
 
            self.assertLength(1, self.calls)
1427
 
        else:
1428
 
            self.assertLength(0, self.calls)
1429
 
 
1430
 
    def run_fetch(self, src_fmt, target_fmt, expect_pack_called):
1431
 
        self.expect_hint = expect_pack_called
1432
 
        self.calls = []
1433
 
        source_tree = self.make_branch_and_tree('src', format=src_fmt)
1434
 
        source_tree.lock_write()
1435
 
        self.addCleanup(source_tree.unlock)
1436
 
        tip = source_tree.commit('foo')
1437
 
        target = self.make_repository('target', format=target_fmt)
1438
 
        target.lock_write()
1439
 
        self.addCleanup(target.unlock)
1440
 
        source = source_tree.branch.repository
1441
 
        self.orig_pack = target.pack
1442
 
        target.pack = self.log_pack
1443
 
        target.fetch(source)
1444
 
        if expect_pack_called:
1445
 
            self.assertLength(1, self.calls)
1446
 
        else:
1447
 
            self.assertLength(0, self.calls)
1448
 
 
1449
 
    def test_sink_format_hint_no(self):
1450
 
        # When the target format says packing makes no difference, pack is not
1451
 
        # called.
1452
 
        self.run_stream('1.9', 'rich-root-pack', False)
1453
 
 
1454
 
    def test_sink_format_hint_yes(self):
1455
 
        # When the target format says packing makes a difference, pack is
1456
 
        # called.
1457
 
        self.run_stream('1.9', '2a', True)
1458
 
 
1459
 
    def test_sink_format_same_no(self):
1460
 
        # When the formats are the same, pack is not called.
1461
 
        self.run_stream('2a', '2a', False)
1462
 
 
1463
 
    def test_IDS_format_hint_no(self):
1464
 
        # When the target format says packing makes no difference, pack is not
1465
 
        # called.
1466
 
        self.run_fetch('1.9', 'rich-root-pack', False)
1467
 
 
1468
 
    def test_IDS_format_hint_yes(self):
1469
 
        # When the target format says packing makes a difference, pack is
1470
 
        # called.
1471
 
        self.run_fetch('1.9', '2a', True)
1472
 
 
1473
 
    def test_IDS_format_same_no(self):
1474
 
        # When the formats are the same, pack is not called.
1475
 
        self.run_fetch('2a', '2a', False)