~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

(robertc) Pack 2a repositories after fetching from a different format
        (bug 376748) and fix problems with autopacking 2a repositories
        (bug 365615). (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1404
1404
            raise errors.BzrError('mismatched lock context %r and '
1405
1405
                'write group %r.' %
1406
1406
                (self.get_transaction(), self._write_group))
1407
 
        self._commit_write_group()
 
1407
        result = self._commit_write_group()
1408
1408
        self._write_group = None
 
1409
        return result
1409
1410
 
1410
1411
    def _commit_write_group(self):
1411
1412
        """Template method for per-repository write group cleanup.
2418
2419
            keys = tsort.topo_sort(parent_map)
2419
2420
        return [None] + list(keys)
2420
2421
 
2421
 
    def pack(self):
 
2422
    def pack(self, hint=None):
2422
2423
        """Compress the data within the repository.
2423
2424
 
2424
2425
        This operation only makes sense for some repository types. For other
2427
2428
        This stub method does not require a lock, but subclasses should use
2428
2429
        @needs_write_lock as this is a long running call its reasonable to
2429
2430
        implicitly lock for the user.
 
2431
 
 
2432
        :param hint: If not supplied, the whole repository is packed.
 
2433
            If supplied, the repository may use the hint parameter as a
 
2434
            hint for the parts of the repository to pack. A hint can be
 
2435
            obtained from the result of commit_write_group(). Out of
 
2436
            date hints are simply ignored, because concurrent operations
 
2437
            can obsolete them rapidly.
2430
2438
        """
2431
2439
 
2432
2440
    def get_transaction(self):
2835
2843
    # Does this format have < O(tree_size) delta generation. Used to hint what
2836
2844
    # code path for commit, amongst other things.
2837
2845
    fast_deltas = None
 
2846
    # Does doing a pack operation compress data? Useful for the pack UI command
 
2847
    # (so if there is one pack, the operation can still proceed because it may
 
2848
    # help), and for fetching when data won't have come from the same
 
2849
    # compressor.
 
2850
    pack_compresses = False
2838
2851
 
2839
2852
    def __str__(self):
2840
2853
        return "<%s>" % self.__class__.__name__
3666
3679
        cache = lru_cache.LRUCache(100)
3667
3680
        cache[basis_id] = basis_tree
3668
3681
        del basis_tree # We don't want to hang on to it here
 
3682
        hints = []
3669
3683
        for offset in range(0, len(revision_ids), batch_size):
3670
3684
            self.target.start_write_group()
3671
3685
            try:
3677
3691
                self.target.abort_write_group()
3678
3692
                raise
3679
3693
            else:
3680
 
                self.target.commit_write_group()
 
3694
                hint = self.target.commit_write_group()
 
3695
                if hint:
 
3696
                    hints.extend(hint)
 
3697
        if hints and self.target._format.pack_compresses:
 
3698
            self.target.pack(hint=hints)
3681
3699
        pb.update('Transferring revisions', len(revision_ids),
3682
3700
                  len(revision_ids))
3683
3701
 
4025
4043
                # missing keys can handle suspending a write group).
4026
4044
                write_group_tokens = self.target_repo.suspend_write_group()
4027
4045
                return write_group_tokens, missing_keys
4028
 
        self.target_repo.commit_write_group()
 
4046
        hint = self.target_repo.commit_write_group()
 
4047
        if (to_serializer != src_serializer and
 
4048
            self.target_repo._format.pack_compresses):
 
4049
            self.target_repo.pack(hint=hint)
4029
4050
        return [], set()
4030
4051
 
4031
4052
    def _extract_and_insert_inventories(self, substream, serializer):