284
292
set(), reopened_repo.get_missing_parent_inventories())
285
293
reopened_repo.abort_write_group()
295
def test_get_missing_parent_inventories_check(self):
296
builder = self.make_branch_builder('test')
297
builder.build_snapshot('A-id', ['ghost-parent-id'], [
298
('add', ('', 'root-id', 'directory', None)),
299
('add', ('file', 'file-id', 'file', 'content\n'))],
300
allow_leftmost_as_ghost=True)
301
b = builder.get_branch()
303
self.addCleanup(b.unlock)
304
repo = self.make_repository('test-repo')
306
self.addCleanup(repo.unlock)
307
repo.start_write_group()
308
self.addCleanup(repo.abort_write_group)
309
# Now, add the objects manually
310
text_keys = [('file-id', 'A-id')]
311
if repo.supports_rich_root():
312
text_keys.append(('root-id', 'A-id'))
313
# Directly add the texts, inventory, and revision object for 'A-id'
314
repo.texts.insert_record_stream(b.repository.texts.get_record_stream(
315
text_keys, 'unordered', True))
316
repo.add_revision('A-id', b.repository.get_revision('A-id'),
317
b.repository.get_inventory('A-id'))
318
get_missing = repo.get_missing_parent_inventories
319
if repo._format.supports_external_lookups:
320
self.assertEqual(set([('inventories', 'ghost-parent-id')]),
321
get_missing(check_for_missing_texts=False))
322
self.assertEqual(set(), get_missing(check_for_missing_texts=True))
323
self.assertEqual(set(), get_missing())
325
# If we don't support external lookups, we always return empty
326
self.assertEqual(set(), get_missing(check_for_missing_texts=False))
327
self.assertEqual(set(), get_missing(check_for_missing_texts=True))
328
self.assertEqual(set(), get_missing())
330
def test_insert_stream_passes_resume_info(self):
331
repo = self.make_repository('test-repo')
332
if not repo._format.supports_external_lookups:
333
raise TestNotApplicable('only valid in resumable repos')
334
# log calls to get_missing_parent_inventories, so that we can assert it
335
# is called with the correct parameters
337
orig = repo.get_missing_parent_inventories
338
def get_missing(check_for_missing_texts=True):
339
call_log.append(check_for_missing_texts)
340
return orig(check_for_missing_texts=check_for_missing_texts)
341
repo.get_missing_parent_inventories = get_missing
343
self.addCleanup(repo.unlock)
344
sink = repo._get_sink()
345
sink.insert_stream((), repo._format, [])
346
self.assertEqual([False], call_log)
348
repo.start_write_group()
349
# We need to insert something, or suspend_write_group won't actually
351
repo.texts.insert_record_stream([versionedfile.FulltextContentFactory(
352
('file-id', 'rev-id'), (), None, 'lines\n')])
353
tokens = repo.suspend_write_group()
354
self.assertNotEqual([], tokens)
355
sink.insert_stream((), repo._format, tokens)
356
self.assertEqual([True], call_log)
288
359
class TestResumeableWriteGroup(TestCaseWithRepository):
518
589
source_repo.start_write_group()
519
590
key_base = ('file-id', 'base')
520
591
key_delta = ('file-id', 'delta')
521
source_repo.texts.add_lines(key_base, (), ['lines\n'])
522
source_repo.texts.add_lines(
523
key_delta, (key_base,), ['more\n', 'lines\n'])
593
yield versionedfile.FulltextContentFactory(
594
key_base, (), None, 'lines\n')
595
yield versionedfile.FulltextContentFactory(
596
key_delta, (key_base,), None, 'more\nlines\n')
597
source_repo.texts.insert_record_stream(text_stream())
524
598
source_repo.commit_write_group()
525
599
return source_repo
536
610
stream = source_repo.texts.get_record_stream(
537
611
[key_delta], 'unordered', False)
538
612
repo.texts.insert_record_stream(stream)
539
# It's not commitable due to the missing compression parent.
541
errors.BzrCheckError, repo.commit_write_group)
613
# It's either not commitable due to the missing compression parent, or
614
# the stacked location has already filled in the fulltext.
616
repo.commit_write_group()
617
except errors.BzrCheckError:
618
# It refused to commit because we have a missing parent
621
same_repo = self.reopen_repo(repo)
622
same_repo.lock_read()
623
record = same_repo.texts.get_record_stream([key_delta],
624
'unordered', True).next()
625
self.assertEqual('more\nlines\n', record.get_bytes_as('fulltext'))
542
627
# Merely suspending and resuming doesn't make it commitable either.
543
628
wg_tokens = repo.suspend_write_group()
544
629
same_repo = self.reopen_repo(repo)
570
655
same_repo.texts.insert_record_stream(stream)
571
656
# Just like if we'd added that record without a suspend/resume cycle,
572
657
# commit_write_group fails.
574
errors.BzrCheckError, same_repo.commit_write_group)
659
same_repo.commit_write_group()
660
except errors.BzrCheckError:
663
# If the commit_write_group didn't fail, that is because the
664
# insert_record_stream already gave it a fulltext.
665
same_repo = self.reopen_repo(repo)
666
same_repo.lock_read()
667
record = same_repo.texts.get_record_stream([key_delta],
668
'unordered', True).next()
669
self.assertEqual('more\nlines\n', record.get_bytes_as('fulltext'))
575
671
same_repo.abort_write_group()
577
673
def test_add_missing_parent_after_resume(self):