~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

(robertc) Pack 2a repositories after fetching from a different format
        (bug 376748) and fix problems with autopacking 2a repositories
        (bug 365615). (Robert Collins)

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 TestDevelopment6(TestCaseWithTransport):
 
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)
677
681
 
678
682
    def test_inventories_use_chk_map_with_parent_base_dict(self):
679
 
        tree = self.make_branch_and_tree('repo', format="development6-rich-root")
 
683
        tree = self.make_branch_and_tree('repo', format="2a")
680
684
        revid = tree.commit("foo")
681
685
        tree.lock_read()
682
686
        self.addCleanup(tree.unlock)
688
692
        self.assertEqual(65536,
689
693
            inv.parent_id_basename_to_file_id._root_node.maximum_size)
690
694
 
 
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
 
691
722
    def test_stream_source_to_gc(self):
692
 
        source = self.make_repository('source', format='development6-rich-root')
693
 
        target = self.make_repository('target', format='development6-rich-root')
 
723
        source = self.make_repository('source', format='2a')
 
724
        target = self.make_repository('target', format='2a')
694
725
        stream = source._get_source(target._format)
695
726
        self.assertIsInstance(stream, groupcompress_repo.GroupCHKStreamSource)
696
727
 
697
728
    def test_stream_source_to_non_gc(self):
698
 
        source = self.make_repository('source', format='development6-rich-root')
 
729
        source = self.make_repository('source', format='2a')
699
730
        target = self.make_repository('target', format='rich-root-pack')
700
731
        stream = source._get_source(target._format)
701
732
        # We don't want the child GroupCHKStreamSource
703
734
 
704
735
    def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
705
736
        source_builder = self.make_branch_builder('source',
706
 
                            format='development6-rich-root')
 
737
                            format='2a')
707
738
        # We have to build a fairly large tree, so that we are sure the chk
708
739
        # pages will have split into multiple pages.
709
740
        entries = [('add', ('', 'a-root-id', 'directory', None))]
726
757
        source_branch = source_builder.get_branch()
727
758
        source_branch.lock_read()
728
759
        self.addCleanup(source_branch.unlock)
729
 
        target = self.make_repository('target', format='development6-rich-root')
 
760
        target = self.make_repository('target', format='2a')
730
761
        source = source_branch.repository._get_source(target._format)
731
762
        self.assertIsInstance(source, groupcompress_repo.GroupCHKStreamSource)
732
763
 
1354
1385
        self.assertTrue(new_pack.inventory_index._optimize_for_size)
1355
1386
        self.assertTrue(new_pack.text_index._optimize_for_size)
1356
1387
        self.assertTrue(new_pack.signature_index._optimize_for_size)
 
1388
 
 
1389
 
 
1390
class TestCrossFormatPacks(TestCaseWithTransport):
 
1391
 
 
1392
    def log_pack(self, hint=None):
 
1393
        self.calls.append(('pack', hint))
 
1394
        self.orig_pack(hint=hint)
 
1395
        if self.expect_hint:
 
1396
            self.assertTrue(hint)
 
1397
 
 
1398
    def run_stream(self, src_fmt, target_fmt, expect_pack_called):
 
1399
        self.expect_hint = expect_pack_called
 
1400
        self.calls = []
 
1401
        source_tree = self.make_branch_and_tree('src', format=src_fmt)
 
1402
        source_tree.lock_write()
 
1403
        self.addCleanup(source_tree.unlock)
 
1404
        tip = source_tree.commit('foo')
 
1405
        target = self.make_repository('target', format=target_fmt)
 
1406
        target.lock_write()
 
1407
        self.addCleanup(target.unlock)
 
1408
        source = source_tree.branch.repository._get_source(target._format)
 
1409
        self.orig_pack = target.pack
 
1410
        target.pack = self.log_pack
 
1411
        search = target.search_missing_revision_ids(
 
1412
            source_tree.branch.repository, tip)
 
1413
        stream = source.get_stream(search)
 
1414
        from_format = source_tree.branch.repository._format
 
1415
        sink = target._get_sink()
 
1416
        sink.insert_stream(stream, from_format, [])
 
1417
        if expect_pack_called:
 
1418
            self.assertLength(1, self.calls)
 
1419
        else:
 
1420
            self.assertLength(0, self.calls)
 
1421
 
 
1422
    def run_fetch(self, src_fmt, target_fmt, expect_pack_called):
 
1423
        self.expect_hint = expect_pack_called
 
1424
        self.calls = []
 
1425
        source_tree = self.make_branch_and_tree('src', format=src_fmt)
 
1426
        source_tree.lock_write()
 
1427
        self.addCleanup(source_tree.unlock)
 
1428
        tip = source_tree.commit('foo')
 
1429
        target = self.make_repository('target', format=target_fmt)
 
1430
        target.lock_write()
 
1431
        self.addCleanup(target.unlock)
 
1432
        source = source_tree.branch.repository
 
1433
        self.orig_pack = target.pack
 
1434
        target.pack = self.log_pack
 
1435
        target.fetch(source)
 
1436
        if expect_pack_called:
 
1437
            self.assertLength(1, self.calls)
 
1438
        else:
 
1439
            self.assertLength(0, self.calls)
 
1440
 
 
1441
    def test_sink_format_hint_no(self):
 
1442
        # When the target format says packing makes no difference, pack is not
 
1443
        # called.
 
1444
        self.run_stream('1.9', 'rich-root-pack', False)
 
1445
 
 
1446
    def test_sink_format_hint_yes(self):
 
1447
        # When the target format says packing makes a difference, pack is
 
1448
        # called.
 
1449
        self.run_stream('1.9', '2a', True)
 
1450
 
 
1451
    def test_sink_format_same_no(self):
 
1452
        # When the formats are the same, pack is not called.
 
1453
        self.run_stream('2a', '2a', False)
 
1454
 
 
1455
    def test_IDS_format_hint_no(self):
 
1456
        # When the target format says packing makes no difference, pack is not
 
1457
        # called.
 
1458
        self.run_fetch('1.9', 'rich-root-pack', False)
 
1459
 
 
1460
    def test_IDS_format_hint_yes(self):
 
1461
        # When the target format says packing makes a difference, pack is
 
1462
        # called.
 
1463
        self.run_fetch('1.9', '2a', True)
 
1464
 
 
1465
    def test_IDS_format_same_no(self):
 
1466
        # When the formats are the same, pack is not called.
 
1467
        self.run_fetch('2a', '2a', False)