/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Martin Pool
  • Date: 2010-10-08 04:38:25 UTC
  • mfrom: (5462 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5478.
  • Revision ID: mbp@sourcefrog.net-20101008043825-b181r8bo5r3qwb6j
merge trunk

Show diffs side-by-side

added added

removed removed

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