~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Brian de Alwis
  • Date: 2009-09-24 19:51:37 UTC
  • mto: (4715.4.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4727.
  • Revision ID: bsd@acm.org-20090924195137-wubyeqv515mkigi8
Introduce new mailer to support MacOS X's Mail.app

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
22
22
    BzrDir,
23
23
    BzrDirFormat,
24
24
    BzrDirMetaFormat1,
25
 
    BzrProber,
26
25
    network_format_registry,
27
26
    )
28
27
from bzrlib.smart.request import (
45
44
            # clients that don't anticipate errors from this method.
46
45
            answer = 'no'
47
46
        else:
48
 
            bzr_prober = BzrProber()
 
47
            default_format = BzrDirFormat.get_default_format()
 
48
            real_bzrdir = default_format.open(t, _found=True)
49
49
            try:
50
 
                bzr_prober.probe_transport(t)
 
50
                real_bzrdir._format.probe_transport(t)
51
51
            except (errors.NotBranchError, errors.UnknownFormatError):
52
52
                answer = 'no'
53
53
            else:
88
88
        try:
89
89
            self._bzrdir = BzrDir.open_from_transport(
90
90
                self.transport_from_client_path(path))
91
 
        except errors.NotBranchError, e:
92
 
            return FailedSmartServerResponse(('nobranch',))
 
91
        except errors.NotBranchError:
 
92
            return FailedSmartServerResponse(('nobranch', ))
93
93
        return self.do_bzrdir_request(*args)
94
94
 
95
95
    def _boolean_to_yes_no(self, a_boolean):
110
110
        """Get the relative path for repository from current_transport."""
111
111
        # the relpath of the bzrdir in the found repository gives us the
112
112
        # path segments to pop-out.
113
 
        relpath = repository.user_transport.relpath(
 
113
        relpath = repository.bzrdir.root_transport.relpath(
114
114
            current_transport.base)
115
115
        if len(relpath):
116
116
            segments = ['..'] * len(relpath.split('/'))
429
429
            # It is returned locked, but we need to do the lock to get the lock
430
430
            # token.
431
431
            repo.unlock()
432
 
            repo_lock_token = repo.lock_write().repository_token or ''
 
432
            repo_lock_token = repo.lock_write() or ''
433
433
            if repo_lock_token:
434
434
                repo.leave_lock_in_place()
435
435
            repo.unlock()
465
465
                return SuccessfulSmartServerResponse(('ok', ''))
466
466
            else:
467
467
                return SuccessfulSmartServerResponse(('ok', reference_url))
468
 
        except errors.NotBranchError, e:
469
 
            return FailedSmartServerResponse(('nobranch',))
 
468
        except errors.NotBranchError:
 
469
            return FailedSmartServerResponse(('nobranch', ))
470
470
 
471
471
 
472
472
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
481
481
                return SuccessfulSmartServerResponse(('branch', format))
482
482
            else:
483
483
                return SuccessfulSmartServerResponse(('ref', reference_url))
484
 
        except errors.NotBranchError, e:
485
 
            return FailedSmartServerResponse(('nobranch',))
486
 
 
487
 
 
488
 
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
489
 
 
490
 
    def do_bzrdir_request(self):
491
 
        """Open a branch at path and return the reference or format.
492
 
        
493
 
        This version introduced in 2.1.
494
 
 
495
 
        Differences to SmartServerRequestOpenBranchV2:
496
 
          * can return 2-element ('nobranch', extra), where 'extra' is a string
497
 
            with an explanation like 'location is a repository'.  Previously
498
 
            a 'nobranch' response would never have more than one element.
499
 
        """
500
 
        try:
501
 
            reference_url = self._bzrdir.get_branch_reference()
502
 
            if reference_url is None:
503
 
                br = self._bzrdir.open_branch(ignore_fallbacks=True)
504
 
                format = br._format.network_name()
505
 
                return SuccessfulSmartServerResponse(('branch', format))
506
 
            else:
507
 
                return SuccessfulSmartServerResponse(('ref', reference_url))
508
 
        except errors.NotBranchError, e:
509
 
            # Stringify the exception so that its .detail attribute will be
510
 
            # filled out.
511
 
            str(e)
512
 
            resp = ('nobranch',)
513
 
            detail = e.detail
514
 
            if detail:
515
 
                if detail.startswith(': '):
516
 
                    detail = detail[2:]
517
 
                resp += (detail,)
518
 
            return FailedSmartServerResponse(resp)
519
 
 
 
484
        except errors.NotBranchError:
 
485
            return FailedSmartServerResponse(('nobranch', ))