~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-04 07:10:07 UTC
  • mto: (4086.1.2 hpss-integration)
  • mto: This revision was merged to the branch mainline in revision 4087.
  • Revision ID: andrew.bennetts@canonical.com-20090304071007-8iqoi1m44ypmzg2a
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1096
1096
    def _resume_write_group(self, tokens):
1097
1097
        raise errors.UnsuspendableWriteGroup(self)
1098
1098
 
1099
 
    def fetch(self, source, revision_id=None, pb=None, find_ghosts=False):
 
1099
    def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
 
1100
            fetch_spec=None):
1100
1101
        """Fetch the content required to construct revision_id from source.
1101
1102
 
1102
1103
        If revision_id is None all content is copied.
1104
1105
            ghosts in the target (and not reachable directly by walking out to
1105
1106
            the first-present revision in target from revision_id).
1106
1107
        """
 
1108
        if fetch_spec is not None and revision_id is not None:
 
1109
            raise AssertionError(
 
1110
                "fetch_spec and revision_id are mutually exclusive.")
1107
1111
        # fast path same-url fetch operations
1108
 
        if self.has_same_location(source):
 
1112
        if self.has_same_location(source) and fetch_spec is None:
1109
1113
            # check that last_revision is in 'from' and then return a
1110
1114
            # no-operation.
1111
1115
            if (revision_id is not None and
1117
1121
        # IncompatibleRepositories when asked to fetch.
1118
1122
        inter = InterRepository.get(source, self)
1119
1123
        return inter.fetch(revision_id=revision_id, pb=pb,
1120
 
            find_ghosts=find_ghosts)
 
1124
            find_ghosts=find_ghosts, fetch_spec=fetch_spec)
1121
1125
 
1122
1126
    def create_bundle(self, target, base, fileobj, format=None):
1123
1127
        return serializer.write_bundle(self, target, base, fileobj, format)
2041
2045
        """
2042
2046
        raise NotImplementedError(self.revision_graph_can_have_wrong_parents)
2043
2047
 
 
2048
    def is_empty(self):
 
2049
        return False
 
2050
 
2044
2051
 
2045
2052
# remove these delegates a while after bzr 0.15
2046
2053
def __make_delegated(name, from_module):
2579
2586
            pass
2580
2587
        self.target.fetch(self.source, revision_id=revision_id)
2581
2588
 
2582
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
2589
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
2590
            fetch_spec=None):
2583
2591
        """Fetch the content required to construct revision_id.
2584
2592
 
2585
2593
        The content is copied from self.source to self.target.
2597
2605
        f = RepoFetcher(to_repository=self.target,
2598
2606
                               from_repository=self.source,
2599
2607
                               last_revision=revision_id,
 
2608
                               fetch_spec=fetch_spec,
2600
2609
                               pb=pb, find_ghosts=find_ghosts)
2601
2610
 
2602
2611
    def _walk_to_common_revisions(self, revision_ids):
2812
2821
            self.target.fetch(self.source, revision_id=revision_id)
2813
2822
 
2814
2823
    @needs_write_lock
2815
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
2824
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
2825
            fetch_spec=None):
2816
2826
        """See InterRepository.fetch()."""
2817
2827
        from bzrlib.fetch import RepoFetcher
2818
2828
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2820
2830
        f = RepoFetcher(to_repository=self.target,
2821
2831
                               from_repository=self.source,
2822
2832
                               last_revision=revision_id,
 
2833
                               fetch_spec=fetch_spec,
2823
2834
                               pb=pb, find_ghosts=find_ghosts)
2824
2835
 
2825
2836
    @needs_read_lock
2892
2903
        return are_knits and InterRepository._same_model(source, target)
2893
2904
 
2894
2905
    @needs_write_lock
2895
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
2906
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
2907
            fetch_spec=None):
2896
2908
        """See InterRepository.fetch()."""
2897
2909
        from bzrlib.fetch import RepoFetcher
2898
2910
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2900
2912
        f = RepoFetcher(to_repository=self.target,
2901
2913
                            from_repository=self.source,
2902
2914
                            last_revision=revision_id,
 
2915
                            fetch_spec=fetch_spec,
2903
2916
                            pb=pb, find_ghosts=find_ghosts)
2904
2917
 
2905
2918
    @needs_read_lock
2961
2974
        return are_packs and InterRepository._same_model(source, target)
2962
2975
 
2963
2976
    @needs_write_lock
2964
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
2977
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
2978
            fetch_spec=None):
2965
2979
        """See InterRepository.fetch()."""
2966
2980
        if (len(self.source._fallback_repositories) > 0 or
2967
2981
            len(self.target._fallback_repositories) > 0):
2971
2985
            # attributes on repository.
2972
2986
            from bzrlib.fetch import RepoFetcher
2973
2987
            fetcher = RepoFetcher(self.target, self.source, revision_id,
2974
 
                                  pb, find_ghosts)
 
2988
                    pb, find_ghosts, fetch_spec=fetch_spec)
2975
2989
        mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2976
2990
               self.source, self.source._format, self.target, self.target._format)
 
2991
        if fetch_spec is not None:
 
2992
            revision_id = fetch_spec.start_key
 
2993
            fetch_spec = None
2977
2994
        if revision_id is None:
2978
2995
            # TODO:
2979
2996
            # everything to do - use pack logic
3033
3050
        return self.target._pack_collection
3034
3051
 
3035
3052
    @needs_read_lock
3036
 
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
3053
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True,
 
3054
            fetch_spec=None):
3037
3055
        """See InterRepository.missing_revision_ids().
3038
3056
 
3039
3057
        :param find_ghosts: Find ghosts throughout the ancestry of
3040
3058
            revision_id.
3041
3059
        """
3042
 
        if not find_ghosts and revision_id is not None:
3043
 
            return self._walk_to_common_revisions([revision_id])
 
3060
        rev_specified = (revision_id is not None and fetch_spec is not None)
 
3061
        if not find_ghosts and rev_specified:
 
3062
            if fetch_spec is not None:
 
3063
                return fetch_spec
 
3064
            else:
 
3065
                return self._walk_to_common_revisions([revision_id])
 
3066
        elif fetch_spec is not None:
 
3067
            raise AssertionError("not implemented yet...")
3044
3068
        elif revision_id is not None:
3045
3069
            # Find ghosts: search for revisions pointing from one repository to
3046
3070
            # the other, and vice versa, anywhere in the history of revision_id.
3198
3222
                  len(revision_ids))
3199
3223
 
3200
3224
    @needs_write_lock
3201
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
3225
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
3226
            fetch_spec=None):
3202
3227
        """See InterRepository.fetch()."""
 
3228
        if fetch_spec is not None:
 
3229
            raise AssertionError("Not implemented yet...")
3203
3230
        revision_ids = self.target.search_missing_revision_ids(self.source,
3204
3231
            revision_id, find_ghosts=find_ghosts).get_keys()
3205
3232
        if not revision_ids:
3271
3298
        self._ensure_real_inter()
3272
3299
        self._real_inter.copy_content(revision_id=revision_id)
3273
3300
 
3274
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
3301
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
3302
            fetch_spec=None):
3275
3303
        self._ensure_real_inter()
3276
3304
        return self._real_inter.fetch(revision_id=revision_id, pb=pb,
3277
 
            find_ghosts=find_ghosts)
 
3305
            find_ghosts=find_ghosts, fetch_spec=fetch_spec)
3278
3306
 
3279
3307
    @classmethod
3280
3308
    def _get_repo_format_to_test(self):
3300
3328
            self._real_inter = InterRepository.get(real_source, self.target)
3301
3329
 
3302
3330
    @needs_write_lock
3303
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
3331
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
3332
            fetch_spec=None):
3304
3333
        """See InterRepository.fetch()."""
3305
3334
        # Always fetch using the generic streaming fetch code, to allow
3306
3335
        # streaming fetching from remote servers.
3307
3336
        from bzrlib.fetch import RepoFetcher
3308
3337
        fetcher = RepoFetcher(self.target, self.source, revision_id,
3309
 
                              pb, find_ghosts)
 
3338
                pb, find_ghosts, fetch_spec=fetch_spec)
3310
3339
 
3311
3340
    def copy_content(self, revision_id=None):
3312
3341
        self._ensure_real_inter()
3344
3373
        self.target.autopack()
3345
3374
 
3346
3375
    @needs_write_lock
3347
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False):
 
3376
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
 
3377
            fetch_spec=None):
3348
3378
        """See InterRepository.fetch()."""
3349
3379
        # Always fetch using the generic streaming fetch code, to allow
3350
3380
        # streaming fetching into remote servers.
3351
3381
        from bzrlib.fetch import RepoFetcher
3352
3382
        fetcher = RepoFetcher(self.target, self.source, revision_id,
3353
 
                              pb, find_ghosts)
 
3383
                              pb, find_ghosts, fetch_spec=fetch_spec)
3354
3384
 
3355
3385
    def _get_target_pack_collection(self):
3356
3386
        return self.target._real_repository._pack_collection