/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to repofmt.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-25 22:14:29 UTC
  • mto: (0.20.19 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090225221429-l0is3qxy1hvzuhes
A first-cut at implementing an auto-pack by copying everything.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
231
231
 
232
 
    def _do_autopack(self):
233
 
        return False
 
232
    def _execute_pack_operations(self, pack_operations, _packer_class=Packer,
 
233
                                 reload_func=None):
 
234
        """Execute a series of pack operations.
 
235
 
 
236
        :param pack_operations: A list of [revision_count, packs_to_combine].
 
237
        :param _packer_class: The class of packer to use (default: Packer).
 
238
        :return: None.
 
239
        """
 
240
        for revision_count, packs in pack_operations:
 
241
            # we may have no-ops from the setup logic
 
242
            if len(packs) == 0:
 
243
                continue
 
244
            # Create a new temp VersionedFile instance based on these packs,
 
245
            # and then just fetch everything into the target
 
246
 
 
247
            # XXX: Find a way to 'set_optimize' on the newly created pack
 
248
            #      indexes
 
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)
 
257
            #       return new_pack
 
258
            to_copy = [('revision_index', 'revisions'),
 
259
                       ('inventory_index', 'inventories'),
 
260
                       ('text_index', 'texts'),
 
261
                       ('signature_index', 'signatures'),
 
262
                      ]
 
263
            if getattr(self, 'chk_index', None) is not None:
 
264
                to_copy.insert(2, ('chk_index', 'chk_bytes'))
 
265
 
 
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'
 
269
                                      ' being written.'
 
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()
 
275
            try:
 
276
                for index_name, vf_name in to_copy:
 
277
                    keys = set()
 
278
                    new_index = getattr(self._new_pack, index_name)
 
279
                    new_index.set_optimize(for_size=True)
 
280
                    for pack in packs:
 
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)
 
286
            except:
 
287
                self._abort_write_group()
 
288
            else:
 
289
                self._commit_write_group()
 
290
            for pack in packs:
 
291
                self._remove_pack_from_memory(pack)
 
292
        # record the newly available packs and stop advertising the old
 
293
        # packs
 
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)
234
298
 
235
299
 
236
300