~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

  • Committer: John Arbash Meinel
  • Date: 2011-01-10 22:20:12 UTC
  • mfrom: (5582 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5599.
  • Revision ID: john@arbash-meinel.com-20110110222012-mtcqudkvmzwiufuc
Merge in the bzr.dev 5582

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
33
33
    revision as _mod_revision,
34
34
    static_tuple,
35
35
    symbol_versioning,
 
36
    urlutils,
36
37
)
37
38
from bzrlib.branch import BranchReferenceFormat, BranchWriteLockResult
38
39
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
246
247
        self._ensure_real()
247
248
        self._real_bzrdir.destroy_repository()
248
249
 
249
 
    def create_branch(self, name=None):
 
250
    def create_branch(self, name=None, repository=None):
250
251
        # as per meta1 formats - just delegate to the format object which may
251
252
        # be parameterised.
252
253
        real_branch = self._format.get_branch_format().initialize(self,
253
 
            name=name)
 
254
            name=name, repository=repository)
254
255
        if not isinstance(real_branch, RemoteBranch):
255
 
            result = RemoteBranch(self, self.find_repository(), real_branch,
256
 
                                  name=name)
 
256
            if not isinstance(repository, RemoteRepository):
 
257
                raise AssertionError(
 
258
                    'need a RemoteRepository to use with RemoteBranch, got %r'
 
259
                    % (repository,))
 
260
            result = RemoteBranch(self, repository, real_branch, name=name)
257
261
        else:
258
262
            result = real_branch
259
263
        # BzrDir.clone_on_transport() uses the result of create_branch but does
2093
2097
                                  name=name)
2094
2098
        return result
2095
2099
 
2096
 
    def initialize(self, a_bzrdir, name=None):
 
2100
    def initialize(self, a_bzrdir, name=None, repository=None):
2097
2101
        # 1) get the network name to use.
2098
2102
        if self._custom_format:
2099
2103
            network_name = self._custom_format.network_name()
2127
2131
        # Turn the response into a RemoteRepository object.
2128
2132
        format = RemoteBranchFormat(network_name=response[1])
2129
2133
        repo_format = response_tuple_to_repo_format(response[3:])
2130
 
        if response[2] == '':
2131
 
            repo_bzrdir = a_bzrdir
 
2134
        repo_path = response[2]
 
2135
        if repository is not None:
 
2136
            remote_repo_url = urlutils.join(medium.base, repo_path)
 
2137
            url_diff = urlutils.relative_url(repository.user_url,
 
2138
                    remote_repo_url)
 
2139
            if url_diff != '.':
 
2140
                raise AssertionError(
 
2141
                    'repository.user_url %r does not match URL from server '
 
2142
                    'response (%r + %r)'
 
2143
                    % (repository.user_url, medium.base, repo_path))
 
2144
            remote_repo = repository
2132
2145
        else:
2133
 
            repo_bzrdir = RemoteBzrDir(
2134
 
                a_bzrdir.root_transport.clone(response[2]), a_bzrdir._format,
2135
 
                a_bzrdir._client)
2136
 
        remote_repo = RemoteRepository(repo_bzrdir, repo_format)
 
2146
            if repo_path == '':
 
2147
                repo_bzrdir = a_bzrdir
 
2148
            else:
 
2149
                repo_bzrdir = RemoteBzrDir(
 
2150
                    a_bzrdir.root_transport.clone(repo_path), a_bzrdir._format,
 
2151
                    a_bzrdir._client)
 
2152
            remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2137
2153
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2138
2154
            format=format, setup_stacking=False, name=name)
2139
2155
        # XXX: We know this is a new branch, so it must have revno 0, revid