~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

Merge in real stacked repository work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1213
1213
 
1214
1214
    def get_format(self):
1215
1215
        return bzrdir.format_registry.make_bzrdir(
1216
 
            'development')
 
1216
            'development0')
1217
1217
 
1218
1218
    def check_format(self, t):
1219
1219
        self.assertEqualDiff(
1225
1225
 
1226
1226
    def get_format(self):
1227
1227
        return bzrdir.format_registry.make_bzrdir(
 
1228
            'development0-subtree')
 
1229
 
 
1230
    def check_format(self, t):
 
1231
        self.assertEqualDiff(
 
1232
            "Bazaar development format 0 with subtree support "
 
1233
            "(needs bzr.dev from before 1.3)\n",
 
1234
            t.get('format').read())
 
1235
 
 
1236
 
 
1237
class TestExternalDevelopment1(object):
 
1238
 
 
1239
    def test_error_mismatched_format(self):
 
1240
        # this first implementation uses the internal pack list from each
 
1241
        # repository and thus needs the same format in both sides.
 
1242
        base = self.make_repository('base', format='pack-0.92')
 
1243
        repo = self.make_repository('repo', format=self.get_format())
 
1244
        self.assertRaises(errors.IncompatibleRepositories,
 
1245
            repo.add_fallback_repository, base)
 
1246
 
 
1247
    def test_ensure_loaded_gets_other_repositories(self):
 
1248
        tree = self.make_branch_and_tree('base', format=self.get_format())
 
1249
        repo = self.make_repository('repo', format=self.get_format())
 
1250
        repo.add_fallback_repository(tree.branch.repository)
 
1251
        tree.commit('foo')
 
1252
        repo.lock_read()
 
1253
        self.addCleanup(repo.unlock)
 
1254
        repo._pack_collection.ensure_loaded()
 
1255
        packs_repo = repo._pack_collection.all_packs()
 
1256
        tree.lock_read()
 
1257
        self.addCleanup(tree.unlock)
 
1258
        packs_base = tree.branch.repository._pack_collection.all_packs()
 
1259
        self.assertEqual(packs_base, packs_repo)
 
1260
        self.assertEqual(1, len(packs_base))
 
1261
 
 
1262
    def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
 
1263
        base = self.make_branch_and_tree('base', format=self.get_format())
 
1264
        base.commit('foo')
 
1265
        referencing = self.make_branch_and_tree('repo', format=self.get_format())
 
1266
        referencing.branch.repository.add_fallback_repository(base.branch.repository)
 
1267
        referencing.commit('bar')
 
1268
        new_instance = referencing.bzrdir.open_repository()
 
1269
        new_instance.lock_read()
 
1270
        self.addCleanup(new_instance.unlock)
 
1271
        new_instance._pack_collection.ensure_loaded()
 
1272
        self.assertEqual(1, len(new_instance._pack_collection.all_packs()))
 
1273
 
 
1274
    def test_autopack_only_considers_main_repo_packs(self):
 
1275
        base = self.make_branch_and_tree('base', format=self.get_format())
 
1276
        base.commit('foo')
 
1277
        tree = self.make_branch_and_tree('repo', format=self.get_format())
 
1278
        tree.branch.repository.add_fallback_repository(base.branch.repository)
 
1279
        trans = tree.branch.repository.bzrdir.get_repository_transport(None)
 
1280
        # This test could be a little cheaper by replacing the packs
 
1281
        # attribute on the repository to allow a different pack distribution
 
1282
        # and max packs policy - so we are checking the policy is honoured
 
1283
        # in the test. But for now 11 commits is not a big deal in a single
 
1284
        # test.
 
1285
        for x in range(9):
 
1286
            tree.commit('commit %s' % x)
 
1287
        # there should be 9 packs:
 
1288
        index = GraphIndex(trans, 'pack-names', None)
 
1289
        self.assertEqual(9, len(list(index.iter_all_entries())))
 
1290
        # committing one more should coalesce to 1 of 10.
 
1291
        tree.commit('commit triggering pack')
 
1292
        index = GraphIndex(trans, 'pack-names', None)
 
1293
        self.assertEqual(1, len(list(index.iter_all_entries())))
 
1294
        # packing should not damage data
 
1295
        tree = tree.bzrdir.open_workingtree()
 
1296
        check_result = tree.branch.repository.check(
 
1297
            [tree.branch.last_revision()])
 
1298
        # We should have 50 (10x5) files in the obsolete_packs directory.
 
1299
        obsolete_files = list(trans.list_dir('obsolete_packs'))
 
1300
        self.assertFalse('foo' in obsolete_files)
 
1301
        self.assertFalse('bar' in obsolete_files)
 
1302
        self.assertEqual(50, len(obsolete_files))
 
1303
        # XXX: Todo check packs obsoleted correctly - old packs and indices
 
1304
        # in the obsolete_packs directory.
 
1305
        large_pack_name = list(index.iter_all_entries())[0][1][0]
 
1306
        # finally, committing again should not touch the large pack.
 
1307
        tree.commit('commit not triggering pack')
 
1308
        index = GraphIndex(trans, 'pack-names', None)
 
1309
        self.assertEqual(2, len(list(index.iter_all_entries())))
 
1310
        pack_names = [node[1][0] for node in index.iter_all_entries()]
 
1311
        self.assertTrue(large_pack_name in pack_names)
 
1312
 
 
1313
 
 
1314
class TestDevelopment1(TestKnitPackNoSubtrees, TestExternalDevelopment1):
 
1315
 
 
1316
    def get_format(self):
 
1317
        return bzrdir.format_registry.make_bzrdir(
 
1318
            'development')
 
1319
 
 
1320
    def check_format(self, t):
 
1321
        self.assertEqualDiff(
 
1322
            "Bazaar development format 1 (needs bzr.dev from before 1.3)\n",
 
1323
            t.get('format').read())
 
1324
 
 
1325
    def test_supports_external_lookups(self):
 
1326
        repo = self.make_repository('.', format=self.get_format())
 
1327
        self.assertTrue(repo._format.supports_external_lookups)
 
1328
 
 
1329
 
 
1330
class TestDevelopment1Subtree(TestKnitPackNoSubtrees, TestExternalDevelopment1):
 
1331
 
 
1332
    def get_format(self):
 
1333
        return bzrdir.format_registry.make_bzrdir(
1228
1334
            'development-subtree')
1229
1335
 
1230
1336
    def check_format(self, t):
1231
1337
        self.assertEqualDiff(
1232
 
            "Bazaar development format 0 with subtree support "
 
1338
            "Bazaar development format 1 with subtree support "
1233
1339
            "(needs bzr.dev from before 1.3)\n",
1234
1340
            t.get('format').read())
1235
1341
 
 
1342
    def test_supports_external_lookups(self):
 
1343
        repo = self.make_repository('.', format=self.get_format())
 
1344
        self.assertTrue(repo._format.supports_external_lookups)
 
1345
 
1236
1346
 
1237
1347
class TestRepositoryPackCollection(TestCaseWithTransport):
1238
1348
 
1396
1506
        name = packs.names()[0]
1397
1507
        pack_1 = packs.get_pack_by_name(name)
1398
1508
        # the pack should be correctly initialised
1399
 
        rev_index = GraphIndex(packs._index_transport, name + '.rix',
1400
 
            packs._names[name][0])
1401
 
        inv_index = GraphIndex(packs._index_transport, name + '.iix',
1402
 
            packs._names[name][1])
1403
 
        txt_index = GraphIndex(packs._index_transport, name + '.tix',
1404
 
            packs._names[name][2])
1405
 
        sig_index = GraphIndex(packs._index_transport, name + '.six',
1406
 
            packs._names[name][3])
 
1509
        sizes = packs._names[name][1]
 
1510
        rev_index = GraphIndex(packs._index_transport, name + '.rix', sizes[0])
 
1511
        inv_index = GraphIndex(packs._index_transport, name + '.iix', sizes[1])
 
1512
        txt_index = GraphIndex(packs._index_transport, name + '.tix', sizes[2])
 
1513
        sig_index = GraphIndex(packs._index_transport, name + '.six', sizes[3])
1407
1514
        self.assertEqual(pack_repo.ExistingPack(packs._pack_transport,
1408
1515
            name, rev_index, inv_index, txt_index, sig_index), pack_1)
1409
1516
        # and the same instance should be returned on successive calls.