/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: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Server-side bzrdir related request implmentations."""
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,
92
97
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
93
98
 
94
99
    def do_bzrdir_request(self, require_stacking):
95
 
        """Get the format that should be used when cloning from this dir."""
 
100
        """Get the format that should be used when cloning from this dir.
 
101
 
 
102
        New in 1.13.
 
103
        
 
104
        :return: on success, a 3-tuple of network names for (control,
 
105
            repository, branch) directories, where '' signifies "not present".
 
106
            If this BzrDir contains a branch reference then this will fail with
 
107
            BranchReference; clients should resolve branch references before
 
108
            calling this RPC.
 
109
        """
96
110
        try:
97
111
            branch_ref = self._bzrdir.get_branch_reference()
98
112
        except errors.NotBranchError:
99
113
            branch_ref = None
 
114
        if branch_ref is not None:
 
115
            # The server shouldn't try to resolve references, and it quite
 
116
            # possibly can't reach them anyway.  The client needs to resolve
 
117
            # the branch reference to determine the cloning_metadir.
 
118
            return FailedSmartServerResponse(('BranchReference',))
100
119
        if require_stacking == "True":
101
120
            require_stacking = True
102
121
        else:
104
123
        control_format = self._bzrdir.cloning_metadir(
105
124
            require_stacking=require_stacking)
106
125
        control_name = control_format.network_name()
107
 
        # XXX: There should be a method that tells us that the format does/does not
108
 
        # have subformats.
 
126
        # XXX: There should be a method that tells us that the format does/does
 
127
        # not have subformats.
109
128
        if isinstance(control_format, BzrDirMetaFormat1):
110
 
            if branch_ref is not None:
111
 
                # If there's a branch reference, the client will have to resolve
112
 
                # the branch reference to figure out the cloning metadir
113
 
                branch_name = ('ref', branch_ref)
114
 
            else:
115
 
                branch_name = ('branch',
116
 
                    control_format.get_branch_format().network_name())
 
129
            branch_name = ('branch',
 
130
                control_format.get_branch_format().network_name())
117
131
            repository_name = control_format.repository_format.network_name()
118
132
        else:
119
133
            # Only MetaDir has delegated formats today.
166
180
 
167
181
        This operates precisely like 'bzrdir.create_repository'.
168
182
 
169
 
        If a bzrdir is not present, an exception is propogated
 
183
        If a bzrdir is not present, an exception is propagated
170
184
        rather than 'no branch' because these are different conditions (and
171
185
        this method should only be called after establishing that a bzr dir
172
186
        exists anyway).
223
237
 
224
238
        This operates precisely like 'bzrdir.find_repository'.
225
239
 
226
 
        If a bzrdir is not present, an exception is propogated
 
240
        If a bzrdir is not present, an exception is propagated
227
241
        rather than 'no branch' because these are different conditions.
228
242
 
229
243
        This is the initial version of this method introduced with the smart
246
260
 
247
261
        This operates precisely like 'bzrdir.find_repository'.
248
262
 
249
 
        If a bzrdir is not present, an exception is propogated
 
263
        If a bzrdir is not present, an exception is propagated
250
264
        rather than 'no branch' because these are different conditions.
251
265
 
252
266
        This is the second edition of this method introduced in bzr 1.3, which
288
302
            return FailedSmartServerResponse(('norepository', ))
289
303
 
290
304
 
 
305
class SmartServerBzrDirRequestConfigFile(SmartServerRequestBzrDir):
 
306
 
 
307
    def do_bzrdir_request(self):
 
308
        """Get the configuration bytes for a config file in bzrdir.
 
309
        
 
310
        The body is not utf8 decoded - it is the literal bytestream from disk.
 
311
        """
 
312
        config = self._bzrdir._get_config()
 
313
        if config is None:
 
314
            content = ''
 
315
        else:
 
316
            content = config._get_config_file().read()
 
317
        return SuccessfulSmartServerResponse((), content)
 
318
 
 
319
 
291
320
class SmartServerRequestInitializeBzrDir(SmartServerRequest):
292
321
 
293
322
    def do(self, path):
301
330
        return SuccessfulSmartServerResponse(('ok', ))
302
331
 
303
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: return SuccessfulSmartServerResponse((repo_path, rich_root,
 
360
            tree_ref, external_lookup, repo_network_name,
 
361
            repo_bzrdir_network_name, bzrdir_format_network_name,
 
362
            NoneTrueFalse(stacking), final_stack, final_stack_pwd,
 
363
            repo_lock_token))
 
364
        """
 
365
        target_transport = self.transport_from_client_path(path)
 
366
        format = network_format_registry.get(bzrdir_network_name)
 
367
        use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
 
368
        create_prefix = self.parse_NoneTrueFalse(create_prefix)
 
369
        force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
 
370
        stacked_on = self.parse_NoneString(stacked_on)
 
371
        stack_on_pwd = self.parse_NoneString(stack_on_pwd)
 
372
        make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
 
373
        shared_repo = self.parse_NoneTrueFalse(shared_repo)
 
374
        if stack_on_pwd == '.':
 
375
            stack_on_pwd = target_transport.base
 
376
        repo_format_name = self.parse_NoneString(repo_format_name)
 
377
        repo, bzrdir, stacking, repository_policy = \
 
378
            format.initialize_on_transport_ex(target_transport,
 
379
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
 
380
            force_new_repo=force_new_repo, stacked_on=stacked_on,
 
381
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
 
382
            make_working_trees=make_working_trees, shared_repo=shared_repo)
 
383
        if repo is None:
 
384
            repo_path = ''
 
385
            repo_name = ''
 
386
            rich_root = tree_ref = external_lookup = ''
 
387
            repo_bzrdir_name = ''
 
388
            final_stack = None
 
389
            final_stack_pwd = None
 
390
            repo_lock_token = ''
 
391
        else:
 
392
            repo_path = self._repo_relpath(bzrdir.root_transport, repo)
 
393
            if repo_path == '':
 
394
                repo_path = '.'
 
395
            rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
396
                repo._format)
 
397
            repo_name = repo._format.network_name()
 
398
            repo_bzrdir_name = repo.bzrdir._format.network_name()
 
399
            final_stack = repository_policy._stack_on
 
400
            final_stack_pwd = repository_policy._stack_on_pwd
 
401
            # It is returned locked, but we need to do the lock to get the lock
 
402
            # token.
 
403
            repo.unlock()
 
404
            repo_lock_token = repo.lock_write() or ''
 
405
            if repo_lock_token:
 
406
                repo.leave_lock_in_place()
 
407
            repo.unlock()
 
408
        final_stack = final_stack or ''
 
409
        final_stack_pwd = final_stack_pwd or ''
 
410
        return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
 
411
            external_lookup, repo_name, repo_bzrdir_name,
 
412
            bzrdir._format.network_name(),
 
413
            self._serialize_NoneTrueFalse(stacking), final_stack,
 
414
            final_stack_pwd, repo_lock_token))
 
415
 
 
416
 
304
417
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
305
418
 
306
419
    def do_bzrdir_request(self):
322
435
        try:
323
436
            reference_url = self._bzrdir.get_branch_reference()
324
437
            if reference_url is None:
325
 
                format = self._bzrdir.open_branch()._format.network_name()
 
438
                br = self._bzrdir.open_branch(ignore_fallbacks=True)
 
439
                format = br._format.network_name()
326
440
                return SuccessfulSmartServerResponse(('branch', format))
327
441
            else:
328
442
                return SuccessfulSmartServerResponse(('ref', reference_url))