13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Server-side bzrdir related request implmentations."""
20
20
from bzrlib import branch, errors, repository
21
from bzrlib.bzrdir import BzrDir, BzrDirFormat, BzrDirMetaFormat1
21
from bzrlib.bzrdir import (
25
network_format_registry,
22
27
from bzrlib.smart.request import (
23
28
FailedSmartServerResponse,
24
29
SmartServerRequest,
92
97
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
94
99
def do_bzrdir_request(self, require_stacking):
95
"""Get the format that should be used when cloning from this dir."""
100
"""Get the format that should be used when cloning from this dir.
104
:return: on success, a 3-tuple of network names for (control,
105
repository, branch) directories, where '' signifies "not present".
106
If this BzrDir contains a branch reference then this will fail with
107
BranchReference; clients should resolve branch references before
97
111
branch_ref = self._bzrdir.get_branch_reference()
98
112
except errors.NotBranchError:
114
if branch_ref is not None:
115
# The server shouldn't try to resolve references, and it quite
116
# possibly can't reach them anyway. The client needs to resolve
117
# the branch reference to determine the cloning_metadir.
118
return FailedSmartServerResponse(('BranchReference',))
100
119
if require_stacking == "True":
101
120
require_stacking = True
104
123
control_format = self._bzrdir.cloning_metadir(
105
124
require_stacking=require_stacking)
106
125
control_name = control_format.network_name()
107
# XXX: There should be a method that tells us that the format does/does not
126
# XXX: There should be a method that tells us that the format does/does
127
# not have subformats.
109
128
if isinstance(control_format, BzrDirMetaFormat1):
110
if branch_ref is not None:
111
# If there's a branch reference, the client will have to resolve
112
# the branch reference to figure out the cloning metadir
113
branch_name = ('ref', branch_ref)
115
branch_name = ('branch',
116
control_format.get_branch_format().network_name())
129
branch_name = ('branch',
130
control_format.get_branch_format().network_name())
117
131
repository_name = control_format.repository_format.network_name()
119
133
# Only MetaDir has delegated formats today.
301
330
return SuccessfulSmartServerResponse(('ok', ))
333
class SmartServerRequestBzrDirInitializeEx(SmartServerRequestBzrDir):
335
def parse_NoneTrueFalse(self, arg):
342
raise AssertionError("invalid arg %r" % arg)
344
def parse_NoneString(self, arg):
347
def _serialize_NoneTrueFalse(self, arg):
354
def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
355
force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
356
make_working_trees, shared_repo):
357
"""Initialize a bzrdir at path as per BzrDirFormat.initialize_ex
359
:return: return SuccessfulSmartServerResponse((repo_path, rich_root,
360
tree_ref, external_lookup, repo_network_name,
361
repo_bzrdir_network_name, bzrdir_format_network_name,
362
NoneTrueFalse(stacking), final_stack, final_stack_pwd,
365
target_transport = self.transport_from_client_path(path)
366
format = network_format_registry.get(bzrdir_network_name)
367
use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
368
create_prefix = self.parse_NoneTrueFalse(create_prefix)
369
force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
370
stacked_on = self.parse_NoneString(stacked_on)
371
stack_on_pwd = self.parse_NoneString(stack_on_pwd)
372
make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
373
shared_repo = self.parse_NoneTrueFalse(shared_repo)
374
if stack_on_pwd == '.':
375
stack_on_pwd = target_transport.base
376
repo_format_name = self.parse_NoneString(repo_format_name)
377
repo, bzrdir, stacking, repository_policy = \
378
format.initialize_on_transport_ex(target_transport,
379
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
380
force_new_repo=force_new_repo, stacked_on=stacked_on,
381
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
382
make_working_trees=make_working_trees, shared_repo=shared_repo)
386
rich_root = tree_ref = external_lookup = ''
387
repo_bzrdir_name = ''
389
final_stack_pwd = None
392
repo_path = self._repo_relpath(bzrdir.root_transport, repo)
395
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
397
repo_name = repo._format.network_name()
398
repo_bzrdir_name = repo.bzrdir._format.network_name()
399
final_stack = repository_policy._stack_on
400
final_stack_pwd = repository_policy._stack_on_pwd
401
# It is returned locked, but we need to do the lock to get the lock
404
repo_lock_token = repo.lock_write() or ''
406
repo.leave_lock_in_place()
408
final_stack = final_stack or ''
409
final_stack_pwd = final_stack_pwd or ''
410
return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
411
external_lookup, repo_name, repo_bzrdir_name,
412
bzrdir._format.network_name(),
413
self._serialize_NoneTrueFalse(stacking), final_stack,
414
final_stack_pwd, repo_lock_token))
304
417
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
306
419
def do_bzrdir_request(self):