17
17
"""Server-side bzrdir related request implmentations."""
20
from bzrlib import errors
20
from bzrlib import branch, errors, repository
21
21
from bzrlib.bzrdir import BzrDir, BzrDirFormat
22
22
from bzrlib.smart.request import (
23
23
FailedSmartServerResponse,
24
24
SmartServerRequest,
25
25
SuccessfulSmartServerResponse,
27
from bzrlib.repository import network_format_registry
30
29
class SmartServerRequestOpenBzrDir(SmartServerRequest):
68
67
repo_format.supports_external_lookups)
69
68
return rich_root, tree_ref, external_lookup
70
def _repo_relpath(self, current_transport, repository):
71
"""Get the relative path for repository from current_transport."""
72
# the relpath of the bzrdir in the found repository gives us the
73
# path segments to pop-out.
74
relpath = repository.bzrdir.root_transport.relpath(
75
current_transport.base)
77
segments = ['..'] * len(relpath.split('/'))
80
return '/'.join(segments)
83
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
85
def do(self, path, network_name):
86
"""Create a branch in the bzr dir at path.
88
This operates precisely like 'bzrdir.create_branch'.
90
If a bzrdir is not present, an exception is propogated
91
rather than 'no branch' because these are different conditions (and
92
this method should only be called after establishing that a bzr dir
95
This is the initial version of this method introduced to the smart
98
:param path: The path to the bzrdir.
99
:param network_name: The network name of the branch type to create.
100
:return: (ok, network_name)
102
bzrdir = BzrDir.open_from_transport(
103
self.transport_from_client_path(path))
104
format = branch.network_format_registry.get(network_name)
105
bzrdir.branch_format = format
106
result = format.initialize(bzrdir)
107
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
108
result.repository._format)
109
branch_format = result._format.network_name()
110
repo_format = result.repository._format.network_name()
111
repo_path = self._repo_relpath(bzrdir.root_transport,
113
# branch format, repo relpath, rich_root, tree_ref, external_lookup,
115
return SuccessfulSmartServerResponse(('ok', branch_format, repo_path,
116
rich_root, tree_ref, external_lookup, repo_format))
72
119
class SmartServerRequestCreateRepository(SmartServerRequestBzrDir):
93
140
bzrdir = BzrDir.open_from_transport(
94
141
self.transport_from_client_path(path))
95
142
shared = shared == 'True'
96
format = network_format_registry.get(network_name)
143
format = repository.network_format_registry.get(network_name)
97
144
bzrdir.repository_format = format
98
145
result = format.initialize(bzrdir, shared=shared)
99
146
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
118
165
bzrdir = BzrDir.open_from_transport(
119
166
self.transport_from_client_path(path))
120
167
repository = bzrdir.find_repository()
121
# the relpath of the bzrdir in the found repository gives us the
122
# path segments to pop-out.
123
relpath = repository.bzrdir.root_transport.relpath(
124
bzrdir.root_transport.base)
126
segments = ['..'] * len(relpath.split('/'))
168
path = self._repo_relpath(bzrdir.root_transport, repository)
129
169
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
130
170
repository._format)
131
return '/'.join(segments), rich_root, tree_ref, external_lookup
171
return path, rich_root, tree_ref, external_lookup
134
174
class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):