/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
    def check_format(self, t):
98
98
        self.assertEqualDiff(
99
 
            self.format_string.encode('ascii'), # from scenario
 
99
            self.format_string.encode('ascii'),  # from scenario
100
100
            t.get('format').read())
101
101
 
102
102
    def assertHasNoKndx(self, t, knit_name):
120
120
        self.assertFalse(t.has('knits'))
121
121
        # revision-indexes file-container directory
122
122
        self.assertEqual([],
123
 
            list(self.index_class(t, 'pack-names', None).iter_all_entries()))
 
123
                         list(self.index_class(t, 'pack-names', None).iter_all_entries()))
124
124
        self.assertTrue(S_ISDIR(t.stat('packs').st_mode))
125
125
        self.assertTrue(S_ISDIR(t.stat('upload').st_mode))
126
126
        self.assertTrue(S_ISDIR(t.stat('indices').st_mode))
162
162
    def test_adding_revision_creates_pack_indices(self):
163
163
        format = self.get_format()
164
164
        tree = self.make_branch_and_tree('.', format=format)
165
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
165
        trans = tree.branch.repository.controldir.get_repository_transport(
 
166
            None)
166
167
        self.assertEqual([],
167
 
            list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
 
168
                         list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
168
169
        tree.commit('foobarbaz')
169
170
        index = self.index_class(trans, 'pack-names', None)
170
171
        index_nodes = list(index.iter_all_entries())
183
184
        tree1 = self.make_branch_and_tree('1', format=format)
184
185
        tree2 = self.make_branch_and_tree('2', format=format)
185
186
        tree1.branch.repository.fetch(tree2.branch.repository)
186
 
        trans = tree1.branch.repository.controldir.get_repository_transport(None)
 
187
        trans = tree1.branch.repository.controldir.get_repository_transport(
 
188
            None)
187
189
        self.assertEqual([],
188
 
            list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
 
190
                         list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
189
191
 
190
192
    def test_commit_across_pack_shape_boundary_autopacks(self):
191
193
        format = self.get_format()
192
194
        tree = self.make_branch_and_tree('.', format=format)
193
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
195
        trans = tree.branch.repository.controldir.get_repository_transport(
 
196
            None)
194
197
        # This test could be a little cheaper by replacing the packs
195
198
        # attribute on the repository to allow a different pack distribution
196
199
        # and max packs policy - so we are checking the policy is honoured
212
215
        tree = tree.controldir.open_workingtree()
213
216
        check_result = tree.branch.repository.check(
214
217
            [tree.branch.last_revision()])
215
 
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
218
        nb_files = 5  # .pack, .rix, .iix, .tix, .six
216
219
        if tree.branch.repository._format.supports_chks:
217
 
            nb_files += 1 # .cix
 
220
            nb_files += 1  # .cix
218
221
        # We should have 10 x nb_files files in the obsolete_packs directory.
219
222
        obsolete_files = list(trans.list_dir('obsolete_packs'))
220
223
        self.assertFalse('foo' in obsolete_files)
249
252
                    inv.root.revision = revid
250
253
                    repo.texts.add_lines((inv.root.file_id, revid), [], [])
251
254
                    rev = _mod_revision.Revision(timestamp=0, timezone=None,
252
 
                        committer="Foo Bar <foo@example.com>", message="Message",
253
 
                        revision_id=revid)
 
255
                                                 committer="Foo Bar <foo@example.com>", message="Message",
 
256
                                                 revision_id=revid)
254
257
                    rev.parent_ids = ()
255
258
                    repo.add_revision(revid, rev, inv=inv)
256
259
                except:
287
290
        repo = self.make_repository('repo')
288
291
        pack_coll = repo._pack_collection
289
292
        indices = {pack_coll.revision_index, pack_coll.inventory_index,
290
 
                pack_coll.text_index, pack_coll.signature_index}
 
293
                   pack_coll.text_index, pack_coll.signature_index}
291
294
        if pack_coll.chk_index is not None:
292
295
            indices.add(pack_coll.chk_index)
293
296
        combined_indices = set(idx.combined_index for idx in indices)
299
302
    def test_pack_after_two_commits_packs_everything(self):
300
303
        format = self.get_format()
301
304
        tree = self.make_branch_and_tree('.', format=format)
302
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
305
        trans = tree.branch.repository.controldir.get_repository_transport(
 
306
            None)
303
307
        tree.commit('start')
304
308
        tree.commit('more work')
305
309
        tree.branch.repository.pack()
351
355
        # tip->ancestor
352
356
        format = self.get_format()
353
357
        tree = self.make_branch_and_tree('.', format=format)
354
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
358
        trans = tree.branch.repository.controldir.get_repository_transport(
 
359
            None)
355
360
        tree.commit('start', rev_id=b'1')
356
361
        tree.commit('more work', rev_id=b'2')
357
362
        tree.branch.repository.pack()
388
393
 
389
394
    def _add_text(self, repo, fileid):
390
395
        """Add a text to the repository within a write group."""
391
 
        repo.texts.add_lines((fileid, b'samplerev+'+fileid), [],
392
 
            [b'smaplerev+'+fileid])
 
396
        repo.texts.add_lines((fileid, b'samplerev+' + fileid), [],
 
397
                             [b'smaplerev+' + fileid])
393
398
 
394
399
    def test_concurrent_writers_merge_new_packs(self):
395
400
        format = self.get_format()
431
436
                # Now both repositories should know about both names
432
437
                r1._pack_collection.ensure_loaded()
433
438
                r2._pack_collection.ensure_loaded()
434
 
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
 
439
                self.assertEqual(r1._pack_collection.names(),
 
440
                                 r2._pack_collection.names())
435
441
                self.assertEqual(2, len(r1._pack_collection.names()))
436
442
            finally:
437
443
                r2.unlock()
500
506
                # Now both repositories should now about just one name.
501
507
                r1._pack_collection.ensure_loaded()
502
508
                r2._pack_collection.ensure_loaded()
503
 
                self.assertEqual(r1._pack_collection.names(), r2._pack_collection.names())
 
509
                self.assertEqual(r1._pack_collection.names(),
 
510
                                 r2._pack_collection.names())
504
511
                self.assertEqual(1, len(r1._pack_collection.names()))
505
512
                self.assertFalse(name_to_drop in r1._pack_collection.names())
506
513
            finally:
521
528
                # Now r2 has read the pack-names file, but will need to reload
522
529
                # it after r1 has repacked
523
530
                tree.branch.repository.pack()
524
 
                self.assertEqual({rev2:(rev1,)}, r2.get_parent_map([rev2]))
 
531
                self.assertEqual({rev2: (rev1,)}, r2.get_parent_map([rev2]))
525
532
            finally:
526
533
                r2.unlock()
527
534
        finally:
542
549
                packed = False
543
550
                result = {}
544
551
                record_stream = r2.revisions.get_record_stream(keys,
545
 
                                    'unordered', False)
 
552
                                                               'unordered', False)
546
553
                for record in record_stream:
547
554
                    result[record.key] = record
548
555
                    if not packed:
573
580
                autopack_count = [0]
574
581
                r1 = tree.branch.repository
575
582
                orig = r1._pack_collection.pack_distribution
 
583
 
576
584
                def trigger_during_auto(*args, **kwargs):
577
585
                    ret = orig(*args, **kwargs)
578
586
                    if not autopack_count[0]:
621
629
        repo2 = repository.Repository.open('.')
622
630
        self.prepare_for_break_lock()
623
631
        repo2.break_lock()
624
 
        self.assertRaises(errors.LockBroken, repo._pack_collection._unlock_names)
 
632
        self.assertRaises(errors.LockBroken,
 
633
                          repo._pack_collection._unlock_names)
625
634
 
626
635
    def test_fetch_without_find_ghosts_ignores_ghosts(self):
627
636
        # we want two repositories at this point:
631
640
        # 'references' is present in both repositories, and 'tip' is present
632
641
        # just in has_ghost.
633
642
        # has_ghost       missing_ghost
634
 
        #------------------------------
 
643
        # ------------------------------
635
644
        # 'ghost'             -
636
645
        # 'references'    'references'
637
646
        # 'tip'               -
638
647
        # In this test we fetch 'tip' which should not fetch 'ghost'
639
648
        has_ghost = self.make_repository('has_ghost', format=self.get_format())
640
649
        missing_ghost = self.make_repository('missing_ghost',
641
 
            format=self.get_format())
 
650
                                             format=self.get_format())
642
651
 
643
652
        def add_commit(repo, revision_id, parent_ids):
644
653
            repo.lock_write()
667
676
        rev = missing_ghost.get_revision(b'tip')
668
677
        inv = missing_ghost.get_inventory(b'tip')
669
678
        self.assertRaises(errors.NoSuchRevision,
670
 
            missing_ghost.get_revision, b'ghost')
 
679
                          missing_ghost.get_revision, b'ghost')
671
680
        self.assertRaises(errors.NoSuchRevision,
672
 
            missing_ghost.get_inventory, b'ghost')
 
681
                          missing_ghost.get_inventory, b'ghost')
673
682
 
674
683
    def make_write_ready_repo(self):
675
684
        format = self.get_format()
713
722
    def test_supports_external_lookups(self):
714
723
        repo = self.make_repository('.', format=self.get_format())
715
724
        self.assertEqual(self.format_supports_external_lookups,
716
 
            repo._format.supports_external_lookups)
 
725
                         repo._format.supports_external_lookups)
717
726
 
718
727
    def _lock_write(self, write_lockable):
719
728
        """Lock write_lockable, add a cleanup and return the result.
720
 
        
 
729
 
721
730
        :param write_lockable: An object with a lock_write method.
722
731
        :return: The result of write_lockable.lock_write().
723
732
        """
766
775
        wg_tokens = repo.suspend_write_group()
767
776
        expected_pack_name = wg_tokens[0] + '.pack'
768
777
        expected_names = [wg_tokens[0] + ext for ext in
769
 
                            ('.rix', '.iix', '.tix', '.six')]
 
778
                          ('.rix', '.iix', '.tix', '.six')]
770
779
        if repo.chk_bytes is not None:
771
780
            expected_names.append(wg_tokens[0] + '.cix')
772
781
        expected_names.append(expected_pack_name)
794
803
        self.assertEqual([key], list(same_repo.chk_bytes.keys()))
795
804
        self.assertEqual(
796
805
            text, next(same_repo.chk_bytes.get_record_stream([key],
797
 
                'unordered', True)).get_bytes_as('fulltext'))
 
806
                                                             'unordered', True)).get_bytes_as('fulltext'))
798
807
        same_repo.abort_write_group()
799
808
        self.assertEqual([], list(same_repo.chk_bytes.keys()))
800
809
 
836
845
        same_repo.commit_write_group()
837
846
        expected_pack_name = wg_tokens[0] + '.pack'
838
847
        expected_names = [wg_tokens[0] + ext for ext in
839
 
                            ('.rix', '.iix', '.tix', '.six')]
 
848
                          ('.rix', '.iix', '.tix', '.six')]
840
849
        if repo.chk_bytes is not None:
841
850
            expected_names.append(wg_tokens[0] + '.cix')
842
851
        self.assertEqual(
872
881
    def setUp(self):
873
882
        if not self.format_supports_external_lookups:
874
883
            raise TestNotApplicable("%r doesn't support stacking"
875
 
                % (self.format_name,))
 
884
                                    % (self.format_name,))
876
885
        super(TestPackRepositoryStacking, self).setUp()
877
886
 
878
887
    def get_format(self):
909
918
        repo.add_fallback_repository(base)
910
919
        # you can't stack on something with incompatible data
911
920
        bad_repo = self.make_repository('mismatch',
912
 
            format=mismatching_format_name)
 
921
                                        format=mismatching_format_name)
913
922
        e = self.assertRaises(errors.IncompatibleRepositories,
914
 
            repo.add_fallback_repository, bad_repo)
 
923
                              repo.add_fallback_repository, bad_repo)
915
924
        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')
 
925
                              r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
 
926
                              r'.*Repository.*/repo/.*\n'
 
927
                              r'different rich-root support')
919
928
 
920
929
    def test_stack_checks_serializers_compatibility(self):
921
930
        repo = self.make_repository('repo', format=self.get_format())
933
942
                mismatching_format_name = 'pack-0.92-subtree'
934
943
            else:
935
944
                raise TestNotApplicable('No formats use non-v5 serializer'
936
 
                    ' without having rich-root also set')
 
945
                                        ' without having rich-root also set')
937
946
        base = self.make_repository('base', format=matching_format_name)
938
947
        repo.add_fallback_repository(base)
939
948
        # you can't stack on something with incompatible data
940
949
        bad_repo = self.make_repository('mismatch',
941
 
            format=mismatching_format_name)
 
950
                                        format=mismatching_format_name)
942
951
        e = self.assertRaises(errors.IncompatibleRepositories,
943
 
            repo.add_fallback_repository, bad_repo)
 
952
                              repo.add_fallback_repository, bad_repo)
944
953
        self.assertContainsRe(str(e),
945
 
            r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
946
 
            r'.*Repository.*/repo/.*\n'
947
 
            r'different serializers')
 
954
                              r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
 
955
                              r'.*Repository.*/repo/.*\n'
 
956
                              r'different serializers')
948
957
 
949
958
    def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
950
959
        base = self.make_branch_and_tree('base', format=self.get_format())
951
960
        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)
 
961
        referencing = self.make_branch_and_tree(
 
962
            'repo', format=self.get_format())
 
963
        referencing.branch.repository.add_fallback_repository(
 
964
            base.branch.repository)
954
965
        local_tree = referencing.branch.create_checkout('local')
955
966
        local_tree.commit('bar')
956
967
        new_instance = referencing.controldir.open_repository()
965
976
        base.commit('foo')
966
977
        tree = self.make_branch_and_tree('repo', format=format)
967
978
        tree.branch.repository.add_fallback_repository(base.branch.repository)
968
 
        trans = tree.branch.repository.controldir.get_repository_transport(None)
 
979
        trans = tree.branch.repository.controldir.get_repository_transport(
 
980
            None)
969
981
        # This test could be a little cheaper by replacing the packs
970
982
        # attribute on the repository to allow a different pack distribution
971
983
        # and max packs policy - so we are checking the policy is honoured
985
997
        tree = tree.controldir.open_workingtree()
986
998
        check_result = tree.branch.repository.check(
987
999
            [tree.branch.last_revision()])
988
 
        nb_files = 5 # .pack, .rix, .iix, .tix, .six
 
1000
        nb_files = 5  # .pack, .rix, .iix, .tix, .six
989
1001
        if tree.branch.repository._format.supports_chks:
990
 
            nb_files += 1 # .cix
 
1002
            nb_files += 1  # .cix
991
1003
        # We should have 10 x nb_files files in the obsolete_packs directory.
992
1004
        obsolete_files = list(trans.list_dir('obsolete_packs'))
993
1005
        self.assertFalse('foo' in obsolete_files)
1016
1028
            ('add', ('', b'root-id', 'directory', None))],
1017
1029
            revision_id=b'A-id')
1018
1030
        builder.build_snapshot(
1019
 
                [b'A-id', b'ghost-id'], [],
1020
 
                revision_id=b'B-id', )
 
1031
            [b'A-id', b'ghost-id'], [],
 
1032
            revision_id=b'B-id', )
1021
1033
        builder.finish_series()
1022
1034
        repo = self.make_repository('target', format=self.get_format())
1023
1035
        b = builder.get_branch()
1103
1115
        tree = self.make_branch_and_tree('local', format=format)
1104
1116
        self.make_branch_and_tree('remote', format=format)
1105
1117
        remote_branch_url = self.smart_server.get_url() + 'remote'
1106
 
        remote_branch = controldir.ControlDir.open(remote_branch_url).open_branch()
 
1118
        remote_branch = controldir.ControlDir.open(
 
1119
            remote_branch_url).open_branch()
1107
1120
        # Make 9 local revisions, and push them one at a time to the remote
1108
1121
        # repo to produce 9 pack files.
1109
1122
        for x in range(9):
1113
1126
        self.hpss_calls = []
1114
1127
        tree.commit('commit triggering pack')
1115
1128
        tree.branch.push(remote_branch)
1116
 
        autopack_calls = len([call for call in self.hpss_calls if call ==
1117
 
            b'PackRepository.autopack'])
 
1129
        autopack_calls = len([call for call in self.hpss_calls if call
 
1130
                              == b'PackRepository.autopack'])
1118
1131
        streaming_calls = len([call for call in self.hpss_calls if call in
1119
 
            (b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
 
1132
                               (b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
1120
1133
        if autopack_calls:
1121
1134
            # Non streaming server
1122
1135
            self.assertEqual(1, autopack_calls)
1134
1147
    # these give the bzrdir canned format name, and the repository on-disk
1135
1148
    # format string
1136
1149
    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
 
         ]
 
1150
        dict(format_name='pack-0.92',
 
1151
             format_string="Bazaar pack repository format 1 (needs bzr 0.92)\n",
 
1152
             format_supports_external_lookups=False,
 
1153
             index_class=GraphIndex),
 
1154
        dict(format_name='pack-0.92-subtree',
 
1155
             format_string="Bazaar pack repository format 1 "
 
1156
             "with subtree support (needs bzr 0.92)\n",
 
1157
             format_supports_external_lookups=False,
 
1158
             index_class=GraphIndex),
 
1159
        dict(format_name='1.6',
 
1160
             format_string="Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n",
 
1161
             format_supports_external_lookups=True,
 
1162
             index_class=GraphIndex),
 
1163
        dict(format_name='1.6.1-rich-root',
 
1164
             format_string="Bazaar RepositoryFormatKnitPack5RichRoot "
 
1165
             "(bzr 1.6.1)\n",
 
1166
             format_supports_external_lookups=True,
 
1167
             index_class=GraphIndex),
 
1168
        dict(format_name='1.9',
 
1169
             format_string="Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n",
 
1170
             format_supports_external_lookups=True,
 
1171
             index_class=BTreeGraphIndex),
 
1172
        dict(format_name='1.9-rich-root',
 
1173
             format_string="Bazaar RepositoryFormatKnitPack6RichRoot "
 
1174
             "(bzr 1.9)\n",
 
1175
             format_supports_external_lookups=True,
 
1176
             index_class=BTreeGraphIndex),
 
1177
        dict(format_name='2a',
 
1178
             format_string="Bazaar repository format 2a "
 
1179
             "(needs bzr 1.16 or later)\n",
 
1180
             format_supports_external_lookups=True,
 
1181
             index_class=BTreeGraphIndex),
 
1182
        ]
1170
1183
    # name of the scenario is the format name
1171
1184
    scenarios = [(s['format_name'], s) for s in scenarios_params]
1172
1185
    return tests.multiply_tests(basic_tests, scenarios, loader.suiteClass())