~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-04 22:47:34 UTC
  • mfrom: (2951.1.11 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071104224734-8l8km2gqk9n1pdla
(robertc) Stage one of reconcile for pack repositories - perform inventory gc. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    errors,
31
31
    ui,
32
32
    repository,
 
33
    repofmt,
33
34
    )
34
35
from bzrlib.trace import mutter, note
35
36
from bzrlib.tsort import TopoSorter
468
469
 
469
470
    def _reconcile_steps(self):
470
471
        """Perform the steps to reconcile this repository."""
 
472
        if not self.thorough:
 
473
            return
 
474
        collection = self.repo._pack_collection
 
475
        collection.ensure_loaded()
 
476
        collection.lock_names()
 
477
        try:
 
478
            packs = collection.all_packs()
 
479
            all_revisions = self.repo.all_revision_ids()
 
480
            total_inventories = len(list(
 
481
                collection.inventory_index.combined_index.iter_all_entries()))
 
482
            if len(all_revisions):
 
483
                self._packer = repofmt.pack_repo.ReconcilePacker(
 
484
                    collection, packs, ".reconcile", all_revisions)
 
485
                new_pack = self._packer.pack(pb=self.pb)
 
486
                if new_pack is not None:
 
487
                    self._discard_and_save(packs)
 
488
            else:
 
489
                # only make a new pack when there is data to copy.
 
490
                self._discard_and_save(packs)
 
491
            self.garbage_inventories = total_inventories - len(list(
 
492
                collection.inventory_index.combined_index.iter_all_entries()))
 
493
        finally:
 
494
            collection._unlock_names()
 
495
 
 
496
    def _discard_and_save(self, packs):
 
497
        """Discard some packs from the repository.
 
498
 
 
499
        This removes them from the memory index, saves the in-memory index
 
500
        which makes the newly reconciled pack visible and hides the packs to be
 
501
        discarded, and finally renames the packs being discarded into the
 
502
        obsolete packs directory.
 
503
 
 
504
        :param packs: The packs to discard.
 
505
        """
 
506
        for pack in packs:
 
507
            self.repo._pack_collection._remove_pack_from_memory(pack)
 
508
        self.repo._pack_collection._save_pack_names()
 
509
        self.repo._pack_collection._obsolete_packs(packs)