~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.py

Avoid reopening (and relocking) the same branches/repositories in ControlDir.sprout.  Still a few rough edges, but the tests I've run are passing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
        self._ensure_real()
247
247
        self._real_bzrdir.destroy_repository()
248
248
 
249
 
    def create_branch(self, name=None):
 
249
    def create_branch(self, name=None, repository=None):
250
250
        # as per meta1 formats - just delegate to the format object which may
251
251
        # be parameterised.
252
252
        real_branch = self._format.get_branch_format().initialize(self,
253
 
            name=name)
 
253
            name=name, repository=repository)
254
254
        if not isinstance(real_branch, RemoteBranch):
255
 
            result = RemoteBranch(self, self.find_repository(), real_branch,
256
 
                                  name=name)
 
255
            if not isinstance(repository, RemoteRepository):
 
256
                raise AssertionError('xxx %r' % (repository,))
 
257
            result = RemoteBranch(self, repository, real_branch, name=name)
257
258
        else:
258
259
            result = real_branch
259
260
        # BzrDir.clone_on_transport() uses the result of create_branch but does
2093
2094
                                  name=name)
2094
2095
        return result
2095
2096
 
2096
 
    def initialize(self, a_bzrdir, name=None):
 
2097
    def initialize(self, a_bzrdir, name=None, repository=None):
2097
2098
        # 1) get the network name to use.
2098
2099
        if self._custom_format:
2099
2100
            network_name = self._custom_format.network_name()
2127
2128
        # Turn the response into a RemoteRepository object.
2128
2129
        format = RemoteBranchFormat(network_name=response[1])
2129
2130
        repo_format = response_tuple_to_repo_format(response[3:])
2130
 
        if response[2] == '':
2131
 
            repo_bzrdir = a_bzrdir
 
2131
        repo_path = response[2]
 
2132
        if repository is not None:
 
2133
            if repository.bzrdir.root_transport.base != medium.base + repo_path:
 
2134
                raise AssertionError(
 
2135
                    'xxx %r vs. %r %r' % (repository, medium.base, repo_path))
 
2136
            remote_repo = repository
2132
2137
        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)
 
2138
            if repo_path == '':
 
2139
                repo_bzrdir = a_bzrdir
 
2140
            else:
 
2141
                repo_bzrdir = RemoteBzrDir(
 
2142
                    a_bzrdir.root_transport.clone(repo_path), a_bzrdir._format,
 
2143
                    a_bzrdir._client)
 
2144
            remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2137
2145
        remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2138
2146
            format=format, setup_stacking=False, name=name)
2139
2147
        # XXX: We know this is a new branch, so it must have revno 0, revid