266
273
self.assertEqual(expected_texts, unstacked_repo.texts.keys())
267
274
self.assertCanStreamRevision(unstacked_repo, 'third')
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.
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).
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
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
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'))
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(
340
new_stacked_branch.lock_read()
341
self.addCleanup(new_stacked_branch.unlock)
343
stacked_right_tree) = new_stacked_branch.repository.revision_trees(
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
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',
355
# If a (root-id,merge) text exists, it should be in the stacked
357
expected_texts.add(('root-id', 'merge'))
358
self.assertEqual(expected_texts, new_unstacked_repo.texts.keys())
359
self.assertCanStreamRevision(new_unstacked_repo, 'merge')
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')