~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

Merge pt1 hooks branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1573
1573
        mutter('Packing repository %s, which has %d pack files, '
1574
1574
            'containing %d revisions with hint %r.', self, total_packs,
1575
1575
            total_revisions, hint)
 
1576
        while True:
 
1577
            try:
 
1578
                self._try_pack_operations(hint)
 
1579
            except RetryPackOperations:
 
1580
                continue
 
1581
            break
 
1582
 
 
1583
        if clean_obsolete_packs:
 
1584
            self._clear_obsolete_packs()
 
1585
 
 
1586
    def _try_pack_operations(self, hint):
 
1587
        """Calculate the pack operations based on the hint (if any), and
 
1588
        execute them.
 
1589
        """
1576
1590
        # determine which packs need changing
1577
1591
        pack_operations = [[0, []]]
1578
1592
        for pack in self.all_packs():
1581
1595
                # or this pack was included in the hint.
1582
1596
                pack_operations[-1][0] += pack.get_revision_count()
1583
1597
                pack_operations[-1][1].append(pack)
1584
 
        self._execute_pack_operations(pack_operations, OptimisingPacker)
1585
 
 
1586
 
        if clean_obsolete_packs:
1587
 
            self._clear_obsolete_packs()
 
1598
        self._execute_pack_operations(pack_operations, OptimisingPacker,
 
1599
            reload_func=self._restart_pack_operations)
1588
1600
 
1589
1601
    def plan_autopack_combinations(self, existing_packs, pack_distribution):
1590
1602
        """Plan a pack operation.
2044
2056
            raise
2045
2057
        raise errors.RetryAutopack(self.repo, False, sys.exc_info())
2046
2058
 
 
2059
    def _restart_pack_operations(self):
 
2060
        """Reload the pack names list, and restart the autopack code."""
 
2061
        if not self.reload_pack_names():
 
2062
            # Re-raise the original exception, because something went missing
 
2063
            # and a restart didn't find it
 
2064
            raise
 
2065
        raise RetryPackOperations(self.repo, False, sys.exc_info())
 
2066
 
2047
2067
    def _clear_obsolete_packs(self, preserve=None):
2048
2068
        """Delete everything from the obsolete-packs directory.
2049
2069
 
2933
2953
        return ("Development repository format, currently the same as "
2934
2954
            "1.6.1-subtree with B+Tree indices.\n")
2935
2955
 
 
2956
 
 
2957
class RetryPackOperations(errors.RetryWithNewPacks):
 
2958
    """Raised when we are packing and we find a missing file.
 
2959
 
 
2960
    Meant as a signaling exception, to tell the RepositoryPackCollection.pack
 
2961
    code it should try again.
 
2962
    """
 
2963
 
 
2964
    internal_error = True
 
2965
 
 
2966
    _fmt = ("Pack files have changed, reload and try pack again."
 
2967
            " context: %(context)s %(orig_error)s")
 
2968
 
 
2969