/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/remote.py

  • Committer: Robert Collins
  • Date: 2009-02-19 07:28:37 UTC
  • mto: This revision was merged to the branch mainline in revision 4023.
  • Revision ID: robertc@robertcollins.net-20090219072837-vznmfrq7lz1grtti
Reduce the number of round trips required to create a repository over the network.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import (
23
23
    branch,
 
24
    bzrdir,
24
25
    debug,
25
26
    errors,
26
27
    graph,
281
282
    def __init__(self):
282
283
        repository.RepositoryFormat.__init__(self)
283
284
        self._custom_format = None
 
285
        self._network_name = None
284
286
 
285
287
    def initialize(self, a_bzrdir, shared=False):
 
288
        # Being asked to create on a non RemoteBzrDir:
 
289
        if not isinstance(a_bzrdir, RemoteBzrDir):
 
290
            if self._custom_format:
 
291
                # Custom format requested
 
292
                return self._custom_format.initialize(a_bzrdir, shared=shared)
 
293
            else:
 
294
                # Use the format that the repository we were created to back
 
295
                # has.
 
296
                prior_repo = self._creating_bzrdir.open_repository()
 
297
                prior_repo._ensure_real()
 
298
                return prior_repo._real_repository._format.initialize(
 
299
                    a_bzrdir, shared=shared)
 
300
        # Creating on a remote bzr dir.
 
301
        # 1) get the network name to use.
286
302
        if self._custom_format:
287
 
            # This returns a custom instance - e.g. a pack repo, not a remote
288
 
            # repo.
289
 
            return self._custom_format.initialize(a_bzrdir, shared=shared)
290
 
        if not isinstance(a_bzrdir, RemoteBzrDir):
291
 
            prior_repo = self._creating_bzrdir.open_repository()
292
 
            prior_repo._ensure_real()
293
 
            return prior_repo._real_repository._format.initialize(
294
 
                a_bzrdir, shared=shared)
295
 
        # delegate to a real object at this point (remoteBzrDir delegate to the
296
 
        # repository format which would lead to infinite recursion).
297
 
        a_bzrdir._ensure_real()
298
 
        result = a_bzrdir._real_bzrdir.create_repository(shared=shared)
299
 
        if not isinstance(result, RemoteRepository):
300
 
            return self.open(a_bzrdir)
301
 
        else:
302
 
            return result
 
303
            network_name = self._custom_format.network_name()
 
304
        else:
 
305
            # Select the current bzrlib default and ask for that.
 
306
            reference_bzrdir_format = bzrdir.format_registry.get('default')()
 
307
            reference_format = reference_bzrdir_format.repository_format
 
308
            network_name = reference_format.network_name()
 
309
        # 2) try direct creation via RPC
 
310
        path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
 
311
        verb = 'BzrDir.create_repository'
 
312
        if shared:
 
313
            shared_str = 'True'
 
314
        else:
 
315
            shared_str = 'False'
 
316
        try:
 
317
            response = a_bzrdir._call(verb, path, network_name, shared_str)
 
318
        except errors.UnknownSmartMethod:
 
319
            # Fallback - vfs methods
 
320
            if self._custom_format:
 
321
                # This returns a custom instance - e.g. a pack repo, not a remote
 
322
                # repo.
 
323
                return self._custom_format.initialize(a_bzrdir, shared=shared)
 
324
            # delegate to a real object at this point (remoteBzrDir delegate to the
 
325
            # repository format which would lead to infinite recursion).
 
326
            a_bzrdir._ensure_real()
 
327
            result = a_bzrdir._real_bzrdir.create_repository(shared=shared)
 
328
            if not isinstance(result, RemoteRepository):
 
329
                return self.open(a_bzrdir)
 
330
            else:
 
331
                return result
 
332
        else:
 
333
            # Turn the response into a RemoteRepository object.
 
334
            format = RemoteRepositoryFormat()
 
335
            format.rich_root_data = (response[1] == 'yes')
 
336
            format.supports_tree_reference = (response[2] == 'yes')
 
337
            format.supports_external_lookups = (response[3] == 'yes')
 
338
            format._network_name = response[4]
 
339
            # Used to support creating a real format instance when needed.
 
340
            format._creating_bzrdir = a_bzrdir
 
341
            remote_repo = RemoteRepository(a_bzrdir, format)
 
342
            format._creating_repo = remote_repo
 
343
            return remote_repo
303
344
    
304
345
    def open(self, a_bzrdir):
305
346
        if not isinstance(a_bzrdir, RemoteBzrDir):
322
363
                'Does not support nested trees', target_format)
323
364
 
324
365
    def network_name(self):
 
366
        if self._network_name:
 
367
            return self._network_name
325
368
        self._creating_repo._ensure_real()
326
369
        return self._creating_repo._real_repository._format.network_name()
327
370