~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interrepository/test_fetch.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-25 01:25:57 UTC
  • mfrom: (4642 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4657.
  • Revision ID: andrew.bennetts@canonical.com-20090825012557-1ku5o09nv3ra9n12
Merge from bzr.dev.

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,
266
265
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
267
266
        self.assertCanStreamRevision(unstacked_repo, 'third')
268
267
 
 
268
    def test_fetch_from_stacked_to_stacked_copies_parent_inventories(self):
 
269
        """Fetch from a stacked branch copies inventories for parents of
 
270
        revisions at the stacking boundary.
 
271
 
 
272
        Specifically, fetch will copy the parent inventories from the
 
273
        source for which the corresponding revisions are not present.  This
 
274
        will happen even when the source repository has no fallbacks configured
 
275
        (as is the case during upgrade).
 
276
        """
 
277
        if not self.repository_format.supports_external_lookups:
 
278
            raise TestNotApplicable("Need stacking support in the source.")
 
279
        if not self.repository_format_to.supports_external_lookups:
 
280
            raise TestNotApplicable("Need stacking support in the target.")
 
281
        builder = self.make_branch_builder('branch')
 
282
        builder.start_series()
 
283
        builder.build_snapshot('base', None, [
 
284
            ('add', ('', 'root-id', 'directory', '')),
 
285
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
286
        builder.build_snapshot('left', ['base'], [
 
287
            ('modify', ('file-id', 'left content\n'))])
 
288
        builder.build_snapshot('right', ['base'], [
 
289
            ('modify', ('file-id', 'right content\n'))])
 
290
        builder.build_snapshot('merge', ['left', 'right'], [
 
291
            ('modify', ('file-id', 'left and right content\n'))])
 
292
        builder.finish_series()
 
293
        branch = builder.get_branch()
 
294
        repo = self.make_repository('old-trunk')
 
295
        # Make a pair of equivalent trunk repos in the from and to formats.
 
296
        old_trunk = repo.bzrdir.create_branch()
 
297
        old_trunk.repository.fetch(branch.repository, 'left')
 
298
        old_trunk.repository.fetch(branch.repository, 'right')
 
299
        repo = self.make_to_repository('new-trunk')
 
300
        new_trunk = repo.bzrdir.create_branch()
 
301
        new_trunk.repository.fetch(branch.repository, 'left')
 
302
        new_trunk.repository.fetch(branch.repository, 'right')
 
303
        # Make the source; a repo stacked on old_trunk contained just the data
 
304
        # for 'merge'.
 
305
        repo = self.make_repository('old-stacked')
 
306
        old_stacked_branch = repo.bzrdir.create_branch()
 
307
        old_stacked_branch.set_stacked_on_url(old_trunk.base)
 
308
        old_stacked_branch.repository.fetch(branch.repository, 'merge')
 
309
        # Make the target, a repo stacked on new_trunk.
 
310
        repo = self.make_to_repository('new-stacked')
 
311
        new_stacked_branch = repo.bzrdir.create_branch()
 
312
        new_stacked_branch.set_stacked_on_url(new_trunk.base)
 
313
        old_unstacked_repo = old_stacked_branch.bzrdir.open_repository()
 
314
        new_unstacked_repo = new_stacked_branch.bzrdir.open_repository()
 
315
        # Reopen the source and target repos without any fallbacks, and fetch
 
316
        # 'merge'.
 
317
        new_unstacked_repo.fetch(old_unstacked_repo, 'merge')
 
318
        # Now check the results.  new_unstacked_repo should contain all the
 
319
        # data necessary to stream 'merge' (i.e. the parent inventories).
 
320
        new_unstacked_repo.lock_read()
 
321
        self.addCleanup(new_unstacked_repo.unlock)
 
322
        self.assertFalse(new_unstacked_repo.has_revision('left'))
 
323
        self.assertFalse(new_unstacked_repo.has_revision('right'))
 
324
        self.assertEqual(
 
325
            set([('left',), ('right',), ('merge',)]),
 
326
            new_unstacked_repo.inventories.keys())
 
327
        # And the basis inventories have been copied correctly
 
328
        new_trunk.lock_read()
 
329
        self.addCleanup(new_trunk.unlock)
 
330
        left_tree, right_tree = new_trunk.repository.revision_trees(
 
331
            ['left', 'right'])
 
332
        new_stacked_branch.lock_read()
 
333
        self.addCleanup(new_stacked_branch.unlock)
 
334
        (stacked_left_tree,
 
335
         stacked_right_tree) = new_stacked_branch.repository.revision_trees(
 
336
            ['left', 'right'])
 
337
        self.assertEqual(left_tree.inventory, stacked_left_tree.inventory)
 
338
        self.assertEqual(right_tree.inventory, stacked_right_tree.inventory)
 
339
        # Finally, it's not enough to see that the basis inventories are
 
340
        # present.  The texts introduced in merge (and only those) should be
 
341
        # present, and also generating a stream should succeed without blowing
 
342
        # up.
 
343
        self.assertTrue(new_unstacked_repo.has_revision('merge'))
 
344
        expected_texts = set([('file-id', 'merge')])
 
345
        if new_stacked_branch.repository.texts.get_parent_map([('root-id',
 
346
            'merge')]):
 
347
            # If a (root-id,merge) text exists, it should be in the stacked
 
348
            # repo.
 
349
            expected_texts.add(('root-id', 'merge'))
 
350
        self.assertEqual(expected_texts, new_unstacked_repo.texts.keys())
 
351
        self.assertCanStreamRevision(new_unstacked_repo, 'merge')
 
352
 
269
353
    def test_fetch_missing_basis_text(self):
270
354
        """If fetching a delta, we should die if a basis is not present."""
271
355
        tree = self.make_branch_and_tree('tree')