/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 bzrlib/tests/per_interrepository/test_fetch.py

  • Committer: Aaron Bentley
  • Date: 2009-09-29 04:40:55 UTC
  • mfrom: (4717 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4718.
  • Revision ID: aaron@aaronbentley.com-20090929044055-e9jtpmz6eyut711h
Merged bzr.dev into fix_get_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import sys
19
19
 
20
 
import bzrlib
21
20
from bzrlib import (
22
21
    errors,
23
22
    inventory,
46
45
    )
47
46
 
48
47
 
 
48
 
49
49
class TestInterRepository(TestCaseWithInterRepository):
50
50
 
 
51
    def disable_commit_write_group_paranoia(self, repo):
 
52
        pack_coll = getattr(repo, '_pack_collection', None)
 
53
        if pack_coll is not None:
 
54
            # Monkey-patch the pack collection instance to allow storing
 
55
            # incomplete revisions.
 
56
            pack_coll._check_new_inventories = lambda: []
 
57
 
51
58
    def test_fetch(self):
52
59
        tree_a = self.make_branch_and_tree('a')
53
60
        self.build_tree(['a/foo'])
266
273
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
267
274
        self.assertCanStreamRevision(unstacked_repo, 'third')
268
275
 
 
276
    def test_fetch_from_stacked_to_stacked_copies_parent_inventories(self):
 
277
        """Fetch from a stacked branch copies inventories for parents of
 
278
        revisions at the stacking boundary.
 
279
 
 
280
        Specifically, fetch will copy the parent inventories from the
 
281
        source for which the corresponding revisions are not present.  This
 
282
        will happen even when the source repository has no fallbacks configured
 
283
        (as is the case during upgrade).
 
284
        """
 
285
        if not self.repository_format.supports_external_lookups:
 
286
            raise TestNotApplicable("Need stacking support in the source.")
 
287
        if not self.repository_format_to.supports_external_lookups:
 
288
            raise TestNotApplicable("Need stacking support in the target.")
 
289
        builder = self.make_branch_builder('branch')
 
290
        builder.start_series()
 
291
        builder.build_snapshot('base', None, [
 
292
            ('add', ('', 'root-id', 'directory', '')),
 
293
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
294
        builder.build_snapshot('left', ['base'], [
 
295
            ('modify', ('file-id', 'left content\n'))])
 
296
        builder.build_snapshot('right', ['base'], [
 
297
            ('modify', ('file-id', 'right content\n'))])
 
298
        builder.build_snapshot('merge', ['left', 'right'], [
 
299
            ('modify', ('file-id', 'left and right content\n'))])
 
300
        builder.finish_series()
 
301
        branch = builder.get_branch()
 
302
        repo = self.make_repository('old-trunk')
 
303
        # Make a pair of equivalent trunk repos in the from and to formats.
 
304
        old_trunk = repo.bzrdir.create_branch()
 
305
        old_trunk.repository.fetch(branch.repository, 'left')
 
306
        old_trunk.repository.fetch(branch.repository, 'right')
 
307
        repo = self.make_to_repository('new-trunk')
 
308
        new_trunk = repo.bzrdir.create_branch()
 
309
        new_trunk.repository.fetch(branch.repository, 'left')
 
310
        new_trunk.repository.fetch(branch.repository, 'right')
 
311
        # Make the source; a repo stacked on old_trunk contained just the data
 
312
        # for 'merge'.
 
313
        repo = self.make_repository('old-stacked')
 
314
        old_stacked_branch = repo.bzrdir.create_branch()
 
315
        old_stacked_branch.set_stacked_on_url(old_trunk.base)
 
316
        old_stacked_branch.repository.fetch(branch.repository, 'merge')
 
317
        # Make the target, a repo stacked on new_trunk.
 
318
        repo = self.make_to_repository('new-stacked')
 
319
        new_stacked_branch = repo.bzrdir.create_branch()
 
320
        new_stacked_branch.set_stacked_on_url(new_trunk.base)
 
321
        old_unstacked_repo = old_stacked_branch.bzrdir.open_repository()
 
322
        new_unstacked_repo = new_stacked_branch.bzrdir.open_repository()
 
323
        # Reopen the source and target repos without any fallbacks, and fetch
 
324
        # 'merge'.
 
325
        new_unstacked_repo.fetch(old_unstacked_repo, 'merge')
 
326
        # Now check the results.  new_unstacked_repo should contain all the
 
327
        # data necessary to stream 'merge' (i.e. the parent inventories).
 
328
        new_unstacked_repo.lock_read()
 
329
        self.addCleanup(new_unstacked_repo.unlock)
 
330
        self.assertFalse(new_unstacked_repo.has_revision('left'))
 
331
        self.assertFalse(new_unstacked_repo.has_revision('right'))
 
332
        self.assertEqual(
 
333
            set([('left',), ('right',), ('merge',)]),
 
334
            new_unstacked_repo.inventories.keys())
 
335
        # And the basis inventories have been copied correctly
 
336
        new_trunk.lock_read()
 
337
        self.addCleanup(new_trunk.unlock)
 
338
        left_tree, right_tree = new_trunk.repository.revision_trees(
 
339
            ['left', 'right'])
 
340
        new_stacked_branch.lock_read()
 
341
        self.addCleanup(new_stacked_branch.unlock)
 
342
        (stacked_left_tree,
 
343
         stacked_right_tree) = new_stacked_branch.repository.revision_trees(
 
344
            ['left', 'right'])
 
345
        self.assertEqual(left_tree.inventory, stacked_left_tree.inventory)
 
346
        self.assertEqual(right_tree.inventory, stacked_right_tree.inventory)
 
347
        # Finally, it's not enough to see that the basis inventories are
 
348
        # present.  The texts introduced in merge (and only those) should be
 
349
        # present, and also generating a stream should succeed without blowing
 
350
        # up.
 
351
        self.assertTrue(new_unstacked_repo.has_revision('merge'))
 
352
        expected_texts = set([('file-id', 'merge')])
 
353
        if new_stacked_branch.repository.texts.get_parent_map([('root-id',
 
354
            'merge')]):
 
355
            # If a (root-id,merge) text exists, it should be in the stacked
 
356
            # repo.
 
357
            expected_texts.add(('root-id', 'merge'))
 
358
        self.assertEqual(expected_texts, new_unstacked_repo.texts.keys())
 
359
        self.assertCanStreamRevision(new_unstacked_repo, 'merge')
 
360
 
269
361
    def test_fetch_missing_basis_text(self):
270
362
        """If fetching a delta, we should die if a basis is not present."""
271
363
        tree = self.make_branch_and_tree('tree')
281
373
        to_repo.lock_write()
282
374
        try:
283
375
            to_repo.start_write_group()
284
 
            inv = tree.branch.repository.get_inventory('rev-one')
285
 
            to_repo.add_inventory('rev-one', inv, [])
286
 
            rev = tree.branch.repository.get_revision('rev-one')
287
 
            to_repo.add_revision('rev-one', rev, inv=inv)
288
 
            to_repo.commit_write_group()
 
376
            try:
 
377
                inv = tree.branch.repository.get_inventory('rev-one')
 
378
                to_repo.add_inventory('rev-one', inv, [])
 
379
                rev = tree.branch.repository.get_revision('rev-one')
 
380
                to_repo.add_revision('rev-one', rev, inv=inv)
 
381
                self.disable_commit_write_group_paranoia(to_repo)
 
382
                to_repo.commit_write_group()
 
383
            except:
 
384
                to_repo.abort_write_group(suppress_errors=True)
 
385
                raise
289
386
        finally:
290
387
            to_repo.unlock()
291
388
 
340
437
        source_tree.add(['id'], ['id'])
341
438
        source_tree.commit('a', rev_id='a')
342
439
        # now we manually insert a revision with an inventory referencing
343
 
        # 'id' at revision 'b', but we do not insert revision b.
 
440
        # file 'id' at revision 'b', but we do not insert revision b.
344
441
        # this should ensure that the new versions of files are being checked
345
442
        # for during pull operations
346
443
        inv = source.get_inventory('a')
358
455
                       revision_id='b')
359
456
        rev.parent_ids = ['a']
360
457
        source.add_revision('b', rev)
 
458
        self.disable_commit_write_group_paranoia(source)
361
459
        source.commit_write_group()
362
460
        self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
363
461
        self.assertFalse(target.has_revision('b'))