369
369
tree = self.make_branch_and_memory_tree('tree')
370
370
tree.lock_write()
372
tree.add([''], ['root-id'])
373
tree.commit('one', rev_id='rev-1')
374
tree.commit('two', rev_id='rev-2')
375
tree.commit('three', rev_id='rev-3')
376
# Pack these two revisions into another pack file, but don't remove
378
repo = tree.branch.repository
379
collection = repo._pack_collection
380
collection.ensure_loaded()
381
orig_packs = collection.packs
382
packer = pack_repo.Packer(collection, orig_packs, '.testpack')
383
new_pack = packer.pack()
385
vf = tree.branch.repository.revisions
388
tree.branch.repository.lock_read()
389
371
self.addCleanup(tree.branch.repository.unlock)
372
tree.add([''], ['root-id'])
373
tree.commit('one', rev_id='rev-1')
374
tree.commit('two', rev_id='rev-2')
375
tree.commit('three', rev_id='rev-3')
376
# Pack these three revisions into another pack file, but don't remove
378
repo = tree.branch.repository
379
collection = repo._pack_collection
380
collection.ensure_loaded()
381
orig_packs = collection.packs
382
packer = pack_repo.Packer(collection, orig_packs, '.testpack')
383
new_pack = packer.pack()
384
# forget about the new pack
387
vf = tree.branch.repository.revisions
391
389
# Set up a reload() function that switches to using the new pack file
392
390
new_index = new_pack.revision_index
1093
1091
call[1][1].getvalue())
1094
1092
self.assertEqual({'create_parent_dir': True}, call[2])
1094
def assertTotalBuildSize(self, size, keys, positions):
1095
self.assertEqual(size,
1096
knit._get_total_build_size(None, keys, positions))
1098
def test__get_total_build_size(self):
1100
('a',): (('fulltext', False), (('a',), 0, 100), None),
1101
('b',): (('line-delta', False), (('b',), 100, 21), ('a',)),
1102
('c',): (('line-delta', False), (('c',), 121, 35), ('b',)),
1103
('d',): (('line-delta', False), (('d',), 156, 12), ('b',)),
1105
self.assertTotalBuildSize(100, [('a',)], positions)
1106
self.assertTotalBuildSize(121, [('b',)], positions)
1107
# c needs both a & b
1108
self.assertTotalBuildSize(156, [('c',)], positions)
1109
# we shouldn't count 'b' twice
1110
self.assertTotalBuildSize(156, [('b',), ('c',)], positions)
1111
self.assertTotalBuildSize(133, [('d',)], positions)
1112
self.assertTotalBuildSize(168, [('c',), ('d',)], positions)
1096
1114
def test_get_position(self):
1097
1115
transport = MockTransport([
1098
1116
_KndxIndex.HEADER,
1867
1885
self.assertEqual([], self.caught_entries)
1888
class TestKnitVersionedFiles(KnitTests):
1890
def assertGroupKeysForIo(self, exp_groups, keys, non_local_keys,
1891
positions, _min_buffer_size=None):
1892
kvf = self.make_test_knit()
1893
if _min_buffer_size is None:
1894
_min_buffer_size = knit._STREAM_MIN_BUFFER_SIZE
1895
self.assertEqual(exp_groups, kvf._group_keys_for_io(keys,
1896
non_local_keys, positions,
1897
_min_buffer_size=_min_buffer_size))
1899
def assertSplitByPrefix(self, expected_map, expected_prefix_order,
1901
split, prefix_order = KnitVersionedFiles._split_by_prefix(keys)
1902
self.assertEqual(expected_map, split)
1903
self.assertEqual(expected_prefix_order, prefix_order)
1905
def test__group_keys_for_io(self):
1906
ft_detail = ('fulltext', False)
1907
ld_detail = ('line-delta', False)
1915
f_a: (ft_detail, (f_a, 0, 100), None),
1916
f_b: (ld_detail, (f_b, 100, 21), f_a),
1917
f_c: (ld_detail, (f_c, 180, 15), f_b),
1918
g_a: (ft_detail, (g_a, 121, 35), None),
1919
g_b: (ld_detail, (g_b, 156, 12), g_a),
1920
g_c: (ld_detail, (g_c, 195, 13), g_a),
1922
self.assertGroupKeysForIo([([f_a], set())],
1923
[f_a], [], positions)
1924
self.assertGroupKeysForIo([([f_a], set([f_a]))],
1925
[f_a], [f_a], positions)
1926
self.assertGroupKeysForIo([([f_a, f_b], set([]))],
1927
[f_a, f_b], [], positions)
1928
self.assertGroupKeysForIo([([f_a, f_b], set([f_b]))],
1929
[f_a, f_b], [f_b], positions)
1930
self.assertGroupKeysForIo([([f_a, f_b, g_a, g_b], set())],
1931
[f_a, g_a, f_b, g_b], [], positions)
1932
self.assertGroupKeysForIo([([f_a, f_b, g_a, g_b], set())],
1933
[f_a, g_a, f_b, g_b], [], positions,
1934
_min_buffer_size=150)
1935
self.assertGroupKeysForIo([([f_a, f_b], set()), ([g_a, g_b], set())],
1936
[f_a, g_a, f_b, g_b], [], positions,
1937
_min_buffer_size=100)
1938
self.assertGroupKeysForIo([([f_c], set()), ([g_b], set())],
1939
[f_c, g_b], [], positions,
1940
_min_buffer_size=125)
1941
self.assertGroupKeysForIo([([g_b, f_c], set())],
1942
[g_b, f_c], [], positions,
1943
_min_buffer_size=125)
1945
def test__split_by_prefix(self):
1946
self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
1947
'g': [('g', 'b'), ('g', 'a')],
1949
[('f', 'a'), ('g', 'b'),
1950
('g', 'a'), ('f', 'b')])
1952
self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
1953
'g': [('g', 'b'), ('g', 'a')],
1955
[('f', 'a'), ('f', 'b'),
1956
('g', 'b'), ('g', 'a')])
1958
self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
1959
'g': [('g', 'b'), ('g', 'a')],
1961
[('f', 'a'), ('f', 'b'),
1962
('g', 'b'), ('g', 'a')])
1964
self.assertSplitByPrefix({'f': [('f', 'a'), ('f', 'b')],
1965
'g': [('g', 'b'), ('g', 'a')],
1966
'': [('a',), ('b',)]
1968
[('f', 'a'), ('g', 'b'),
1970
('g', 'a'), ('f', 'b')])
1870
1973
class TestStacking(KnitTests):
1872
1975
def get_basis_and_test_knit(self):