~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: Martin Packman
  • Date: 2012-02-01 13:24:42 UTC
  • mto: (6437.23.4 2.5)
  • mto: This revision was merged to the branch mainline in revision 6462.
  • Revision ID: martin.packman@canonical.com-20120201132442-ela7jc4mxv4b058o
Treat path for .bzr.log as unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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 urlutils.join(self.branch.user_url, 'control.conf')
 
387
        return self.bzrdir.user_url
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 = controldir.format_registry.get('default')()
 
1054
            reference_bzrdir_format = _mod_bzrdir.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
 
2163
2170
    def fileids_altered_by_revision_ids(self, revision_ids):
2164
2171
        self._ensure_real()
2165
2172
        return self._real_repository.fileids_altered_by_revision_ids(revision_ids)
2702
2709
    def supports_rich_root(self):
2703
2710
        return self._format.rich_root_data
2704
2711
 
 
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
 
2705
2717
    @property
2706
2718
    def _serializer(self):
2707
2719
        return self._format._serializer
3117
3129
        return a_bzrdir.open_branch(name=name, 
3118
3130
            ignore_fallbacks=ignore_fallbacks)
3119
3131
 
3120
 
    def _vfs_initialize(self, a_bzrdir, name, append_revisions_only,
3121
 
                        repository=None):
 
3132
    def _vfs_initialize(self, a_bzrdir, name, append_revisions_only):
3122
3133
        # Initialisation when using a local bzrdir object, or a non-vfs init
3123
3134
        # method is not available on the server.
3124
3135
        # self._custom_format is always set - the start of initialize ensures
3126
3137
        if isinstance(a_bzrdir, RemoteBzrDir):
3127
3138
            a_bzrdir._ensure_real()
3128
3139
            result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3129
 
                name=name, append_revisions_only=append_revisions_only,
3130
 
                repository=repository)
 
3140
                name=name, append_revisions_only=append_revisions_only)
3131
3141
        else:
3132
3142
            # We assume the bzrdir is parameterised; it may not be.
3133
3143
            result = self._custom_format.initialize(a_bzrdir, name=name,
3134
 
                append_revisions_only=append_revisions_only,
3135
 
                repository=repository)
 
3144
                append_revisions_only=append_revisions_only)
3136
3145
        if (isinstance(a_bzrdir, RemoteBzrDir) and
3137
3146
            not isinstance(result, RemoteBranch)):
3138
3147
            result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
3148
3157
            network_name = self._custom_format.network_name()
3149
3158
        else:
3150
3159
            # Select the current bzrlib default and ask for that.
3151
 
            reference_bzrdir_format = controldir.format_registry.get('default')()
 
3160
            reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
3152
3161
            reference_format = reference_bzrdir_format.get_branch_format()
3153
3162
            self._custom_format = reference_format
3154
3163
            network_name = reference_format.network_name()
3155
3164
        # Being asked to create on a non RemoteBzrDir:
3156
3165
        if not isinstance(a_bzrdir, RemoteBzrDir):
3157
3166
            return self._vfs_initialize(a_bzrdir, name=name,
3158
 
                append_revisions_only=append_revisions_only,
3159
 
                repository=repository)
 
3167
                append_revisions_only=append_revisions_only)
3160
3168
        medium = a_bzrdir._client._medium
3161
3169
        if medium._is_remote_before((1, 13)):
3162
3170
            return self._vfs_initialize(a_bzrdir, name=name,
3163
 
                append_revisions_only=append_revisions_only,
3164
 
                repository=repository)
 
3171
                append_revisions_only=append_revisions_only)
3165
3172
        # Creating on a remote bzr dir.
3166
3173
        # 2) try direct creation via RPC
3167
3174
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
3175
3182
            # Fallback - use vfs methods
3176
3183
            medium._remember_remote_is_before((1, 13))
3177
3184
            return self._vfs_initialize(a_bzrdir, name=name,
3178
 
                    append_revisions_only=append_revisions_only,
3179
 
                    repository=repository)
 
3185
                    append_revisions_only=append_revisions_only)
3180
3186
        if response[0] != 'ok':
3181
3187
            raise errors.UnexpectedSmartServerResponse(response)
3182
3188
        # Turn the response into a RemoteRepository object.
3256
3262
        self.id = "branch"
3257
3263
        self._real_store = None
3258
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
 
3259
3279
    def external_url(self):
3260
 
        return urlutils.join(self.branch.user_url, 'branch.conf')
 
3280
        return self.branch.user_url
3261
3281
 
3262
3282
    def _load_content(self):
3263
3283
        path = self.branch._remote_path()
3346
3366
        self._repo_lock_token = None
3347
3367
        self._lock_count = 0
3348
3368
        self._leave_lock = False
3349
 
        self.conf_store = None
3350
3369
        # Setup a format: note that we cannot call _ensure_real until all the
3351
3370
        # attributes above are set: This code cannot be moved higher up in this
3352
3371
        # function.
3395
3414
        return RemoteBranchConfig(self)
3396
3415
 
3397
3416
    def _get_config_store(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)
 
3417
        return RemoteBranchStore(self)
3409
3418
 
3410
3419
    def _get_real_transport(self):
3411
3420
        # if we try vfs access, return the real branch's vfs transport
3431
3440
            self.bzrdir._ensure_real()
3432
3441
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
3433
3442
                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
3438
3443
            if self.repository._real_repository is None:
3439
3444
                # Give the remote repository the matching real repo.
3440
3445
                real_repo = self._real_branch.repository
3518
3523
 
3519
3524
    def set_stacked_on_url(self, url):
3520
3525
        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()
3528
3526
        if not url:
3529
3527
            self._is_stacked = False
3530
3528
        else:
3658
3656
        try:
3659
3657
            self._lock_count -= 1
3660
3658
            if not self._lock_count:
3661
 
                if self.conf_store is not None:
3662
 
                    self.conf_store.save_changes()
3663
3659
                self._clear_cached_state()
3664
3660
                mode = self._lock_mode
3665
3661
                self._lock_mode = None
3794
3790
            raise errors.UnexpectedSmartServerResponse(response)
3795
3791
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
3796
3792
 
 
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
 
3797
3813
    def _get_parent_location(self):
3798
3814
        medium = self._client._medium
3799
3815
        if medium._is_remote_before((1, 13)):
3851
3867
            target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
3852
3868
            _override_hook_source_branch=self)
3853
3869
 
3854
 
    def peek_lock_mode(self):
3855
 
        return self._lock_mode
3856
 
 
3857
3870
    def is_locked(self):
3858
3871
        return self._lock_count >= 1
3859
3872
 
3934
3947
            except errors.UnknownSmartMethod:
3935
3948
                medium._remember_remote_is_before((1, 6))
3936
3949
        self._clear_cached_state_of_remote_branch_only()
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)
 
3950
        self._set_revision_history(self._lefthand_history(revision_id,
 
3951
            last_rev=last_rev,other_branch=other_branch))
3949
3952
 
3950
3953
    def set_push_location(self, location):
3951
 
        self._set_config_location('push_location', location)
 
3954
        self._ensure_real()
 
3955
        return self._real_branch.set_push_location(location)
3952
3956
 
3953
3957
    def heads_to_fetch(self):
3954
3958
        if self._format._use_default_local_heads_to_fetch():