680
664
self.assertFalse(repo._format.supports_external_lookups)
683
class Test2a(tests.TestCaseWithMemoryTransport):
685
def test_chk_bytes_uses_custom_btree_parser(self):
686
mt = self.make_branch_and_memory_tree('test', format='2a')
688
self.addCleanup(mt.unlock)
689
mt.add([''], ['root-id'])
691
index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
692
self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
693
# It should also work if we re-open the repo
694
repo = mt.branch.repository.bzrdir.open_repository()
696
self.addCleanup(repo.unlock)
697
index = repo.chk_bytes._index._graph_index._indices[0]
698
self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
700
def test_fetch_combines_groups(self):
701
builder = self.make_branch_builder('source', format='2a')
702
builder.start_series()
703
builder.build_snapshot('1', None, [
704
('add', ('', 'root-id', 'directory', '')),
705
('add', ('file', 'file-id', 'file', 'content\n'))])
706
builder.build_snapshot('2', ['1'], [
707
('modify', ('file-id', 'content-2\n'))])
708
builder.finish_series()
709
source = builder.get_branch()
710
target = self.make_repository('target', format='2a')
711
target.fetch(source.repository)
713
self.addCleanup(target.unlock)
714
details = target.texts._index.get_build_details(
715
[('file-id', '1',), ('file-id', '2',)])
716
file_1_details = details[('file-id', '1')]
717
file_2_details = details[('file-id', '2')]
718
# The index, and what to read off disk, should be the same for both
719
# versions of the file.
720
self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
722
def test_fetch_combines_groups(self):
723
builder = self.make_branch_builder('source', format='2a')
724
builder.start_series()
725
builder.build_snapshot('1', None, [
726
('add', ('', 'root-id', 'directory', '')),
727
('add', ('file', 'file-id', 'file', 'content\n'))])
728
builder.build_snapshot('2', ['1'], [
729
('modify', ('file-id', 'content-2\n'))])
730
builder.finish_series()
731
source = builder.get_branch()
732
target = self.make_repository('target', format='2a')
733
target.fetch(source.repository)
735
self.addCleanup(target.unlock)
736
details = target.texts._index.get_build_details(
737
[('file-id', '1',), ('file-id', '2',)])
738
file_1_details = details[('file-id', '1')]
739
file_2_details = details[('file-id', '2')]
740
# The index, and what to read off disk, should be the same for both
741
# versions of the file.
742
self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
744
def test_fetch_combines_groups(self):
745
builder = self.make_branch_builder('source', format='2a')
746
builder.start_series()
747
builder.build_snapshot('1', None, [
748
('add', ('', 'root-id', 'directory', '')),
749
('add', ('file', 'file-id', 'file', 'content\n'))])
750
builder.build_snapshot('2', ['1'], [
751
('modify', ('file-id', 'content-2\n'))])
752
builder.finish_series()
753
source = builder.get_branch()
754
target = self.make_repository('target', format='2a')
755
target.fetch(source.repository)
757
self.addCleanup(target.unlock)
758
details = target.texts._index.get_build_details(
759
[('file-id', '1',), ('file-id', '2',)])
760
file_1_details = details[('file-id', '1')]
761
file_2_details = details[('file-id', '2')]
762
# The index, and what to read off disk, should be the same for both
763
# versions of the file.
764
self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
766
def test_format_pack_compresses_True(self):
767
repo = self.make_repository('repo', format='2a')
768
self.assertTrue(repo._format.pack_compresses)
770
def test_inventories_use_chk_map_with_parent_base_dict(self):
771
tree = self.make_branch_and_memory_tree('repo', format="2a")
773
tree.add([''], ['TREE_ROOT'])
774
revid = tree.commit("foo")
777
self.addCleanup(tree.unlock)
778
inv = tree.branch.repository.get_inventory(revid)
779
self.assertNotEqual(None, inv.parent_id_basename_to_file_id)
780
inv.parent_id_basename_to_file_id._ensure_root()
781
inv.id_to_entry._ensure_root()
782
self.assertEqual(65536, inv.id_to_entry._root_node.maximum_size)
783
self.assertEqual(65536,
784
inv.parent_id_basename_to_file_id._root_node.maximum_size)
786
def test_autopack_unchanged_chk_nodes(self):
787
# at 20 unchanged commits, chk pages are packed that are split into
788
# two groups such that the new pack being made doesn't have all its
789
# pages in the source packs (though they are in the repository).
790
# Use a memory backed repository, we don't need to hit disk for this
791
tree = self.make_branch_and_memory_tree('tree', format='2a')
793
self.addCleanup(tree.unlock)
794
tree.add([''], ['TREE_ROOT'])
795
for pos in range(20):
796
tree.commit(str(pos))
798
def test_pack_with_hint(self):
799
tree = self.make_branch_and_memory_tree('tree', format='2a')
801
self.addCleanup(tree.unlock)
802
tree.add([''], ['TREE_ROOT'])
803
# 1 commit to leave untouched
805
to_keep = tree.branch.repository._pack_collection.names()
809
all = tree.branch.repository._pack_collection.names()
810
combine = list(set(all) - set(to_keep))
811
self.assertLength(3, all)
812
self.assertLength(2, combine)
813
tree.branch.repository.pack(hint=combine)
814
final = tree.branch.repository._pack_collection.names()
815
self.assertLength(2, final)
816
self.assertFalse(combine[0] in final)
817
self.assertFalse(combine[1] in final)
818
self.assertSubset(to_keep, final)
820
def test_stream_source_to_gc(self):
821
source = self.make_repository('source', format='2a')
822
target = self.make_repository('target', format='2a')
823
stream = source._get_source(target._format)
824
self.assertIsInstance(stream, groupcompress_repo.GroupCHKStreamSource)
826
def test_stream_source_to_non_gc(self):
827
source = self.make_repository('source', format='2a')
828
target = self.make_repository('target', format='rich-root-pack')
829
stream = source._get_source(target._format)
830
# We don't want the child GroupCHKStreamSource
831
self.assertIs(type(stream), repository.StreamSource)
833
def test_get_stream_for_missing_keys_includes_all_chk_refs(self):
834
source_builder = self.make_branch_builder('source',
836
# We have to build a fairly large tree, so that we are sure the chk
837
# pages will have split into multiple pages.
838
entries = [('add', ('', 'a-root-id', 'directory', None))]
839
for i in 'abcdefghijklmnopqrstuvwxyz123456789':
840
for j in 'abcdefghijklmnopqrstuvwxyz123456789':
843
content = 'content for %s\n' % (fname,)
844
entries.append(('add', (fname, fid, 'file', content)))
845
source_builder.start_series()
846
source_builder.build_snapshot('rev-1', None, entries)
847
# Now change a few of them, so we get a few new pages for the second
849
source_builder.build_snapshot('rev-2', ['rev-1'], [
850
('modify', ('aa-id', 'new content for aa-id\n')),
851
('modify', ('cc-id', 'new content for cc-id\n')),
852
('modify', ('zz-id', 'new content for zz-id\n')),
854
source_builder.finish_series()
855
source_branch = source_builder.get_branch()
856
source_branch.lock_read()
857
self.addCleanup(source_branch.unlock)
858
target = self.make_repository('target', format='2a')
859
source = source_branch.repository._get_source(target._format)
860
self.assertIsInstance(source, groupcompress_repo.GroupCHKStreamSource)
862
# On a regular pass, getting the inventories and chk pages for rev-2
863
# would only get the newly created chk pages
864
search = graph.SearchResult(set(['rev-2']), set(['rev-1']), 1,
866
simple_chk_records = []
867
for vf_name, substream in source.get_stream(search):
868
if vf_name == 'chk_bytes':
869
for record in substream:
870
simple_chk_records.append(record.key)
874
# 3 pages, the root (InternalNode), + 2 pages which actually changed
875
self.assertEqual([('sha1:91481f539e802c76542ea5e4c83ad416bf219f73',),
876
('sha1:4ff91971043668583985aec83f4f0ab10a907d3f',),
877
('sha1:81e7324507c5ca132eedaf2d8414ee4bb2226187',),
878
('sha1:b101b7da280596c71a4540e9a1eeba8045985ee0',)],
880
# Now, when we do a similar call using 'get_stream_for_missing_keys'
881
# we should get a much larger set of pages.
882
missing = [('inventories', 'rev-2')]
883
full_chk_records = []
884
for vf_name, substream in source.get_stream_for_missing_keys(missing):
885
if vf_name == 'inventories':
886
for record in substream:
887
self.assertEqual(('rev-2',), record.key)
888
elif vf_name == 'chk_bytes':
889
for record in substream:
890
full_chk_records.append(record.key)
892
self.fail('Should not be getting a stream of %s' % (vf_name,))
893
# We have 257 records now. This is because we have 1 root page, and 256
894
# leaf pages in a complete listing.
895
self.assertEqual(257, len(full_chk_records))
896
self.assertSubset(simple_chk_records, full_chk_records)
898
def test_inconsistency_fatal(self):
899
repo = self.make_repository('repo', format='2a')
900
self.assertTrue(repo.revisions._index._inconsistency_fatal)
901
self.assertFalse(repo.texts._index._inconsistency_fatal)
902
self.assertFalse(repo.inventories._index._inconsistency_fatal)
903
self.assertFalse(repo.signatures._index._inconsistency_fatal)
904
self.assertFalse(repo.chk_bytes._index._inconsistency_fatal)
907
class TestKnitPackStreamSource(tests.TestCaseWithMemoryTransport):
909
def test_source_to_exact_pack_092(self):
910
source = self.make_repository('source', format='pack-0.92')
911
target = self.make_repository('target', format='pack-0.92')
912
stream_source = source._get_source(target._format)
913
self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
915
def test_source_to_exact_pack_rich_root_pack(self):
916
source = self.make_repository('source', format='rich-root-pack')
917
target = self.make_repository('target', format='rich-root-pack')
918
stream_source = source._get_source(target._format)
919
self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
921
def test_source_to_exact_pack_19(self):
922
source = self.make_repository('source', format='1.9')
923
target = self.make_repository('target', format='1.9')
924
stream_source = source._get_source(target._format)
925
self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
927
def test_source_to_exact_pack_19_rich_root(self):
928
source = self.make_repository('source', format='1.9-rich-root')
929
target = self.make_repository('target', format='1.9-rich-root')
930
stream_source = source._get_source(target._format)
931
self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
933
def test_source_to_remote_exact_pack_19(self):
934
trans = self.make_smart_server('target')
936
source = self.make_repository('source', format='1.9')
937
target = self.make_repository('target', format='1.9')
938
target = repository.Repository.open(trans.base)
939
stream_source = source._get_source(target._format)
940
self.assertIsInstance(stream_source, pack_repo.KnitPackStreamSource)
942
def test_stream_source_to_non_exact(self):
943
source = self.make_repository('source', format='pack-0.92')
944
target = self.make_repository('target', format='1.9')
945
stream = source._get_source(target._format)
946
self.assertIs(type(stream), repository.StreamSource)
948
def test_stream_source_to_non_exact_rich_root(self):
949
source = self.make_repository('source', format='1.9')
950
target = self.make_repository('target', format='1.9-rich-root')
951
stream = source._get_source(target._format)
952
self.assertIs(type(stream), repository.StreamSource)
954
def test_source_to_remote_non_exact_pack_19(self):
955
trans = self.make_smart_server('target')
957
source = self.make_repository('source', format='1.9')
958
target = self.make_repository('target', format='1.6')
959
target = repository.Repository.open(trans.base)
960
stream_source = source._get_source(target._format)
961
self.assertIs(type(stream_source), repository.StreamSource)
963
def test_stream_source_to_knit(self):
964
source = self.make_repository('source', format='pack-0.92')
965
target = self.make_repository('target', format='dirstate')
966
stream = source._get_source(target._format)
967
self.assertIs(type(stream), repository.StreamSource)
970
class TestDevelopment6FindParentIdsOfRevisions(TestCaseWithTransport):
971
"""Tests for _find_parent_ids_of_revisions."""
974
super(TestDevelopment6FindParentIdsOfRevisions, self).setUp()
975
self.builder = self.make_branch_builder('source',
976
format='development6-rich-root')
977
self.builder.start_series()
978
self.builder.build_snapshot('initial', None,
979
[('add', ('', 'tree-root', 'directory', None))])
980
self.repo = self.builder.get_branch().repository
981
self.addCleanup(self.builder.finish_series)
983
def assertParentIds(self, expected_result, rev_set):
984
self.assertEqual(sorted(expected_result),
985
sorted(self.repo._find_parent_ids_of_revisions(rev_set)))
987
def test_simple(self):
988
self.builder.build_snapshot('revid1', None, [])
989
self.builder.build_snapshot('revid2', ['revid1'], [])
991
self.assertParentIds(['revid1'], rev_set)
993
def test_not_first_parent(self):
994
self.builder.build_snapshot('revid1', None, [])
995
self.builder.build_snapshot('revid2', ['revid1'], [])
996
self.builder.build_snapshot('revid3', ['revid2'], [])
997
rev_set = ['revid3', 'revid2']
998
self.assertParentIds(['revid1'], rev_set)
1000
def test_not_null(self):
1001
rev_set = ['initial']
1002
self.assertParentIds([], rev_set)
1004
def test_not_null_set(self):
1005
self.builder.build_snapshot('revid1', None, [])
1006
rev_set = [_mod_revision.NULL_REVISION]
1007
self.assertParentIds([], rev_set)
1009
def test_ghost(self):
1010
self.builder.build_snapshot('revid1', None, [])
1011
rev_set = ['ghost', 'revid1']
1012
self.assertParentIds(['initial'], rev_set)
1014
def test_ghost_parent(self):
1015
self.builder.build_snapshot('revid1', None, [])
1016
self.builder.build_snapshot('revid2', ['revid1', 'ghost'], [])
1017
rev_set = ['revid2', 'revid1']
1018
self.assertParentIds(['ghost', 'initial'], rev_set)
1020
def test_righthand_parent(self):
1021
self.builder.build_snapshot('revid1', None, [])
1022
self.builder.build_snapshot('revid2a', ['revid1'], [])
1023
self.builder.build_snapshot('revid2b', ['revid1'], [])
1024
self.builder.build_snapshot('revid3', ['revid2a', 'revid2b'], [])
1025
rev_set = ['revid3', 'revid2a']
1026
self.assertParentIds(['revid1', 'revid2b'], rev_set)
1029
667
class TestWithBrokenRepo(TestCaseWithTransport):
1030
668
"""These tests seem to be more appropriate as interface tests?"""
1630
1116
packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
1632
1118
new_pack = packer.open_pack()
1633
self.addCleanup(new_pack.abort) # ensure cleanup
1634
1119
self.assertIsInstance(new_pack, pack_repo.NewPack)
1635
1120
self.assertTrue(new_pack.revision_index._optimize_for_size)
1636
1121
self.assertTrue(new_pack.inventory_index._optimize_for_size)
1637
1122
self.assertTrue(new_pack.text_index._optimize_for_size)
1638
1123
self.assertTrue(new_pack.signature_index._optimize_for_size)
1641
class TestCrossFormatPacks(TestCaseWithTransport):
1643
def log_pack(self, hint=None):
1644
self.calls.append(('pack', hint))
1645
self.orig_pack(hint=hint)
1646
if self.expect_hint:
1647
self.assertTrue(hint)
1649
def run_stream(self, src_fmt, target_fmt, expect_pack_called):
1650
self.expect_hint = expect_pack_called
1652
source_tree = self.make_branch_and_tree('src', format=src_fmt)
1653
source_tree.lock_write()
1654
self.addCleanup(source_tree.unlock)
1655
tip = source_tree.commit('foo')
1656
target = self.make_repository('target', format=target_fmt)
1658
self.addCleanup(target.unlock)
1659
source = source_tree.branch.repository._get_source(target._format)
1660
self.orig_pack = target.pack
1661
target.pack = self.log_pack
1662
search = target.search_missing_revision_ids(
1663
source_tree.branch.repository, tip)
1664
stream = source.get_stream(search)
1665
from_format = source_tree.branch.repository._format
1666
sink = target._get_sink()
1667
sink.insert_stream(stream, from_format, [])
1668
if expect_pack_called:
1669
self.assertLength(1, self.calls)
1671
self.assertLength(0, self.calls)
1673
def run_fetch(self, src_fmt, target_fmt, expect_pack_called):
1674
self.expect_hint = expect_pack_called
1676
source_tree = self.make_branch_and_tree('src', format=src_fmt)
1677
source_tree.lock_write()
1678
self.addCleanup(source_tree.unlock)
1679
tip = source_tree.commit('foo')
1680
target = self.make_repository('target', format=target_fmt)
1682
self.addCleanup(target.unlock)
1683
source = source_tree.branch.repository
1684
self.orig_pack = target.pack
1685
target.pack = self.log_pack
1686
target.fetch(source)
1687
if expect_pack_called:
1688
self.assertLength(1, self.calls)
1690
self.assertLength(0, self.calls)
1692
def test_sink_format_hint_no(self):
1693
# When the target format says packing makes no difference, pack is not
1695
self.run_stream('1.9', 'rich-root-pack', False)
1697
def test_sink_format_hint_yes(self):
1698
# When the target format says packing makes a difference, pack is
1700
self.run_stream('1.9', '2a', True)
1702
def test_sink_format_same_no(self):
1703
# When the formats are the same, pack is not called.
1704
self.run_stream('2a', '2a', False)
1706
def test_IDS_format_hint_no(self):
1707
# When the target format says packing makes no difference, pack is not
1709
self.run_fetch('1.9', 'rich-root-pack', False)
1711
def test_IDS_format_hint_yes(self):
1712
# When the target format says packing makes a difference, pack is
1714
self.run_fetch('1.9', '2a', True)
1716
def test_IDS_format_same_no(self):
1717
# When the formats are the same, pack is not called.
1718
self.run_fetch('2a', '2a', False)