~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

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
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
3157
3157
            network_name = self._custom_format.network_name()
3158
3158
        else:
3159
3159
            # Select the current bzrlib default and ask for that.
3160
 
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
 
3160
            reference_bzrdir_format = controldir.format_registry.get('default')()
3161
3161
            reference_format = reference_bzrdir_format.get_branch_format()
3162
3162
            self._custom_format = reference_format
3163
3163
            network_name = reference_format.network_name()
3262
3262
        self.id = "branch"
3263
3263
        self._real_store = None
3264
3264
 
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
3265
    def external_url(self):
3280
3266
        return self.branch.user_url
3281
3267
 
3366
3352
        self._repo_lock_token = None
3367
3353
        self._lock_count = 0
3368
3354
        self._leave_lock = False
 
3355
        self.conf_store = None
3369
3356
        # Setup a format: note that we cannot call _ensure_real until all the
3370
3357
        # attributes above are set: This code cannot be moved higher up in this
3371
3358
        # function.
3414
3401
        return RemoteBranchConfig(self)
3415
3402
 
3416
3403
    def _get_config_store(self):
3417
 
        return RemoteBranchStore(self)
 
3404
        if self.conf_store is None:
 
3405
            self.conf_store =  RemoteBranchStore(self)
 
3406
        return self.conf_store
3418
3407
 
3419
3408
    def _get_real_transport(self):
3420
3409
        # if we try vfs access, return the real branch's vfs transport
3440
3429
            self.bzrdir._ensure_real()
3441
3430
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
3442
3431
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
 
3432
            # The remote branch and the real branch shares the same store. If
 
3433
            # we don't, there will always be cases where one of the stores
 
3434
            # doesn't see an update made on the other.
 
3435
            self._real_branch.conf_store = self.conf_store
3443
3436
            if self.repository._real_repository is None:
3444
3437
                # Give the remote repository the matching real repo.
3445
3438
                real_repo = self._real_branch.repository
3523
3516
 
3524
3517
    def set_stacked_on_url(self, url):
3525
3518
        branch.Branch.set_stacked_on_url(self, url)
 
3519
        # We need the stacked_on_url to be visible both locally (to not query
 
3520
        # it repeatedly) and remotely (so smart verbs can get it server side)
 
3521
        # Without the following line,
 
3522
        # bzrlib.tests.per_branch.test_create_clone.TestCreateClone
 
3523
        # .test_create_clone_on_transport_stacked_hooks_get_stacked_branch
 
3524
        # fails for remote branches -- vila 2012-01-04
 
3525
        self.conf_store.save_changes()
3526
3526
        if not url:
3527
3527
            self._is_stacked = False
3528
3528
        else:
3656
3656
        try:
3657
3657
            self._lock_count -= 1
3658
3658
            if not self._lock_count:
 
3659
                if self.conf_store is not None:
 
3660
                    self.conf_store.save_changes()
3659
3661
                self._clear_cached_state()
3660
3662
                mode = self._lock_mode
3661
3663
                self._lock_mode = None
3790
3792
            raise errors.UnexpectedSmartServerResponse(response)
3791
3793
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
3792
3794
 
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
3795
    def _get_parent_location(self):
3814
3796
        medium = self._client._medium
3815
3797
        if medium._is_remote_before((1, 13)):
3947
3929
            except errors.UnknownSmartMethod:
3948
3930
                medium._remember_remote_is_before((1, 6))
3949
3931
        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))
 
3932
        graph = self.repository.get_graph()
 
3933
        (last_revno, last_revid) = self.last_revision_info()
 
3934
        known_revision_ids = [
 
3935
            (last_revid, last_revno),
 
3936
            (_mod_revision.NULL_REVISION, 0),
 
3937
            ]
 
3938
        if last_rev is not None:
 
3939
            if not graph.is_ancestor(last_rev, revision_id):
 
3940
                # our previous tip is not merged into stop_revision
 
3941
                raise errors.DivergedBranches(self, other_branch)
 
3942
        revno = graph.find_distance_to_null(revision_id, known_revision_ids)
 
3943
        self.set_last_revision_info(revno, revision_id)
3952
3944
 
3953
3945
    def set_push_location(self, location):
3954
 
        self._ensure_real()
3955
 
        return self._real_branch.set_push_location(location)
 
3946
        self._set_config_location('push_location', location)
3956
3947
 
3957
3948
    def heads_to_fetch(self):
3958
3949
        if self._format._use_default_local_heads_to_fetch():