~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-19 10:58:39 UTC
  • mfrom: (6383 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6386.
  • Revision ID: jelmer@canonical.com-20111219105839-uji05ck4rkm1mj4j
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

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