~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-27 06:47:50 UTC
  • mfrom: (4294.2.12 push.roundtrips)
  • Revision ID: pqm@pqm.ubuntu.com-20090427064750-e9obd6h83omt86ps
(robertc) Reduce roundtrips needed to push a new branch by coalescing
        many steps of the initialisation process. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 
20
20
from bzrlib import branch, errors, repository
21
 
from bzrlib.bzrdir import BzrDir, BzrDirFormat, BzrDirMetaFormat1
 
21
from bzrlib.bzrdir import (
 
22
    BzrDir,
 
23
    BzrDirFormat,
 
24
    BzrDirMetaFormat1,
 
25
    network_format_registry,
 
26
    )
22
27
from bzrlib.smart.request import (
23
28
    FailedSmartServerResponse,
24
29
    SmartServerRequest,
325
330
        return SuccessfulSmartServerResponse(('ok', ))
326
331
 
327
332
 
 
333
class SmartServerRequestBzrDirInitializeEx(SmartServerRequestBzrDir):
 
334
 
 
335
    def parse_NoneTrueFalse(self, arg):
 
336
        if not arg:
 
337
            return None
 
338
        if arg == 'False':
 
339
            return False
 
340
        if arg == 'True':
 
341
            return True
 
342
        raise AssertionError("invalid arg %r" % arg)
 
343
 
 
344
    def parse_NoneString(self, arg):
 
345
        return arg or None
 
346
 
 
347
    def _serialize_NoneTrueFalse(self, arg):
 
348
        if arg is False:
 
349
            return 'False'
 
350
        if not arg:
 
351
            return ''
 
352
        return 'True'
 
353
 
 
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
 
358
 
 
359
        :return: SmartServerResponse()
 
360
        """
 
361
        target_transport = self.transport_from_client_path(path)
 
362
        format = network_format_registry.get(bzrdir_network_name)
 
363
        use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
 
364
        create_prefix = self.parse_NoneTrueFalse(create_prefix)
 
365
        force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
 
366
        stacked_on = self.parse_NoneString(stacked_on)
 
367
        stack_on_pwd = self.parse_NoneString(stack_on_pwd)
 
368
        make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
 
369
        shared_repo = self.parse_NoneTrueFalse(shared_repo)
 
370
        if stack_on_pwd == '.':
 
371
            stack_on_pwd = target_transport.base
 
372
        repo_format_name = self.parse_NoneString(repo_format_name)
 
373
        repo, bzrdir, stacking, repository_policy = \
 
374
            format.initialize_on_transport_ex(target_transport,
 
375
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
376
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
377
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
378
            make_working_trees=make_working_trees, shared_repo=shared_repo)
 
379
        if repo is None:
 
380
            repo_path = ''
 
381
            repo_name = ''
 
382
            rich_root = tree_ref = external_lookup = ''
 
383
            repo_bzrdir_name = ''
 
384
            final_stack = None
 
385
            final_stack_pwd = None
 
386
        else:
 
387
            repo_path = self._repo_relpath(bzrdir.root_transport, repo)
 
388
            if repo_path == '':
 
389
                repo_path = '.'
 
390
            rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
391
                repo._format)
 
392
            repo_name = repo._format.network_name()
 
393
            repo_bzrdir_name = repo.bzrdir._format.network_name()
 
394
            final_stack = repository_policy._stack_on
 
395
            final_stack_pwd = repository_policy._stack_on_pwd
 
396
        final_stack = final_stack or ''
 
397
        final_stack_pwd = final_stack_pwd or ''
 
398
        return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
 
399
            external_lookup, repo_name, repo_bzrdir_name,
 
400
            bzrdir._format.network_name(),
 
401
            self._serialize_NoneTrueFalse(stacking), final_stack,
 
402
            final_stack_pwd))
 
403
 
 
404
 
328
405
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
329
406
 
330
407
    def do_bzrdir_request(self):