281
282
def __init__(self):
282
283
repository.RepositoryFormat.__init__(self)
283
284
self._custom_format = None
285
self._network_name = None
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)
294
# Use the format that the repository we were created to back
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
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)
303
network_name = self._custom_format.network_name()
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'
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
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)
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
304
345
def open(self, a_bzrdir):
305
346
if not isinstance(a_bzrdir, RemoteBzrDir):