~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

Bring the groupcompress code into brisbane-core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2677
2677
    'bzrlib.repofmt.pack_repo',
2678
2678
    'RepositoryFormatPackDevelopment5Hash255',
2679
2679
    )
 
2680
# XXX: This format is scheduled for termination
 
2681
# format_registry.register_lazy(
 
2682
#     'Bazaar development format - btree+gc (needs bzr.dev from 1.13)\n',
 
2683
#     'bzrlib.repofmt.groupcompress_repo',
 
2684
#     'RepositoryFormatPackGCPlain',
 
2685
#     )
 
2686
format_registry.register_lazy(
 
2687
    'Bazaar development format - hash16chk+gc rich-root (needs bzr.dev from 1.13)\n',
 
2688
    'bzrlib.repofmt.groupcompress_repo',
 
2689
    'RepositoryFormatPackGCCHK16',
 
2690
    )
 
2691
format_registry.register_lazy(
 
2692
    'Bazaar development format - hash255chk+gc rich-root (needs bzr.dev from 1.13)\n',
 
2693
    'bzrlib.repofmt.groupcompress_repo',
 
2694
    'RepositoryFormatPackGCCHK255',
 
2695
    )
 
2696
format_registry.register_lazy(
 
2697
    'Bazaar development format - hash255chk+gc rich-root bigpage (needs bzr.dev from 1.13)\n',
 
2698
    'bzrlib.repofmt.groupcompress_repo',
 
2699
    'RepositoryFormatPackGCCHK255Big',
 
2700
    )
2680
2701
 
2681
2702
 
2682
2703
class InterRepository(InterObject):
3100
3121
        Do not support CHK based repositories at this point.
3101
3122
        """
3102
3123
        from bzrlib.repofmt.pack_repo import RepositoryFormatPack
 
3124
        # XXX: This format is scheduled for termination
 
3125
        # from bzrlib.repofmt.groupcompress_repo import (
 
3126
        #     RepositoryFormatPackGCPlain,
 
3127
        #     )
3103
3128
        try:
3104
3129
            are_packs = (isinstance(source._format, RepositoryFormatPack) and
3105
3130
                isinstance(target._format, RepositoryFormatPack))
3106
3131
        except AttributeError:
3107
3132
            return False
3108
 
        return (are_packs and InterRepository._same_model(source, target) and
 
3133
        if not are_packs:
 
3134
            return False
 
3135
        # if (isinstance(source._format, RepositoryFormatPackGCPlain)
 
3136
        #     or isinstance(target._format, RepositoryFormatPackGCPlain)):
 
3137
        #     return False
 
3138
        return (InterRepository._same_model(source, target) and
3109
3139
            not source._format.supports_chks)
3110
3140
 
3111
3141
    @needs_write_lock
3237
3267
    @staticmethod
3238
3268
    def is_compatible(source, target):
3239
3269
        """Be compatible with Knit2 source and Knit3 target"""
3240
 
        if source.supports_rich_root() != target.supports_rich_root():
3241
 
            return False
 
3270
        # XXX: What do we need to do to support fetching them?
 
3271
        # if source.supports_rich_root() != target.supports_rich_root():
 
3272
        #     return False
3242
3273
        # Ideally, we'd support fetching if the source had no tree references
3243
3274
        # even if it supported them...
3244
 
        if (getattr(source, '_format.supports_tree_reference', False) and
3245
 
            not getattr(target, '_format.supports_tree_reference', False)):
3246
 
            return False
 
3275
        # XXX: What do we need to do to support fetching them?
 
3276
        # if (getattr(source._format, 'supports_tree_reference', False) and
 
3277
        #     not getattr(target._format, 'supports_tree_reference', False)):
 
3278
        #    return False
3247
3279
        return True
3248
3280
 
3249
3281
    def _get_delta_for_revision(self, tree, parent_ids, basis_id, cache):
3278
3310
        # Walk though all revisions; get inventory deltas, copy referenced
3279
3311
        # texts that delta references, insert the delta, revision and
3280
3312
        # signature.
 
3313
        root_keys_to_create = set()
3281
3314
        text_keys = set()
3282
3315
        pending_deltas = []
3283
3316
        pending_revisions = []
3290
3323
            parent_ids = parent_map.get(current_revision_id, ())
3291
3324
            basis_id, delta = self._get_delta_for_revision(tree, parent_ids,
3292
3325
                                                           basis_id, cache)
 
3326
            if self._converting_to_rich_root:
 
3327
                self._revision_id_to_root_id[current_revision_id] = \
 
3328
                    tree.get_root_id()
3293
3329
            # Find text entries that need to be copied
3294
3330
            for old_path, new_path, file_id, entry in delta:
3295
3331
                if new_path is not None:
3296
 
                    if not (new_path or self.target.supports_rich_root()):
3297
 
                        # We don't copy the text for the root node unless the
3298
 
                        # target supports_rich_root.
3299
 
                        continue
 
3332
                    if not new_path:
 
3333
                        # This is the root
 
3334
                        if not self.target.supports_rich_root():
 
3335
                            # The target doesn't support rich root, so we don't
 
3336
                            # copy
 
3337
                            continue
 
3338
                        if self._converting_to_rich_root:
 
3339
                            # This can't be copied normally, we have to insert
 
3340
                            # it specially
 
3341
                            root_keys_to_create.add((file_id, entry.revision))
 
3342
                            continue
3300
3343
                    text_keys.add((file_id, entry.revision))
3301
3344
            revision = self.source.get_revision(current_revision_id)
3302
3345
            pending_deltas.append((basis_id, delta,
3307
3350
        # Copy file texts
3308
3351
        from_texts = self.source.texts
3309
3352
        to_texts = self.target.texts
 
3353
        if root_keys_to_create:
 
3354
            NULL_REVISION = _mod_revision.NULL_REVISION
 
3355
            def _get_parent_keys(root_key):
 
3356
                root_id, rev_id = root_key
 
3357
                # Include direct parents of the revision, but only if they used
 
3358
                # the same root_id.
 
3359
                parent_keys = tuple([(root_id, parent_id)
 
3360
                    for parent_id in parent_map[rev_id]
 
3361
                    if parent_id != NULL_REVISION and
 
3362
                        rev_id_to_root.get(parent_id, root_id) == root_id])
 
3363
                return parent_keys
 
3364
            def new_root_data_stream():
 
3365
                rev_id_to_root = self._revision_id_to_root_id
 
3366
                for root_key in root_keys_to_create:
 
3367
                    parent_keys = _get_parent_keys(root_key)
 
3368
                    yield versionedfile.FulltextContentFactory(root_key,
 
3369
                        parent_keys, None, '')
 
3370
            to_texts.insert_record_stream(new_root_data_stream())
3310
3371
        to_texts.insert_record_stream(from_texts.get_record_stream(
3311
3372
            text_keys, self.target._format._fetch_order,
3312
3373
            not self.target._format._fetch_uses_deltas))
3359
3420
        """See InterRepository.fetch()."""
3360
3421
        if fetch_spec is not None:
3361
3422
            raise AssertionError("Not implemented yet...")
 
3423
        if (not self.source.supports_rich_root()
 
3424
            and self.target.supports_rich_root()):
 
3425
            self._converting_to_rich_root = True
 
3426
            self._revision_id_to_root_id = {}
 
3427
        else:
 
3428
            self._converting_to_rich_root = False
3362
3429
        revision_ids = self.target.search_missing_revision_ids(self.source,
3363
3430
            revision_id, find_ghosts=find_ghosts).get_keys()
3364
3431
        if not revision_ids: