62
def _format_to_capabilities(self, repo_format):
63
rich_root = self._boolean_to_yes_no(repo_format.rich_root_data)
64
tree_ref = self._boolean_to_yes_no(
65
repo_format.supports_tree_reference)
66
external_lookup = self._boolean_to_yes_no(
67
repo_format.supports_external_lookups)
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))
119
class SmartServerRequestCreateRepository(SmartServerRequestBzrDir):
121
def do(self, path, network_name, shared):
122
"""Create a repository in the bzr dir at path.
124
This operates precisely like 'bzrdir.create_repository'.
126
If a bzrdir is not present, an exception is propogated
127
rather than 'no branch' because these are different conditions (and
128
this method should only be called after establishing that a bzr dir
131
This is the initial version of this method introduced to the smart
134
:param path: The path to the bzrdir.
135
:param network_name: The network name of the repository type to create.
136
:param shared: The value to pass create_repository for the shared
138
:return: (ok, rich_root, tree_ref, external_lookup, network_name)
140
bzrdir = BzrDir.open_from_transport(
141
self.transport_from_client_path(path))
142
shared = shared == 'True'
143
format = repository.network_format_registry.get(network_name)
144
bzrdir.repository_format = format
145
result = format.initialize(bzrdir, shared=shared)
146
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
148
return SuccessfulSmartServerResponse(('ok', rich_root, tree_ref,
149
external_lookup, result._format.network_name()))
152
class SmartServerRequestFindRepository(SmartServerRequestBzrDir):
62
154
def _find(self, path):
63
155
"""try to find a repository from path upwards
65
157
This operates precisely like 'bzrdir.find_repository'.
67
159
:return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
68
160
strings, relpath is a / prefixed path, and the other three are
69
161
either 'yes' or 'no'.
73
165
bzrdir = BzrDir.open_from_transport(
74
166
self.transport_from_client_path(path))
75
167
repository = bzrdir.find_repository()
76
# the relpath of the bzrdir in the found repository gives us the
77
# path segments to pop-out.
78
relpath = repository.bzrdir.root_transport.relpath(
79
bzrdir.root_transport.base)
81
segments = ['..'] * len(relpath.split('/'))
84
rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
85
tree_ref = self._boolean_to_yes_no(
86
repository._format.supports_tree_reference)
87
external_lookup = self._boolean_to_yes_no(
88
repository._format.supports_external_lookups)
89
return '/'.join(segments), rich_root, tree_ref, external_lookup
168
path = self._repo_relpath(bzrdir.root_transport, repository)
169
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
171
return path, rich_root, tree_ref, external_lookup
92
174
class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):
94
176
def do(self, path):
95
177
"""try to find a repository from path upwards
97
179
This operates precisely like 'bzrdir.find_repository'.
99
181
If a bzrdir is not present, an exception is propogated
100
182
rather than 'no branch' because these are different conditions.