~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Vincent Ladeuil
  • Date: 2017-01-30 14:30:10 UTC
  • mfrom: (6615.3.7 merges)
  • mto: This revision was merged to the branch mainline in revision 6621.
  • Revision ID: v.ladeuil+lp@free.fr-20170130143010-p31t1ranfeqbaeki
Merge  2.7 into trunk including fix for bug #1657238

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
384
384
            self._real_store = _mod_config.ControlStore(self.bzrdir)
385
385
 
386
386
    def external_url(self):
387
 
        return self.bzrdir.user_url
 
387
        return urlutils.join(self.branch.user_url, 'control.conf')
388
388
 
389
389
    def _load_content(self):
390
390
        medium = self.bzrdir._client._medium
1051
1051
            network_name = self._network_name
1052
1052
        else:
1053
1053
            # Select the current bzrlib default and ask for that.
1054
 
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
 
1054
            reference_bzrdir_format = controldir.format_registry.get('default')()
1055
1055
            reference_format = reference_bzrdir_format.repository_format
1056
1056
            network_name = reference_format.network_name()
1057
1057
        # 2) try direct creation via RPC
2160
2160
        self._ensure_real()
2161
2161
        self._real_repository.create_bundle(target, base, fileobj, format)
2162
2162
 
2163
 
    @needs_read_lock
2164
 
    @symbol_versioning.deprecated_method(
2165
 
        symbol_versioning.deprecated_in((2, 4, 0)))
2166
 
    def get_ancestry(self, revision_id, topo_sorted=True):
2167
 
        self._ensure_real()
2168
 
        return self._real_repository.get_ancestry(revision_id, topo_sorted)
2169
 
 
2170
2163
    def fileids_altered_by_revision_ids(self, revision_ids):
2171
2164
        self._ensure_real()
2172
2165
        return self._real_repository.fileids_altered_by_revision_ids(revision_ids)
2709
2702
    def supports_rich_root(self):
2710
2703
        return self._format.rich_root_data
2711
2704
 
2712
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2713
 
    def iter_reverse_revision_history(self, revision_id):
2714
 
        self._ensure_real()
2715
 
        return self._real_repository.iter_reverse_revision_history(revision_id)
2716
 
 
2717
2705
    @property
2718
2706
    def _serializer(self):
2719
2707
        return self._format._serializer
3129
3117
        return a_bzrdir.open_branch(name=name, 
3130
3118
            ignore_fallbacks=ignore_fallbacks)
3131
3119
 
3132
 
    def _vfs_initialize(self, a_bzrdir, name, append_revisions_only):
 
3120
    def _vfs_initialize(self, a_bzrdir, name, append_revisions_only,
 
3121
                        repository=None):
3133
3122
        # Initialisation when using a local bzrdir object, or a non-vfs init
3134
3123
        # method is not available on the server.
3135
3124
        # self._custom_format is always set - the start of initialize ensures
3137
3126
        if isinstance(a_bzrdir, RemoteBzrDir):
3138
3127
            a_bzrdir._ensure_real()
3139
3128
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3140
 
                name=name, append_revisions_only=append_revisions_only)
 
3129
                name=name, append_revisions_only=append_revisions_only,
 
3130
                repository=repository)
3141
3131
        else:
3142
3132
            # We assume the bzrdir is parameterised; it may not be.
3143
3133
            result = self._custom_format.initialize(a_bzrdir, name=name,
3144
 
                append_revisions_only=append_revisions_only)
 
3134
                append_revisions_only=append_revisions_only,
 
3135
                repository=repository)
3145
3136
        if (isinstance(a_bzrdir, RemoteBzrDir) and
3146
3137
            not isinstance(result, RemoteBranch)):
3147
3138
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
3157
3148
            network_name = self._custom_format.network_name()
3158
3149
        else:
3159
3150
            # Select the current bzrlib default and ask for that.
3160
 
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
 
3151
            reference_bzrdir_format = controldir.format_registry.get('default')()
3161
3152
            reference_format = reference_bzrdir_format.get_branch_format()
3162
3153
            self._custom_format = reference_format
3163
3154
            network_name = reference_format.network_name()
3164
3155
        # Being asked to create on a non RemoteBzrDir:
3165
3156
        if not isinstance(a_bzrdir, RemoteBzrDir):
3166
3157
            return self._vfs_initialize(a_bzrdir, name=name,
3167
 
                append_revisions_only=append_revisions_only)
 
3158
                append_revisions_only=append_revisions_only,
 
3159
                repository=repository)
3168
3160
        medium = a_bzrdir._client._medium
3169
3161
        if medium._is_remote_before((1, 13)):
3170
3162
            return self._vfs_initialize(a_bzrdir, name=name,
3171
 
                append_revisions_only=append_revisions_only)
 
3163
                append_revisions_only=append_revisions_only,
 
3164
                repository=repository)
3172
3165
        # Creating on a remote bzr dir.
3173
3166
        # 2) try direct creation via RPC
3174
3167
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
3182
3175
            # Fallback - use vfs methods
3183
3176
            medium._remember_remote_is_before((1, 13))
3184
3177
            return self._vfs_initialize(a_bzrdir, name=name,
3185
 
                    append_revisions_only=append_revisions_only)
 
3178
                    append_revisions_only=append_revisions_only,
 
3179
                    repository=repository)
3186
3180
        if response[0] != 'ok':
3187
3181
            raise errors.UnexpectedSmartServerResponse(response)
3188
3182
        # Turn the response into a RemoteRepository object.
3262
3256
        self.id = "branch"
3263
3257
        self._real_store = None
3264
3258
 
3265
 
    def lock_write(self, token=None):
3266
 
        return self.branch.lock_write(token)
3267
 
 
3268
 
    def unlock(self):
3269
 
        return self.branch.unlock()
3270
 
 
3271
 
    @needs_write_lock
3272
 
    def save(self):
3273
 
        # We need to be able to override the undecorated implementation
3274
 
        self.save_without_locking()
3275
 
 
3276
 
    def save_without_locking(self):
3277
 
        super(RemoteBranchStore, self).save()
3278
 
 
3279
3259
    def external_url(self):
3280
 
        return self.branch.user_url
 
3260
        return urlutils.join(self.branch.user_url, 'branch.conf')
3281
3261
 
3282
3262
    def _load_content(self):
3283
3263
        path = self.branch._remote_path()
3366
3346
        self._repo_lock_token = None
3367
3347
        self._lock_count = 0
3368
3348
        self._leave_lock = False
 
3349
        self.conf_store = None
3369
3350
        # Setup a format: note that we cannot call _ensure_real until all the
3370
3351
        # attributes above are set: This code cannot be moved higher up in this
3371
3352
        # function.
3414
3395
        return RemoteBranchConfig(self)
3415
3396
 
3416
3397
    def _get_config_store(self):
3417
 
        return RemoteBranchStore(self)
 
3398
        if self.conf_store is None:
 
3399
            self.conf_store =  RemoteBranchStore(self)
 
3400
        return self.conf_store
 
3401
 
 
3402
    def store_uncommitted(self, creator):
 
3403
        self._ensure_real()
 
3404
        return self._real_branch.store_uncommitted(creator)
 
3405
 
 
3406
    def get_unshelver(self, tree):
 
3407
        self._ensure_real()
 
3408
        return self._real_branch.get_unshelver(tree)
3418
3409
 
3419
3410
    def _get_real_transport(self):
3420
3411
        # if we try vfs access, return the real branch's vfs transport
3440
3431
            self.bzrdir._ensure_real()
3441
3432
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
3442
3433
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
 
3434
            # The remote branch and the real branch shares the same store. If
 
3435
            # we don't, there will always be cases where one of the stores
 
3436
            # doesn't see an update made on the other.
 
3437
            self._real_branch.conf_store = self.conf_store
3443
3438
            if self.repository._real_repository is None:
3444
3439
                # Give the remote repository the matching real repo.
3445
3440
                real_repo = self._real_branch.repository
3523
3518
 
3524
3519
    def set_stacked_on_url(self, url):
3525
3520
        branch.Branch.set_stacked_on_url(self, url)
 
3521
        # We need the stacked_on_url to be visible both locally (to not query
 
3522
        # it repeatedly) and remotely (so smart verbs can get it server side)
 
3523
        # Without the following line,
 
3524
        # bzrlib.tests.per_branch.test_create_clone.TestCreateClone
 
3525
        # .test_create_clone_on_transport_stacked_hooks_get_stacked_branch
 
3526
        # fails for remote branches -- vila 2012-01-04
 
3527
        self.conf_store.save_changes()
3526
3528
        if not url:
3527
3529
            self._is_stacked = False
3528
3530
        else:
3656
3658
        try:
3657
3659
            self._lock_count -= 1
3658
3660
            if not self._lock_count:
 
3661
                if self.conf_store is not None:
 
3662
                    self.conf_store.save_changes()
3659
3663
                self._clear_cached_state()
3660
3664
                mode = self._lock_mode
3661
3665
                self._lock_mode = None
3790
3794
            raise errors.UnexpectedSmartServerResponse(response)
3791
3795
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
3792
3796
 
3793
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
3794
 
    @needs_write_lock
3795
 
    def set_revision_history(self, rev_history):
3796
 
        """See Branch.set_revision_history."""
3797
 
        self._set_revision_history(rev_history)
3798
 
 
3799
 
    @needs_write_lock
3800
 
    def _set_revision_history(self, rev_history):
3801
 
        # Send just the tip revision of the history; the server will generate
3802
 
        # the full history from that.  If the revision doesn't exist in this
3803
 
        # branch, NoSuchRevision will be raised.
3804
 
        if rev_history == []:
3805
 
            rev_id = 'null:'
3806
 
        else:
3807
 
            rev_id = rev_history[-1]
3808
 
        self._set_last_revision(rev_id)
3809
 
        for hook in branch.Branch.hooks['set_rh']:
3810
 
            hook(self, rev_history)
3811
 
        self._cache_revision_history(rev_history)
3812
 
 
3813
3797
    def _get_parent_location(self):
3814
3798
        medium = self._client._medium
3815
3799
        if medium._is_remote_before((1, 13)):
3867
3851
            target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
3868
3852
            _override_hook_source_branch=self)
3869
3853
 
 
3854
    def peek_lock_mode(self):
 
3855
        return self._lock_mode
 
3856
 
3870
3857
    def is_locked(self):
3871
3858
        return self._lock_count >= 1
3872
3859
 
3947
3934
            except errors.UnknownSmartMethod:
3948
3935
                medium._remember_remote_is_before((1, 6))
3949
3936
        self._clear_cached_state_of_remote_branch_only()
3950
 
        self._set_revision_history(self._lefthand_history(revision_id,
3951
 
            last_rev=last_rev,other_branch=other_branch))
 
3937
        graph = self.repository.get_graph()
 
3938
        (last_revno, last_revid) = self.last_revision_info()
 
3939
        known_revision_ids = [
 
3940
            (last_revid, last_revno),
 
3941
            (_mod_revision.NULL_REVISION, 0),
 
3942
            ]
 
3943
        if last_rev is not None:
 
3944
            if not graph.is_ancestor(last_rev, revision_id):
 
3945
                # our previous tip is not merged into stop_revision
 
3946
                raise errors.DivergedBranches(self, other_branch)
 
3947
        revno = graph.find_distance_to_null(revision_id, known_revision_ids)
 
3948
        self.set_last_revision_info(revno, revision_id)
3952
3949
 
3953
3950
    def set_push_location(self, location):
3954
 
        self._ensure_real()
3955
 
        return self._real_branch.set_push_location(location)
 
3951
        self._set_config_location('push_location', location)
3956
3952
 
3957
3953
    def heads_to_fetch(self):
3958
3954
        if self._format._use_default_local_heads_to_fetch():