321
322
# self.assertEqualDiff('', t.get('lock').read())
322
323
self.assertTrue(S_ISDIR(t.stat('knits').st_mode))
323
324
self.check_knits(t)
325
# Check per-file knits.
326
branch = control.create_branch()
327
tree = control.create_workingtree()
328
tree.add(['foo'], ['Nasty-IdC:'], ['file'])
329
tree.put_file_bytes_non_atomic('Nasty-IdC:', '')
330
tree.commit('1st post', rev_id='foo')
331
self.assertHasKnit(t, 'knits/e8/%254easty-%2549d%2543%253a',
332
'\nfoo fulltext 0 81 :')
325
def assertHasKnit(self, t, knit_name):
334
def assertHasKnit(self, t, knit_name, extra_content=''):
326
335
"""Assert that knit_name exists on t."""
327
self.assertEqualDiff('# bzr knit index 8\n',
336
self.assertEqualDiff('# bzr knit index 8\n' + extra_content,
328
337
t.get(knit_name + '.kndx').read())
330
self.assertTrue(t.has(knit_name + '.knit'))
332
339
def check_knits(self, t):
333
340
"""check knit content for a repository."""
377
384
self.assertTrue(S_ISDIR(t.stat('knits').st_mode))
378
385
self.check_knits(t)
380
def test_exposed_versioned_files_are_marked_dirty(self):
381
format = bzrdir.BzrDirMetaFormat1()
382
format.repository_format = knitrepo.RepositoryFormatKnit1()
383
repo = self.make_repository('.', format=format)
385
inv = repo.get_inventory_weave()
387
self.assertRaises(errors.OutSideTransaction,
388
inv.add_lines, 'foo', [], [])
390
387
def test_deserialise_sets_root_revision(self):
391
388
"""We must have a inventory.root.revision
420
417
self.assertFalse(repo._format.supports_external_lookups)
423
class KnitRepositoryStreamTests(test_knit.KnitTests):
424
"""Tests for knitrepo._get_stream_as_bytes."""
426
def test_get_stream_as_bytes(self):
428
k1 = self.make_test_knit()
429
k1.add_lines('text-a', [], test_knit.split_lines(test_knit.TEXT_1))
431
# Serialise it, check the output.
432
bytes = knitrepo._get_stream_as_bytes(k1, ['text-a'])
433
data = bencode.bdecode(bytes)
434
format, record = data
435
self.assertEqual('knit-plain', format)
436
self.assertEqual(['text-a', ['fulltext'], []], record[:3])
437
self.assertRecordContentEqual(k1, 'text-a', record[3])
439
def test_get_stream_as_bytes_all(self):
440
"""Get a serialised data stream for all the records in a knit.
442
Much like test_get_stream_all, except for get_stream_as_bytes.
444
k1 = self.make_test_knit()
445
# Insert the same data as BasicKnitTests.test_knit_join, as they seem
446
# to cover a range of cases (no parents, one parent, multiple parents).
448
('text-a', [], test_knit.TEXT_1),
449
('text-b', ['text-a'], test_knit.TEXT_1),
450
('text-c', [], test_knit.TEXT_1),
451
('text-d', ['text-c'], test_knit.TEXT_1),
452
('text-m', ['text-b', 'text-d'], test_knit.TEXT_1),
454
# This test is actually a bit strict as the order in which they're
455
# returned is not defined. This matches the current (deterministic)
457
expected_data_list = [
458
# version, options, parents
459
('text-a', ['fulltext'], []),
460
('text-b', ['line-delta'], ['text-a']),
461
('text-m', ['line-delta'], ['text-b', 'text-d']),
462
('text-c', ['fulltext'], []),
463
('text-d', ['line-delta'], ['text-c']),
465
for version_id, parents, lines in test_data:
466
k1.add_lines(version_id, parents, test_knit.split_lines(lines))
468
bytes = knitrepo._get_stream_as_bytes(
469
k1, ['text-a', 'text-b', 'text-m', 'text-c', 'text-d', ])
471
data = bencode.bdecode(bytes)
473
self.assertEqual('knit-plain', format)
475
for expected, actual in zip(expected_data_list, data):
476
expected_version = expected[0]
477
expected_options = expected[1]
478
expected_parents = expected[2]
479
version, options, parents, bytes = actual
480
self.assertEqual(expected_version, version)
481
self.assertEqual(expected_options, options)
482
self.assertEqual(expected_parents, parents)
483
self.assertRecordContentEqual(k1, version, bytes)
486
420
class DummyRepository(object):
487
421
"""A dummy repository for testing."""
593
527
repo_b).__class__)
596
class TestInterRemoteToOther(TestCaseWithTransport):
598
def make_remote_repository(self, path, backing_format=None):
599
"""Make a RemoteRepository object backed by a real repository that will
600
be created at the given path."""
601
self.make_repository(path, format=backing_format)
602
smart_server = server.SmartTCPServer_for_testing()
604
remote_transport = get_transport(smart_server.get_url()).clone(path)
605
self.addCleanup(smart_server.tearDown)
606
remote_bzrdir = bzrdir.BzrDir.open_from_transport(remote_transport)
607
remote_repo = remote_bzrdir.open_repository()
610
def test_is_compatible_same_format(self):
611
"""InterRemoteToOther is compatible with a remote repository and a
612
second repository that have the same format."""
613
local_repo = self.make_repository('local')
614
remote_repo = self.make_remote_repository('remote')
615
is_compatible = repository.InterRemoteToOther.is_compatible
617
is_compatible(remote_repo, local_repo),
618
"InterRemoteToOther(%r, %r) is false" % (remote_repo, local_repo))
620
def test_is_incompatible_different_format(self):
621
local_repo = self.make_repository('local', 'dirstate')
622
remote_repo = self.make_remote_repository('a', 'dirstate-with-subtree')
623
is_compatible = repository.InterRemoteToOther.is_compatible
625
is_compatible(remote_repo, local_repo),
626
"InterRemoteToOther(%r, %r) is true" % (local_repo, remote_repo))
628
def test_is_incompatible_different_format_both_remote(self):
629
remote_repo_a = self.make_remote_repository(
630
'a', 'dirstate-with-subtree')
631
remote_repo_b = self.make_remote_repository('b', 'dirstate')
632
is_compatible = repository.InterRemoteToOther.is_compatible
634
is_compatible(remote_repo_a, remote_repo_b),
635
"InterRemoteToOther(%r, %r) is true"
636
% (remote_repo_a, remote_repo_b))
639
530
class TestRepositoryConverter(TestCaseWithTransport):
641
532
def test_convert_empty(self):
670
561
tree = self.make_branch_and_tree('.', format)
671
562
tree.commit("Dull commit", rev_id="dull")
672
563
revision_tree = tree.branch.repository.revision_tree('dull')
673
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
674
revision_tree.inventory.root.file_id)
564
revision_tree.lock_read()
566
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
567
revision_tree.inventory.root.file_id)
569
revision_tree.unlock()
675
570
format = bzrdir.BzrDirMetaFormat1()
676
571
format.repository_format = knitrepo.RepositoryFormatKnit3()
677
572
upgrade.Convert('.', format)
678
573
tree = workingtree.WorkingTree.open('.')
679
574
revision_tree = tree.branch.repository.revision_tree('dull')
680
revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
575
revision_tree.lock_read()
577
revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
579
revision_tree.unlock()
681
580
tree.commit("Another dull commit", rev_id='dull2')
682
581
revision_tree = tree.branch.repository.revision_tree('dull2')
582
revision_tree.lock_read()
583
self.addCleanup(revision_tree.unlock)
683
584
self.assertEqual('dull', revision_tree.inventory.root.revision)
685
def test_exposed_versioned_files_are_marked_dirty(self):
686
format = bzrdir.BzrDirMetaFormat1()
687
format.repository_format = knitrepo.RepositoryFormatKnit3()
688
repo = self.make_repository('.', format=format)
690
inv = repo.get_inventory_weave()
692
self.assertRaises(errors.OutSideTransaction,
693
inv.add_lines, 'foo', [], [])
695
586
def test_supports_external_lookups(self):
696
587
format = bzrdir.BzrDirMetaFormat1()
697
588
format.repository_format = knitrepo.RepositoryFormatKnit3()
780
671
broken_repo = self.make_broken_repository()
781
672
empty_repo = self.make_repository('empty-repo')
782
search = graph.SearchResult(set(['rev1a', 'rev2', 'rev3']),
783
set(), 3, ['rev1a', 'rev2', 'rev3'])
784
broken_repo.lock_read()
785
self.addCleanup(broken_repo.unlock)
786
stream = broken_repo.get_data_stream_for_search(search)
787
empty_repo.lock_write()
788
self.addCleanup(empty_repo.unlock)
789
empty_repo.start_write_group()
792
errors.KnitCorrupt, empty_repo.insert_data_stream, stream)
794
empty_repo.abort_write_group()
673
self.assertRaises(errors.RevisionNotPresent, empty_repo.fetch, broken_repo)
797
676
class TestKnitPackNoSubtrees(TestCaseWithTransport):