162
163
def test_adding_revision_creates_pack_indices(self):
163
164
format = self.get_format()
164
165
tree = self.make_branch_and_tree('.', format=format)
165
trans = tree.branch.repository.controldir.get_repository_transport(None)
166
trans = tree.branch.repository.controldir.get_repository_transport(
166
168
self.assertEqual([],
167
list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
169
list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
168
170
tree.commit('foobarbaz')
169
171
index = self.index_class(trans, 'pack-names', None)
170
172
index_nodes = list(index.iter_all_entries())
183
185
tree1 = self.make_branch_and_tree('1', format=format)
184
186
tree2 = self.make_branch_and_tree('2', format=format)
185
187
tree1.branch.repository.fetch(tree2.branch.repository)
186
trans = tree1.branch.repository.controldir.get_repository_transport(None)
188
trans = tree1.branch.repository.controldir.get_repository_transport(
187
190
self.assertEqual([],
188
list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
191
list(self.index_class(trans, 'pack-names', None).iter_all_entries()))
190
193
def test_commit_across_pack_shape_boundary_autopacks(self):
191
194
format = self.get_format()
192
195
tree = self.make_branch_and_tree('.', format=format)
193
trans = tree.branch.repository.controldir.get_repository_transport(None)
196
trans = tree.branch.repository.controldir.get_repository_transport(
194
198
# This test could be a little cheaper by replacing the packs
195
199
# attribute on the repository to allow a different pack distribution
196
200
# and max packs policy - so we are checking the policy is honoured
212
216
tree = tree.controldir.open_workingtree()
213
217
check_result = tree.branch.repository.check(
214
218
[tree.branch.last_revision()])
215
nb_files = 5 # .pack, .rix, .iix, .tix, .six
219
nb_files = 5 # .pack, .rix, .iix, .tix, .six
216
220
if tree.branch.repository._format.supports_chks:
218
222
# We should have 10 x nb_files files in the obsolete_packs directory.
219
223
obsolete_files = list(trans.list_dir('obsolete_packs'))
220
224
self.assertFalse('foo' in obsolete_files)
249
253
inv.root.revision = revid
250
254
repo.texts.add_lines((inv.root.file_id, revid), [], [])
251
255
rev = _mod_revision.Revision(timestamp=0, timezone=None,
252
committer="Foo Bar <foo@example.com>", message="Message",
256
committer="Foo Bar <foo@example.com>", message="Message",
254
258
rev.parent_ids = ()
255
259
repo.add_revision(revid, rev, inv=inv)
296
300
combined_indices.difference([combined_index]),
297
301
combined_index._sibling_indices)
303
def test_pack_with_signatures(self):
304
format = self.get_format()
305
tree = self.make_branch_and_tree('.', format=format)
306
trans = tree.branch.repository.controldir.get_repository_transport(
308
revid1 = tree.commit('start')
309
revid2 = tree.commit('more work')
310
strategy = gpg.LoopbackGPGStrategy(None)
311
repo = tree.branch.repository
312
self.addCleanup(repo.lock_write().unlock)
313
repo.start_write_group()
314
repo.sign_revision(revid1, strategy)
315
repo.commit_write_group()
316
repo.start_write_group()
317
repo.sign_revision(revid2, strategy)
318
repo.commit_write_group()
319
tree.branch.repository.pack()
320
# there should be 1 pack:
321
index = self.index_class(trans, 'pack-names', None)
322
self.assertEqual(1, len(list(index.iter_all_entries())))
323
self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
299
325
def test_pack_after_two_commits_packs_everything(self):
300
326
format = self.get_format()
301
327
tree = self.make_branch_and_tree('.', format=format)
302
trans = tree.branch.repository.controldir.get_repository_transport(None)
328
trans = tree.branch.repository.controldir.get_repository_transport(
303
330
tree.commit('start')
304
331
tree.commit('more work')
305
332
tree.branch.repository.pack()
389
417
def _add_text(self, repo, fileid):
390
418
"""Add a text to the repository within a write group."""
391
repo.texts.add_lines((fileid, b'samplerev+'+fileid), [],
392
[b'smaplerev+'+fileid])
419
repo.texts.add_lines((fileid, b'samplerev+' + fileid), [],
420
[b'smaplerev+' + fileid])
394
422
def test_concurrent_writers_merge_new_packs(self):
395
423
format = self.get_format()
616
648
# 'references' is present in both repositories, and 'tip' is present
617
649
# just in has_ghost.
618
650
# has_ghost missing_ghost
619
#------------------------------
651
# ------------------------------
621
653
# 'references' 'references'
623
655
# In this test we fetch 'tip' which should not fetch 'ghost'
624
656
has_ghost = self.make_repository('has_ghost', format=self.get_format())
625
657
missing_ghost = self.make_repository('missing_ghost',
626
format=self.get_format())
658
format=self.get_format())
628
660
def add_commit(repo, revision_id, parent_ids):
629
661
repo.lock_write()
652
684
rev = missing_ghost.get_revision(b'tip')
653
685
inv = missing_ghost.get_inventory(b'tip')
654
686
self.assertRaises(errors.NoSuchRevision,
655
missing_ghost.get_revision, b'ghost')
687
missing_ghost.get_revision, b'ghost')
656
688
self.assertRaises(errors.NoSuchRevision,
657
missing_ghost.get_inventory, b'ghost')
689
missing_ghost.get_inventory, b'ghost')
659
691
def make_write_ready_repo(self):
660
692
format = self.get_format()
698
730
def test_supports_external_lookups(self):
699
731
repo = self.make_repository('.', format=self.get_format())
700
732
self.assertEqual(self.format_supports_external_lookups,
701
repo._format.supports_external_lookups)
733
repo._format.supports_external_lookups)
703
735
def _lock_write(self, write_lockable):
704
736
"""Lock write_lockable, add a cleanup and return the result.
706
738
:param write_lockable: An object with a lock_write method.
707
739
:return: The result of write_lockable.lock_write().
751
783
wg_tokens = repo.suspend_write_group()
752
784
expected_pack_name = wg_tokens[0] + '.pack'
753
785
expected_names = [wg_tokens[0] + ext for ext in
754
('.rix', '.iix', '.tix', '.six')]
786
('.rix', '.iix', '.tix', '.six')]
755
787
if repo.chk_bytes is not None:
756
788
expected_names.append(wg_tokens[0] + '.cix')
757
789
expected_names.append(expected_pack_name)
894
926
repo.add_fallback_repository(base)
895
927
# you can't stack on something with incompatible data
896
928
bad_repo = self.make_repository('mismatch',
897
format=mismatching_format_name)
929
format=mismatching_format_name)
898
930
e = self.assertRaises(errors.IncompatibleRepositories,
899
repo.add_fallback_repository, bad_repo)
931
repo.add_fallback_repository, bad_repo)
900
932
self.assertContainsRe(str(e),
901
r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
902
r'.*Repository.*/repo/.*\n'
903
r'different rich-root support')
933
r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
934
r'.*Repository.*/repo/.*\n'
935
r'different rich-root support')
905
937
def test_stack_checks_serializers_compatibility(self):
906
938
repo = self.make_repository('repo', format=self.get_format())
918
950
mismatching_format_name = 'pack-0.92-subtree'
920
952
raise TestNotApplicable('No formats use non-v5 serializer'
921
' without having rich-root also set')
953
' without having rich-root also set')
922
954
base = self.make_repository('base', format=matching_format_name)
923
955
repo.add_fallback_repository(base)
924
956
# you can't stack on something with incompatible data
925
957
bad_repo = self.make_repository('mismatch',
926
format=mismatching_format_name)
958
format=mismatching_format_name)
927
959
e = self.assertRaises(errors.IncompatibleRepositories,
928
repo.add_fallback_repository, bad_repo)
960
repo.add_fallback_repository, bad_repo)
929
961
self.assertContainsRe(str(e),
930
r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
931
r'.*Repository.*/repo/.*\n'
932
r'different serializers')
962
r'(?m)KnitPackRepository.*/mismatch/.*\nis not compatible with\n'
963
r'.*Repository.*/repo/.*\n'
964
r'different serializers')
934
966
def test_adding_pack_does_not_record_pack_names_from_other_repositories(self):
935
967
base = self.make_branch_and_tree('base', format=self.get_format())
936
968
base.commit('foo')
937
referencing = self.make_branch_and_tree('repo', format=self.get_format())
938
referencing.branch.repository.add_fallback_repository(base.branch.repository)
969
referencing = self.make_branch_and_tree(
970
'repo', format=self.get_format())
971
referencing.branch.repository.add_fallback_repository(
972
base.branch.repository)
939
973
local_tree = referencing.branch.create_checkout('local')
940
974
local_tree.commit('bar')
941
975
new_instance = referencing.controldir.open_repository()
970
1005
tree = tree.controldir.open_workingtree()
971
1006
check_result = tree.branch.repository.check(
972
1007
[tree.branch.last_revision()])
973
nb_files = 5 # .pack, .rix, .iix, .tix, .six
1008
nb_files = 5 # .pack, .rix, .iix, .tix, .six
974
1009
if tree.branch.repository._format.supports_chks:
1010
nb_files += 1 # .cix
976
1011
# We should have 10 x nb_files files in the obsolete_packs directory.
977
1012
obsolete_files = list(trans.list_dir('obsolete_packs'))
978
1013
self.assertFalse('foo' in obsolete_files)
1098
1134
self.hpss_calls = []
1099
1135
tree.commit('commit triggering pack')
1100
1136
tree.branch.push(remote_branch)
1101
autopack_calls = len([call for call in self.hpss_calls if call ==
1102
b'PackRepository.autopack'])
1137
autopack_calls = len([call for call in self.hpss_calls if call
1138
== b'PackRepository.autopack'])
1103
1139
streaming_calls = len([call for call in self.hpss_calls if call in
1104
(b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
1140
(b'Repository.insert_stream', b'Repository.insert_stream_1.19')])
1105
1141
if autopack_calls:
1106
1142
# Non streaming server
1107
1143
self.assertEqual(1, autopack_calls)
1119
1155
# these give the bzrdir canned format name, and the repository on-disk
1120
1156
# format string
1121
1157
scenarios_params = [
1122
dict(format_name='pack-0.92',
1123
format_string="Bazaar pack repository format 1 (needs bzr 0.92)\n",
1124
format_supports_external_lookups=False,
1125
index_class=GraphIndex),
1126
dict(format_name='pack-0.92-subtree',
1127
format_string="Bazaar pack repository format 1 "
1128
"with subtree support (needs bzr 0.92)\n",
1129
format_supports_external_lookups=False,
1130
index_class=GraphIndex),
1131
dict(format_name='1.6',
1132
format_string="Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n",
1133
format_supports_external_lookups=True,
1134
index_class=GraphIndex),
1135
dict(format_name='1.6.1-rich-root',
1136
format_string="Bazaar RepositoryFormatKnitPack5RichRoot "
1138
format_supports_external_lookups=True,
1139
index_class=GraphIndex),
1140
dict(format_name='1.9',
1141
format_string="Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n",
1142
format_supports_external_lookups=True,
1143
index_class=BTreeGraphIndex),
1144
dict(format_name='1.9-rich-root',
1145
format_string="Bazaar RepositoryFormatKnitPack6RichRoot "
1147
format_supports_external_lookups=True,
1148
index_class=BTreeGraphIndex),
1149
dict(format_name='2a',
1150
format_string="Bazaar repository format 2a "
1151
"(needs bzr 1.16 or later)\n",
1152
format_supports_external_lookups=True,
1153
index_class=BTreeGraphIndex),
1158
dict(format_name='pack-0.92',
1159
format_string="Bazaar pack repository format 1 (needs bzr 0.92)\n",
1160
format_supports_external_lookups=False,
1161
index_class=GraphIndex),
1162
dict(format_name='pack-0.92-subtree',
1163
format_string="Bazaar pack repository format 1 "
1164
"with subtree support (needs bzr 0.92)\n",
1165
format_supports_external_lookups=False,
1166
index_class=GraphIndex),
1167
dict(format_name='1.6',
1168
format_string="Bazaar RepositoryFormatKnitPack5 (bzr 1.6)\n",
1169
format_supports_external_lookups=True,
1170
index_class=GraphIndex),
1171
dict(format_name='1.6.1-rich-root',
1172
format_string="Bazaar RepositoryFormatKnitPack5RichRoot "
1174
format_supports_external_lookups=True,
1175
index_class=GraphIndex),
1176
dict(format_name='1.9',
1177
format_string="Bazaar RepositoryFormatKnitPack6 (bzr 1.9)\n",
1178
format_supports_external_lookups=True,
1179
index_class=BTreeGraphIndex),
1180
dict(format_name='1.9-rich-root',
1181
format_string="Bazaar RepositoryFormatKnitPack6RichRoot "
1183
format_supports_external_lookups=True,
1184
index_class=BTreeGraphIndex),
1185
dict(format_name='2a',
1186
format_string="Bazaar repository format 2a "
1187
"(needs bzr 1.16 or later)\n",
1188
format_supports_external_lookups=True,
1189
index_class=BTreeGraphIndex),
1155
1191
# name of the scenario is the format name
1156
1192
scenarios = [(s['format_name'], s) for s in scenarios_params]
1157
1193
return tests.multiply_tests(basic_tests, scenarios, loader.suiteClass())