229
229
self.repo.signatures._index._add_callback = self.signature_index.add_callback
230
230
self.repo.texts._index._add_callback = self.text_index.add_callback
232
def _do_autopack(self):
232
def _execute_pack_operations(self, pack_operations, _packer_class=Packer,
234
"""Execute a series of pack operations.
236
:param pack_operations: A list of [revision_count, packs_to_combine].
237
:param _packer_class: The class of packer to use (default: Packer).
240
for revision_count, packs in pack_operations:
241
# we may have no-ops from the setup logic
244
# Create a new temp VersionedFile instance based on these packs,
245
# and then just fetch everything into the target
247
# XXX: Find a way to 'set_optimize' on the newly created pack
249
# def open_pack(self):
250
# """Open a pack for the pack we are creating."""
251
# new_pack = super(OptimisingPacker, self).open_pack()
252
# # Turn on the optimization flags for all the index builders.
253
# new_pack.revision_index.set_optimize(for_size=True)
254
# new_pack.inventory_index.set_optimize(for_size=True)
255
# new_pack.text_index.set_optimize(for_size=True)
256
# new_pack.signature_index.set_optimize(for_size=True)
258
to_copy = [('revision_index', 'revisions'),
259
('inventory_index', 'inventories'),
260
('text_index', 'texts'),
261
('signature_index', 'signatures'),
263
if getattr(self, 'chk_index', None) is not None:
264
to_copy.insert(2, ('chk_index', 'chk_bytes'))
266
# Shouldn't we start_write_group around this?
267
if self._new_pack is not None:
268
raise errors.BzrError('call to %s.pack() while another pack is'
270
% (self.__class__.__name__,))
271
# TODO: A better alternative is to probably use Packer.open_pack(), and
272
# then create a GroupCompressVersionedFiles() around the
273
# target pack to insert into.
274
self._start_write_group()
276
for index_name, vf_name in to_copy:
278
new_index = getattr(self._new_pack, index_name)
279
new_index.set_optimize(for_size=True)
281
source_index = getattr(pack, index_name)
282
keys.update(e[1] for e in source_index.iter_all_entries())
283
vf = getattr(self.repo, vf_name)
284
stream = vf.get_record_stream(keys, 'gc-optimal', True)
285
vf.insert_record_stream(stream)
287
self._abort_write_group()
289
self._commit_write_group()
291
self._remove_pack_from_memory(pack)
292
# record the newly available packs and stop advertising the old
294
self._save_pack_names(clear_obsolete_packs=True)
295
# Move the old packs out of the way now they are no longer referenced.
296
for revision_count, packs in pack_operations:
297
self._obsolete_packs(packs)