84
84
"""Packs reuse deltas."""
85
85
format = self.get_format()
86
86
repo = self.make_repository('.', format=format)
87
if isinstance(format.repository_format, RepositoryFormatCHK1):
87
if isinstance(format.repository_format, RepositoryFormat2a):
88
88
# TODO: This is currently a workaround. CHK format repositories
89
89
# ignore the 'deltas' flag, but during conversions, we can't
90
90
# do unordered delta fetches. Remove this clause once we
295
295
self.assertEqual(1, len(list(index.iter_all_entries())))
296
296
self.assertEqual(2, len(tree.branch.repository.all_revision_ids()))
298
def test_pack_preserves_all_inventories(self):
299
# This is related to bug:
300
# https://bugs.launchpad.net/bzr/+bug/412198
301
# Stacked repositories need to keep the inventory for parents, even
302
# after a pack operation. However, it is harder to test that, then just
303
# test that all inventory texts are preserved.
304
format = self.get_format()
305
builder = self.make_branch_builder('source', format=format)
306
builder.start_series()
307
builder.build_snapshot('A-id', None, [
308
('add', ('', 'root-id', 'directory', None))])
309
builder.build_snapshot('B-id', None, [
310
('add', ('file', 'file-id', 'file', 'B content\n'))])
311
builder.build_snapshot('C-id', None, [
312
('modify', ('file-id', 'C content\n'))])
313
builder.finish_series()
314
b = builder.get_branch()
316
self.addCleanup(b.unlock)
317
repo = self.make_repository('repo', shared=True, format=format)
319
self.addCleanup(repo.unlock)
320
repo.fetch(b.repository, revision_id='B-id')
321
inv = b.repository.iter_inventories(['C-id']).next()
322
repo.start_write_group()
323
repo.add_inventory('C-id', inv, ['B-id'])
324
repo.commit_write_group()
325
self.assertEqual([('A-id',), ('B-id',), ('C-id',)],
326
sorted(repo.inventories.keys()))
328
self.assertEqual([('A-id',), ('B-id',), ('C-id',)],
329
sorted(repo.inventories.keys()))
330
# Content should be preserved as well
331
self.assertEqual(inv, repo.iter_inventories(['C-id']).next())
298
333
def test_pack_layout(self):
299
334
# Test that the ordering of revisions in pack repositories is
311
346
# revision access tends to be tip->ancestor, so ordering that way on
312
347
# disk is a good idea.
313
348
for _1, key, val, refs in pack.revision_index.iter_all_entries():
314
if type(format.repository_format) is RepositoryFormatCHK1:
349
if type(format.repository_format) is RepositoryFormat2a:
315
350
# group_start, group_len, internal_start, internal_len
316
351
pos = map(int, val.split())
590
625
def make_write_ready_repo(self):
591
626
format = self.get_format()
592
if isinstance(format.repository_format, RepositoryFormatCHK1):
627
if isinstance(format.repository_format, RepositoryFormat2a):
593
628
raise TestNotApplicable("No missing compression parents")
594
629
repo = self.make_repository('.', format=format)
595
630
repo.lock_write()
865
900
base.commit('foo')
866
901
referencing = self.make_branch_and_tree('repo', format=self.get_format())
867
902
referencing.branch.repository.add_fallback_repository(base.branch.repository)
868
referencing.commit('bar')
903
local_tree = referencing.branch.create_checkout('local')
904
local_tree.commit('bar')
869
905
new_instance = referencing.bzrdir.open_repository()
870
906
new_instance.lock_read()
871
907
self.addCleanup(new_instance.unlock)
884
920
# and max packs policy - so we are checking the policy is honoured
885
921
# in the test. But for now 11 commits is not a big deal in a single
923
local_tree = tree.branch.create_checkout('local')
887
924
for x in range(9):
888
tree.commit('commit %s' % x)
925
local_tree.commit('commit %s' % x)
889
926
# there should be 9 packs:
890
927
index = self.index_class(trans, 'pack-names', None)
891
928
self.assertEqual(9, len(list(index.iter_all_entries())))
892
929
# committing one more should coalesce to 1 of 10.
893
tree.commit('commit triggering pack')
930
local_tree.commit('commit triggering pack')
894
931
index = self.index_class(trans, 'pack-names', None)
895
932
self.assertEqual(1, len(list(index.iter_all_entries())))
896
933
# packing should not damage data
909
946
# in the obsolete_packs directory.
910
947
large_pack_name = list(index.iter_all_entries())[0][1][0]
911
948
# finally, committing again should not touch the large pack.
912
tree.commit('commit not triggering pack')
949
local_tree.commit('commit not triggering pack')
913
950
index = self.index_class(trans, 'pack-names', None)
914
951
self.assertEqual(2, len(list(index.iter_all_entries())))
915
952
pack_names = [node[1][0] for node in index.iter_all_entries()]
1014
1051
tree.branch.push(remote_branch)
1015
1052
autopack_calls = len([call for call in self.hpss_calls if call ==
1016
1053
'PackRepository.autopack'])
1017
streaming_calls = len([call for call in self.hpss_calls if call ==
1018
'Repository.insert_stream'])
1054
streaming_calls = len([call for call in self.hpss_calls if call in
1055
('Repository.insert_stream', 'Repository.insert_stream_1.19')])
1019
1056
if autopack_calls:
1020
1057
# Non streaming server
1021
1058
self.assertEqual(1, autopack_calls)
1061
1098
format_supports_external_lookups=True,
1062
1099
index_class=BTreeGraphIndex),
1063
dict(format_name='development6-rich-root',
1064
format_string='Bazaar development format - group compression '
1065
'and chk inventory (needs bzr.dev from 1.14)\n',
1100
dict(format_name='2a',
1101
format_string="Bazaar repository format 2a "
1102
"(needs bzr 1.16 or later)\n",
1066
1103
format_supports_external_lookups=True,
1067
1104
index_class=BTreeGraphIndex),