/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_pack_repository.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from .. import (
27
27
    controldir,
28
28
    errors,
 
29
    gpg,
29
30
    osutils,
30
31
    repository,
31
32
    revision as _mod_revision,
96
97
 
97
98
    def check_format(self, t):
98
99
        self.assertEqualDiff(
99
 
            self.format_string.encode('ascii'), # from scenario
 
100
            self.format_string.encode('ascii'),  # from scenario
100
101
            t.get('format').read())
101
102
 
102
103
    def assertHasNoKndx(self, t, knit_name):
120
121
        self.assertFalse(t.has('knits'))
121
122
        # revision-indexes file-container directory
122
123
        self.assertEqual([],
123
 
            list(self.index_class(t, 'pack-names', None).iter_all_entries()))
 
124
                         list(self.index_class(t, 'pack-names', None).iter_all_entries()))
124
125
        self.assertTrue(S_ISDIR(t.stat('packs').st_mode))
125
126
        self.assertTrue(S_ISDIR(t.stat('upload').st_mode))
126
127
        self.assertTrue(S_ISDIR(t.stat('indices').st_mode))
162
163
    def test_adding_revision_creates_pack_indices(self):
163
164
        format = self.get_format()
164
165
        tree = self.make_branch_and_tree('.', format=format)
165
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
166
        trans = tree.branch.repository.controldir.get_repository_transport(
 
167
            None)
166
168
        self.assertEqual([],
167
 
            list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
 
169
                         list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
168
170
        tree.commit('foobarbaz')
169
171
        index = self.index_class(trans, 'pack-names', None)
170
172
        index_nodes = list(index.iter_all_entries())
183
185
        tree1 = self.make_branch_and_tree('1', format=format)
184
186
        tree2 = self.make_branch_and_tree('2', format=format)
185
187
        tree1.branch.repository.fetch(tree2.branch.repository)
186
 
        trans = tree1.branch.repository.controldir.get_repository_transport(None)
 
188
        trans = tree1.branch.repository.controldir.get_repository_transport(
 
189
            None)
187
190
        self.assertEqual([],
188
 
            list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
 
191
                         list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
189
192
 
190
193
    def test_commit_across_pack_shape_boundary_autopacks(self):
191
194
        format = self.get_format()
192
195
        tree = self.make_branch_and_tree('.', format=format)
193
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
196
        trans = tree.branch.repository.controldir.get_repository_transport(
 
197
            None)
194
198
        # This test could be a little cheaper by replacing the packs
195
199
        # attribute on the repository to allow a different pack distribution
196
200
        # and max packs policy - so we are checking the policy is honoured
212
216
        tree = tree.controldir.open_workingtree()
213
217
        check_result = tree.branch.repository.check(
214
218
            [tree.branch.last_revision()])
215
 
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
219
        nb_files = 5  # .pack, .rix, .iix, .tix, .six
216
220
        if tree.branch.repository._format.supports_chks:
217
 
            nb_files += 1 # .cix
 
221
            nb_files += 1  # .cix
218
222
        # We should have 10 x nb_files files in the obsolete_packs directory.
219
223
        obsolete_files = list(trans.list_dir('obsolete_packs'))
220
224
        self.assertFalse('foo' in obsolete_files)
249
253
                    inv.root.revision = revid
250
254
                    repo.texts.add_lines((inv.root.file_id, revid), [], [])
251
255
                    rev = _mod_revision.Revision(timestamp=0, timezone=None,
252
 
                        committer="Foo Bar <foo@example.com>", message="Message",
253
 
                        revision_id=revid)
 
256
                                                 committer="Foo Bar <foo@example.com>", message="Message",
 
257
                                                 revision_id=revid)
254
258
                    rev.parent_ids = ()
255
259
                    repo.add_revision(revid, rev, inv=inv)
256
260
                except:
287
291
        repo = self.make_repository('repo')
288
292
        pack_coll = repo._pack_collection
289
293
        indices = {pack_coll.revision_index, pack_coll.inventory_index,
290
 
                pack_coll.text_index, pack_coll.signature_index}
 
294
                   pack_coll.text_index, pack_coll.signature_index}
291
295
        if pack_coll.chk_index is not None:
292
296
            indices.add(pack_coll.chk_index)
293
297
        combined_indices = set(idx.combined_index for idx in indices)
296
300
                combined_indices.difference([combined_index]),
297
301
                combined_index._sibling_indices)
298
302
 
 
303
    def test_pack_with_signatures(self):
 
304
        format = self.get_format()
 
305
        tree = self.make_branch_and_tree('.', format=format)
 
306
        trans = tree.branch.repository.controldir.get_repository_transport(
 
307
            None)
 
308
        revid1 = tree.commit('start')
 
309
        revid2 = tree.commit('more work')
 
310
        strategy = gpg.LoopbackGPGStrategy(None)
 
311
        repo = tree.branch.repository
 
312
        self.addCleanup(repo.lock_write().unlock)
 
313
        repo.start_write_group()
 
314
        repo.sign_revision(revid1, strategy)
 
315
        repo.commit_write_group()
 
316
        repo.start_write_group()
 
317
        repo.sign_revision(revid2, strategy)
 
318
        repo.commit_write_group()
 
319
        tree.branch.repository.pack()
 
320
        # there should be 1 pack:
 
321
        index = self.index_class(trans, 'pack-names', None)
 
322
        self.assertEqual(1, len(list(index.iter_all_entries())))
 
323
        self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
 
324
 
299
325
    def test_pack_after_two_commits_packs_everything(self):
300
326
        format = self.get_format()
301
327
        tree = self.make_branch_and_tree('.', format=format)
302
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
328
        trans = tree.branch.repository.controldir.get_repository_transport(
 
329
            None)
303
330
        tree.commit('start')
304
331
        tree.commit('more work')
305
332
        tree.branch.repository.pack()
351
378
        # tip->ancestor
352
379
        format = self.get_format()
353
380
        tree = self.make_branch_and_tree('.', format=format)
354
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
381
        trans = tree.branch.repository.controldir.get_repository_transport(
 
382
            None)
355
383
        tree.commit('start', rev_id=b'1')
356
384
        tree.commit('more work', rev_id=b'2')
357
385
        tree.branch.repository.pack()
388
416
 
389
417
    def _add_text(self, repo, fileid):
390
418
        """Add a text to the repository within a write group."""
391
 
        repo.texts.add_lines((fileid, b'samplerev+'+fileid), [],
392
 
            [b'smaplerev+'+fileid])
 
419
        repo.texts.add_lines((fileid, b'samplerev+' + fileid), [],
 
420
                             [b'smaplerev+' + fileid])
393
421
 
394
422
    def test_concurrent_writers_merge_new_packs(self):
395
423
        format = self.get_format()
431
459
                # Now both repositories should know about both names
432
460
                r1._pack_collection.ensure_loaded()
433
461
                r2._pack_collection.ensure_loaded()
434
 
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
 
462
                self.assertEqual(r1._pack_collection.names(),
 
463
                                 r2._pack_collection.names())
435
464
                self.assertEqual(2, len(r1._pack_collection.names()))
436
465
            finally:
437
466
                r2.unlock()
500
529
                # Now both repositories should now about just one name.
501
530
                r1._pack_collection.ensure_loaded()
502
531
                r2._pack_collection.ensure_loaded()
503
 
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
 
532
                self.assertEqual(r1._pack_collection.names(),
 
533
                                 r2._pack_collection.names())
504
534
                self.assertEqual(1, len(r1._pack_collection.names()))
505
535
                self.assertFalse(name_to_drop in r1._pack_collection.names())
506
536
            finally:
521
551
                # Now r2 has read the pack-names file, but will need to reload
522
552
                # it after r1 has repacked
523
553
                tree.branch.repository.pack()
524
 
                self.assertEqual({rev2:(rev1,)}, r2.get_parent_map([rev2]))
 
554
                self.assertEqual({rev2: (rev1,)}, r2.get_parent_map([rev2]))
525
555
            finally:
526
556
                r2.unlock()
527
557
        finally:
542
572
                packed = False
543
573
                result = {}
544
574
                record_stream = r2.revisions.get_record_stream(keys,
545
 
                                    'unordered', False)
 
575
                                                               'unordered', False)
546
576
                for record in record_stream:
547
577
                    result[record.key] = record
548
578
                    if not packed:
573
603
                autopack_count = [0]
574
604
                r1 = tree.branch.repository
575
605
                orig = r1._pack_collection.pack_distribution
 
606
 
576
607
                def trigger_during_auto(*args, **kwargs):
577
608
                    ret = orig(*args, **kwargs)
578
609
                    if not autopack_count[0]:
621
652
        repo2 = repository.Repository.open('.')
622
653
        self.prepare_for_break_lock()
623
654
        repo2.break_lock()
624
 
        self.assertRaises(errors.LockBroken, repo._pack_collection._unlock_names)
 
655
        self.assertRaises(errors.LockBroken,
 
656
                          repo._pack_collection._unlock_names)
625
657
 
626
658
    def test_fetch_without_find_ghosts_ignores_ghosts(self):
627
659
        # we want two repositories at this point:
631
663
        # 'references' is present in both repositories, and 'tip' is present
632
664
        # just in has_ghost.
633
665
        # has_ghost       missing_ghost
634
 
        #------------------------------
 
666
        # ------------------------------
635
667
        # 'ghost'             -
636
668
        # 'references'    'references'
637
669
        # 'tip'               -
638
670
        # In this test we fetch 'tip' which should not fetch 'ghost'
639
671
        has_ghost = self.make_repository('has_ghost', format=self.get_format())
640
672
        missing_ghost = self.make_repository('missing_ghost',
641
 
            format=self.get_format())
 
673
                                             format=self.get_format())
642
674
 
643
675
        def add_commit(repo, revision_id, parent_ids):
644
676
            repo.lock_write()
667
699
        rev = missing_ghost.get_revision(b'tip')
668
700
        inv = missing_ghost.get_inventory(b'tip')
669
701
        self.assertRaises(errors.NoSuchRevision,
670
 
            missing_ghost.get_revision, b'ghost')
 
702
                          missing_ghost.get_revision, b'ghost')
671
703
        self.assertRaises(errors.NoSuchRevision,
672
 
            missing_ghost.get_inventory, b'ghost')
 
704
                          missing_ghost.get_inventory, b'ghost')
673
705
 
674
706
    def make_write_ready_repo(self):
675
707
        format = self.get_format()
713
745
    def test_supports_external_lookups(self):
714
746
        repo = self.make_repository('.', format=self.get_format())
715
747
        self.assertEqual(self.format_supports_external_lookups,
716
 
            repo._format.supports_external_lookups)
 
748
                         repo._format.supports_external_lookups)
717
749
 
718
750
    def _lock_write(self, write_lockable):
719
751
        """Lock write_lockable, add a cleanup and return the result.
720
 
        
 
752
 
721
753
        :param write_lockable: An object with a lock_write method.
722
754
        :return: The result of write_lockable.lock_write().
723
755
        """
766
798
        wg_tokens = repo.suspend_write_group()
767
799
        expected_pack_name = wg_tokens[0] + '.pack'
768
800
        expected_names = [wg_tokens[0] + ext for ext in
769
 
                            ('.rix', '.iix', '.tix', '.six')]
 
801
                          ('.rix', '.iix', '.tix', '.six')]
770
802
        if repo.chk_bytes is not None:
771
803
            expected_names.append(wg_tokens[0] + '.cix')
772
804
        expected_names.append(expected_pack_name)
794
826
        self.assertEqual([key], list(same_repo.chk_bytes.keys()))
795
827
        self.assertEqual(
796
828
            text, next(same_repo.chk_bytes.get_record_stream([key],
797
 
                'unordered', True)).get_bytes_as('fulltext'))
 
829
                                                             'unordered', True)).get_bytes_as('fulltext'))
798
830
        same_repo.abort_write_group()
799
831
        self.assertEqual([], list(same_repo.chk_bytes.keys()))
800
832
 
836
868
        same_repo.commit_write_group()
837
869
        expected_pack_name = wg_tokens[0] + '.pack'
838
870
        expected_names = [wg_tokens[0] + ext for ext in
839
 
                            ('.rix', '.iix', '.tix', '.six')]
 
871
                          ('.rix', '.iix', '.tix', '.six')]
840
872
        if repo.chk_bytes is not None:
841
873
            expected_names.append(wg_tokens[0] + '.cix')
842
874
        self.assertEqual(
872
904
    def setUp(self):
873
905
        if not self.format_supports_external_lookups:
874
906
            raise TestNotApplicable("%r doesn't support stacking"
875
 
                % (self.format_name,))
 
907
                                    % (self.format_name,))
876
908
        super(TestPackRepositoryStacking, self).setUp()
877
909
 
878
910
    def get_format(self):
909
941
        repo.add_fallback_repository(base)
910
942
        # you can't stack on something with incompatible data
911
943
        bad_repo = self.make_repository('mismatch',
912
 
            format=mismatching_format_name)
 
944
                                        format=mismatching_format_name)
913
945
        e = self.assertRaises(errors.IncompatibleRepositories,
914
 
            repo.add_fallback_repository, bad_repo)
 
946
                              repo.add_fallback_repository, bad_repo)
915
947
        self.assertContainsRe(str(e),
916
 
            r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
917
 
            r'.*Repository.*/repo/.*\n'
918
 
            r'different rich-root support')
 
948
                              r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
 
949
                              r'.*Repository.*/repo/.*\n'
 
950
                              r'different rich-root support')
919
951
 
920
952
    def test_stack_checks_serializers_compatibility(self):
921
953
        repo = self.make_repository('repo', format=self.get_format())
933
965
                mismatching_format_name = 'pack-0.92-subtree'
934
966
            else:
935
967
                raise TestNotApplicable('No formats use non-v5 serializer'
936
 
                    ' without having rich-root also set')
 
968
                                        ' without having rich-root also set')
937
969
        base = self.make_repository('base', format=matching_format_name)
938
970
        repo.add_fallback_repository(base)
939
971
        # you can't stack on something with incompatible data
940
972
        bad_repo = self.make_repository('mismatch',
941
 
            format=mismatching_format_name)
 
973
                                        format=mismatching_format_name)
942
974
        e = self.assertRaises(errors.IncompatibleRepositories,
943
 
            repo.add_fallback_repository, bad_repo)
 
975
                              repo.add_fallback_repository, bad_repo)
944
976
        self.assertContainsRe(str(e),
945
 
            r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
946
 
            r'.*Repository.*/repo/.*\n'
947
 
            r'different serializers')
 
977
                              r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
 
978
                              r'.*Repository.*/repo/.*\n'
 
979
                              r'different serializers')
948
980
 
949
981
    def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
950
982
        base = self.make_branch_and_tree('base', format=self.get_format())
951
983
        base.commit('foo')
952
 
        referencing = self.make_branch_and_tree('repo', format=self.get_format())
953
 
        referencing.branch.repository.add_fallback_repository(base.branch.repository)
 
984
        referencing = self.make_branch_and_tree(
 
985
            'repo', format=self.get_format())
 
986
        referencing.branch.repository.add_fallback_repository(
 
987
            base.branch.repository)
954
988
        local_tree = referencing.branch.create_checkout('local')
955
989
        local_tree.commit('bar')
956
990
        new_instance = referencing.controldir.open_repository()
965
999
        base.commit('foo')
966
1000
        tree = self.make_branch_and_tree('repo', format=format)
967
1001
        tree.branch.repository.add_fallback_repository(base.branch.repository)
968
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
1002
        trans = tree.branch.repository.controldir.get_repository_transport(
 
1003
            None)
969
1004
        # This test could be a little cheaper by replacing the packs
970
1005
        # attribute on the repository to allow a different pack distribution
971
1006
        # and max packs policy - so we are checking the policy is honoured
985
1020
        tree = tree.controldir.open_workingtree()
986
1021
        check_result = tree.branch.repository.check(
987
1022
            [tree.branch.last_revision()])
988
 
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
1023
        nb_files = 5  # .pack, .rix, .iix, .tix, .six
989
1024
        if tree.branch.repository._format.supports_chks:
990
 
            nb_files += 1 # .cix
 
1025
            nb_files += 1  # .cix
991
1026
        # We should have 10 x nb_files files in the obsolete_packs directory.
992
1027
        obsolete_files = list(trans.list_dir('obsolete_packs'))
993
1028
        self.assertFalse('foo' in obsolete_files)
1016
1051
            ('add', ('', b'root-id', 'directory', None))],
1017
1052
            revision_id=b'A-id')
1018
1053
        builder.build_snapshot(
1019
 
                [b'A-id', b'ghost-id'], [],
1020
 
                revision_id=b'B-id', )
 
1054
            [b'A-id', b'ghost-id'], [],
 
1055
            revision_id=b'B-id', )
1021
1056
        builder.finish_series()
1022
1057
        repo = self.make_repository('target', format=self.get_format())
1023
1058
        b = builder.get_branch()
1103
1138
        tree = self.make_branch_and_tree('local', format=format)
1104
1139
        self.make_branch_and_tree('remote', format=format)
1105
1140
        remote_branch_url = self.smart_server.get_url() + 'remote'
1106
 
        remote_branch = controldir.ControlDir.open(remote_branch_url).open_branch()
 
1141
        remote_branch = controldir.ControlDir.open(
 
1142
            remote_branch_url).open_branch()
1107
1143
        # Make 9 local revisions, and push them one at a time to the remote
1108
1144
        # repo to produce 9 pack files.
1109
1145
        for x in range(9):
1113
1149
        self.hpss_calls = []
1114
1150
        tree.commit('commit triggering pack')
1115
1151
        tree.branch.push(remote_branch)
1116
 
        autopack_calls = len([call for call in self.hpss_calls if call ==
1117
 
            b'PackRepository.autopack'])
 
1152
        autopack_calls = len([call for call in self.hpss_calls if call
 
1153
                              == b'PackRepository.autopack'])
1118
1154
        streaming_calls = len([call for call in self.hpss_calls if call in
1119
 
            (b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
 
1155
                               (b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
1120
1156
        if autopack_calls:
1121
1157
            # Non streaming server
1122
1158
            self.assertEqual(1, autopack_calls)
1134
1170
    # these give the bzrdir canned format name, and the repository on-disk
1135
1171
    # format string
1136
1172
    scenarios_params = [
1137
 
         dict(format_name='pack-0.92',
1138
 
              format_string="Bazaar pack repository format 1 (needs bzr 0.92)\n",
1139
 
              format_supports_external_lookups=False,
1140
 
              index_class=GraphIndex),
1141
 
         dict(format_name='pack-0.92-subtree',
1142
 
              format_string="Bazaar pack repository format 1 "
1143
 
              "with subtree support (needs bzr 0.92)\n",
1144
 
              format_supports_external_lookups=False,
1145
 
              index_class=GraphIndex),
1146
 
         dict(format_name='1.6',
1147
 
              format_string="Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n",
1148
 
              format_supports_external_lookups=True,
1149
 
              index_class=GraphIndex),
1150
 
         dict(format_name='1.6.1-rich-root',
1151
 
              format_string="Bazaar RepositoryFormatKnitPack5RichRoot "
1152
 
                  "(bzr 1.6.1)\n",
1153
 
              format_supports_external_lookups=True,
1154
 
              index_class=GraphIndex),
1155
 
         dict(format_name='1.9',
1156
 
              format_string="Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n",
1157
 
              format_supports_external_lookups=True,
1158
 
              index_class=BTreeGraphIndex),
1159
 
         dict(format_name='1.9-rich-root',
1160
 
              format_string="Bazaar RepositoryFormatKnitPack6RichRoot "
1161
 
                  "(bzr 1.9)\n",
1162
 
              format_supports_external_lookups=True,
1163
 
              index_class=BTreeGraphIndex),
1164
 
         dict(format_name='2a',
1165
 
              format_string="Bazaar repository format 2a "
1166
 
                "(needs bzr 1.16 or later)\n",
1167
 
              format_supports_external_lookups=True,
1168
 
              index_class=BTreeGraphIndex),
1169
 
         ]
 
1173
        dict(format_name='pack-0.92',
 
1174
             format_string="Bazaar pack repository format 1 (needs bzr 0.92)\n",
 
1175
             format_supports_external_lookups=False,
 
1176
             index_class=GraphIndex),
 
1177
        dict(format_name='pack-0.92-subtree',
 
1178
             format_string="Bazaar pack repository format 1 "
 
1179
             "with subtree support (needs bzr 0.92)\n",
 
1180
             format_supports_external_lookups=False,
 
1181
             index_class=GraphIndex),
 
1182
        dict(format_name='1.6',
 
1183
             format_string="Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n",
 
1184
             format_supports_external_lookups=True,
 
1185
             index_class=GraphIndex),
 
1186
        dict(format_name='1.6.1-rich-root',
 
1187
             format_string="Bazaar RepositoryFormatKnitPack5RichRoot "
 
1188
             "(bzr 1.6.1)\n",
 
1189
             format_supports_external_lookups=True,
 
1190
             index_class=GraphIndex),
 
1191
        dict(format_name='1.9',
 
1192
             format_string="Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n",
 
1193
             format_supports_external_lookups=True,
 
1194
             index_class=BTreeGraphIndex),
 
1195
        dict(format_name='1.9-rich-root',
 
1196
             format_string="Bazaar RepositoryFormatKnitPack6RichRoot "
 
1197
             "(bzr 1.9)\n",
 
1198
             format_supports_external_lookups=True,
 
1199
             index_class=BTreeGraphIndex),
 
1200
        dict(format_name='2a',
 
1201
             format_string="Bazaar repository format 2a "
 
1202
             "(needs bzr 1.16 or later)\n",
 
1203
             format_supports_external_lookups=True,
 
1204
             index_class=BTreeGraphIndex),
 
1205
        ]
1170
1206
    # name of the scenario is the format name
1171
1207
    scenarios = [(s['format_name'], s) for s in scenarios_params]
1172
1208
    return tests.multiply_tests(basic_tests, scenarios, loader.suiteClass())