~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-09 13:58:59 UTC
  • mfrom: (3533.2.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080709135859-wq3r1d1fjcafelgw
(jam) (bug #243536) tsort.merge_sorted() can ignore ghosts in the
        mainline history passed in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1106
1106
 
1107
1107
    def get_format(self):
1108
1108
        return bzrdir.format_registry.make_bzrdir(
1109
 
            'development0')
 
1109
            'development')
1110
1110
 
1111
1111
    def check_format(self, t):
1112
1112
        self.assertEqualDiff(
1118
1118
 
1119
1119
    def get_format(self):
1120
1120
        return bzrdir.format_registry.make_bzrdir(
1121
 
            'development0-subtree')
 
1121
            'development-subtree')
1122
1122
 
1123
1123
    def check_format(self, t):
1124
1124
        self.assertEqualDiff(
1127
1127
            t.get('format').read())
1128
1128
 
1129
1129
 
1130
 
class TestExternalDevelopment1(object):
1131
 
 
1132
 
    # mixin class for testing stack-supporting development formats
1133
 
 
1134
 
    def test_compatible_cross_formats(self):
1135
 
        # early versions of the packing code relied on pack internals to
1136
 
        # stack, but the current version should be able to stack on any
1137
 
        # format.
1138
 
        repo = self.make_repository('repo', format=self.get_format())
1139
 
        if repo.supports_rich_root():
1140
 
            # can only stack on repositories that have compatible internal
1141
 
            # metadata
1142
 
            matching_format_name = 'pack-0.92-subtree'
1143
 
            mismatching_format_name = 'pack-0.92'
1144
 
        else:
1145
 
            matching_format_name = 'pack-0.92'
1146
 
            mismatching_format_name = 'pack-0.92-subtree'
1147
 
        base = self.make_repository('base', format=matching_format_name)
1148
 
        repo.add_fallback_repository(base)
1149
 
        # you can't stack on something with incompatible data
1150
 
        bad_repo = self.make_repository('mismatch',
1151
 
            format=mismatching_format_name)
1152
 
        self.assertRaises(errors.IncompatibleRepositories,
1153
 
            repo.add_fallback_repository, bad_repo)
1154
 
 
1155
 
    def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
1156
 
        base = self.make_branch_and_tree('base', format=self.get_format())
1157
 
        base.commit('foo')
1158
 
        referencing = self.make_branch_and_tree('repo', format=self.get_format())
1159
 
        referencing.branch.repository.add_fallback_repository(base.branch.repository)
1160
 
        referencing.commit('bar')
1161
 
        new_instance = referencing.bzrdir.open_repository()
1162
 
        new_instance.lock_read()
1163
 
        self.addCleanup(new_instance.unlock)
1164
 
        new_instance._pack_collection.ensure_loaded()
1165
 
        self.assertEqual(1, len(new_instance._pack_collection.all_packs()))
1166
 
 
1167
 
    def test_autopack_only_considers_main_repo_packs(self):
1168
 
        base = self.make_branch_and_tree('base', format=self.get_format())
1169
 
        base.commit('foo')
1170
 
        tree = self.make_branch_and_tree('repo', format=self.get_format())
1171
 
        tree.branch.repository.add_fallback_repository(base.branch.repository)
1172
 
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
1173
 
        # This test could be a little cheaper by replacing the packs
1174
 
        # attribute on the repository to allow a different pack distribution
1175
 
        # and max packs policy - so we are checking the policy is honoured
1176
 
        # in the test. But for now 11 commits is not a big deal in a single
1177
 
        # test.
1178
 
        for x in range(9):
1179
 
            tree.commit('commit %s' % x)
1180
 
        # there should be 9 packs:
1181
 
        index = GraphIndex(trans, 'pack-names', None)
1182
 
        self.assertEqual(9, len(list(index.iter_all_entries())))
1183
 
        # committing one more should coalesce to 1 of 10.
1184
 
        tree.commit('commit triggering pack')
1185
 
        index = GraphIndex(trans, 'pack-names', None)
1186
 
        self.assertEqual(1, len(list(index.iter_all_entries())))
1187
 
        # packing should not damage data
1188
 
        tree = tree.bzrdir.open_workingtree()
1189
 
        check_result = tree.branch.repository.check(
1190
 
            [tree.branch.last_revision()])
1191
 
        # We should have 50 (10x5) files in the obsolete_packs directory.
1192
 
        obsolete_files = list(trans.list_dir('obsolete_packs'))
1193
 
        self.assertFalse('foo' in obsolete_files)
1194
 
        self.assertFalse('bar' in obsolete_files)
1195
 
        self.assertEqual(50, len(obsolete_files))
1196
 
        # XXX: Todo check packs obsoleted correctly - old packs and indices
1197
 
        # in the obsolete_packs directory.
1198
 
        large_pack_name = list(index.iter_all_entries())[0][1][0]
1199
 
        # finally, committing again should not touch the large pack.
1200
 
        tree.commit('commit not triggering pack')
1201
 
        index = GraphIndex(trans, 'pack-names', None)
1202
 
        self.assertEqual(2, len(list(index.iter_all_entries())))
1203
 
        pack_names = [node[1][0] for node in index.iter_all_entries()]
1204
 
        self.assertTrue(large_pack_name in pack_names)
1205
 
 
1206
 
 
1207
 
class TestDevelopment1(TestKnitPackNoSubtrees, TestExternalDevelopment1):
1208
 
 
1209
 
    def get_format(self):
1210
 
        return bzrdir.format_registry.make_bzrdir(
1211
 
            'development')
1212
 
 
1213
 
    def check_format(self, t):
1214
 
        self.assertEqualDiff(
1215
 
            "Bazaar development format 1 (needs bzr.dev from before 1.6)\n",
1216
 
            t.get('format').read())
1217
 
 
1218
 
    def test_supports_external_lookups(self):
1219
 
        repo = self.make_repository('.', format=self.get_format())
1220
 
        self.assertTrue(repo._format.supports_external_lookups)
1221
 
 
1222
 
 
1223
 
class TestDevelopment1Subtree(TestKnitPackNoSubtrees, TestExternalDevelopment1):
1224
 
 
1225
 
    def get_format(self):
1226
 
        return bzrdir.format_registry.make_bzrdir(
1227
 
            'development-subtree')
1228
 
 
1229
 
    def check_format(self, t):
1230
 
        self.assertEqualDiff(
1231
 
            "Bazaar development format 1 with subtree support "
1232
 
            "(needs bzr.dev from before 1.6)\n",
1233
 
            t.get('format').read())
1234
 
 
1235
 
    def test_supports_external_lookups(self):
1236
 
        repo = self.make_repository('.', format=self.get_format())
1237
 
        self.assertTrue(repo._format.supports_external_lookups)
1238
 
 
1239
 
 
1240
1130
class TestRepositoryPackCollection(TestCaseWithTransport):
1241
1131
 
1242
1132
    def get_format(self):
1399
1289
        name = packs.names()[0]
1400
1290
        pack_1 = packs.get_pack_by_name(name)
1401
1291
        # the pack should be correctly initialised
1402
 
        sizes = packs._names[name]
1403
 
        rev_index = GraphIndex(packs._index_transport, name + '.rix', sizes[0])
1404
 
        inv_index = GraphIndex(packs._index_transport, name + '.iix', sizes[1])
1405
 
        txt_index = GraphIndex(packs._index_transport, name + '.tix', sizes[2])
1406
 
        sig_index = GraphIndex(packs._index_transport, name + '.six', sizes[3])
 
1292
        rev_index = GraphIndex(packs._index_transport, name + '.rix',
 
1293
            packs._names[name][0])
 
1294
        inv_index = GraphIndex(packs._index_transport, name + '.iix',
 
1295
            packs._names[name][1])
 
1296
        txt_index = GraphIndex(packs._index_transport, name + '.tix',
 
1297
            packs._names[name][2])
 
1298
        sig_index = GraphIndex(packs._index_transport, name + '.six',
 
1299
            packs._names[name][3])
1407
1300
        self.assertEqual(pack_repo.ExistingPack(packs._pack_transport,
1408
1301
            name, rev_index, inv_index, txt_index, sig_index), pack_1)
1409
1302
        # and the same instance should be returned on successive calls.