/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Server-side bzrdir related request implmentations."""
18
18
 
19
 
from __future__ import absolute_import
20
19
 
21
20
from bzrlib import branch, errors, repository, urlutils
22
21
from bzrlib.bzrdir import (
23
22
    BzrDir,
24
23
    BzrDirFormat,
25
 
    BzrProber,
26
 
    )
27
 
from bzrlib.controldir import (
 
24
    BzrDirMetaFormat1,
28
25
    network_format_registry,
29
26
    )
30
27
from bzrlib.smart.request import (
47
44
            # clients that don't anticipate errors from this method.
48
45
            answer = 'no'
49
46
        else:
50
 
            bzr_prober = BzrProber()
 
47
            default_format = BzrDirFormat.get_default_format()
 
48
            real_bzrdir = default_format.open(t, _found=True)
51
49
            try:
52
 
                bzr_prober.probe_transport(t)
 
50
                real_bzrdir._format.probe_transport(t)
53
51
            except (errors.NotBranchError, errors.UnknownFormatError):
54
52
                answer = 'no'
55
53
            else:
86
84
class SmartServerRequestBzrDir(SmartServerRequest):
87
85
 
88
86
    def do(self, path, *args):
89
 
        """Open a BzrDir at path, and return `self.do_bzrdir_request(*args)`."""
 
87
        """Open a BzrDir at path, and return self.do_bzrdir_request(*args)."""
90
88
        try:
91
89
            self._bzrdir = BzrDir.open_from_transport(
92
90
                self.transport_from_client_path(path))
121
119
        return '/'.join(segments)
122
120
 
123
121
 
124
 
class SmartServerBzrDirRequestDestroyBranch(SmartServerRequestBzrDir):
125
 
 
126
 
    def do_bzrdir_request(self, name=None):
127
 
        """Destroy the branch with the specified name.
128
 
 
129
 
        New in 2.5.0.
130
 
        :return: On success, 'ok'.
131
 
        """
132
 
        try:
133
 
            self._bzrdir.destroy_branch(name)
134
 
        except errors.NotBranchError, e:
135
 
            return FailedSmartServerResponse(('nobranch',))
136
 
        return SuccessfulSmartServerResponse(('ok',))
137
 
 
138
 
 
139
 
class SmartServerBzrDirRequestHasWorkingTree(SmartServerRequestBzrDir):
140
 
 
141
 
    def do_bzrdir_request(self, name=None):
142
 
        """Check whether there is a working tree present.
143
 
 
144
 
        New in 2.5.0.
145
 
 
146
 
        :return: If there is a working tree present, 'yes'.
147
 
            Otherwise 'no'.
148
 
        """
149
 
        if self._bzrdir.has_workingtree():
150
 
            return SuccessfulSmartServerResponse(('yes', ))
151
 
        else:
152
 
            return SuccessfulSmartServerResponse(('no', ))
153
 
 
154
 
 
155
 
class SmartServerBzrDirRequestDestroyRepository(SmartServerRequestBzrDir):
156
 
 
157
 
    def do_bzrdir_request(self, name=None):
158
 
        """Destroy the repository.
159
 
 
160
 
        New in 2.5.0.
161
 
 
162
 
        :return: On success, 'ok'.
163
 
        """
164
 
        try:
165
 
            self._bzrdir.destroy_repository()
166
 
        except errors.NoRepositoryPresent, e:
167
 
            return FailedSmartServerResponse(('norepository',))
168
 
        return SuccessfulSmartServerResponse(('ok',))
169
 
 
170
 
 
171
122
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
172
123
 
173
124
    def do_bzrdir_request(self, require_stacking):
197
148
        control_format = self._bzrdir.cloning_metadir(
198
149
            require_stacking=require_stacking)
199
150
        control_name = control_format.network_name()
200
 
        if not control_format.fixed_components:
 
151
        # XXX: There should be a method that tells us that the format does/does
 
152
        # not have subformats.
 
153
        if isinstance(control_format, BzrDirMetaFormat1):
201
154
            branch_name = ('branch',
202
155
                control_format.get_branch_format().network_name())
203
156
            repository_name = control_format.repository_format.network_name()
209
162
            branch_name))
210
163
 
211
164
 
212
 
class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
213
 
    """Get the format to use for checkouts.
214
 
 
215
 
    New in 2.5.
216
 
 
217
 
    :return: on success, a 3-tuple of network names for (control,
218
 
        repository, branch) directories, where '' signifies "not present".
219
 
        If this BzrDir contains a branch reference then this will fail with
220
 
        BranchReference; clients should resolve branch references before
221
 
        calling this RPC (they should not try to create a checkout of a
222
 
        checkout).
223
 
    """
224
 
 
225
 
    def do_bzrdir_request(self):
226
 
        try:
227
 
            branch_ref = self._bzrdir.get_branch_reference()
228
 
        except errors.NotBranchError:
229
 
            branch_ref = None
230
 
        if branch_ref is not None:
231
 
            # The server shouldn't try to resolve references, and it quite
232
 
            # possibly can't reach them anyway.  The client needs to resolve
233
 
            # the branch reference to determine the cloning_metadir.
234
 
            return FailedSmartServerResponse(('BranchReference',))
235
 
        control_format = self._bzrdir.checkout_metadir()
236
 
        control_name = control_format.network_name()
237
 
        if not control_format.fixed_components:
238
 
            branch_name = control_format.get_branch_format().network_name()
239
 
            repo_name = control_format.repository_format.network_name()
240
 
        else:
241
 
            branch_name = ''
242
 
            repo_name = ''
243
 
        return SuccessfulSmartServerResponse(
244
 
            (control_name, repo_name, branch_name))
245
 
 
246
 
 
247
165
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
248
166
 
249
167
    def do(self, path, network_name):
261
179
 
262
180
        :param path: The path to the bzrdir.
263
181
        :param network_name: The network name of the branch type to create.
264
 
        :return: ('ok', branch_format, repo_path, rich_root, tree_ref,
265
 
            external_lookup, repo_format)
 
182
        :return: (ok, network_name)
266
183
        """
267
184
        bzrdir = BzrDir.open_from_transport(
268
185
            self.transport_from_client_path(path))
512
429
            # It is returned locked, but we need to do the lock to get the lock
513
430
            # token.
514
431
            repo.unlock()
515
 
            repo_lock_token = repo.lock_write().repository_token or ''
 
432
            repo_lock_token = repo.lock_write() or ''
516
433
            if repo_lock_token:
517
434
                repo.leave_lock_in_place()
518
435
            repo.unlock()