192
192
transport.ensure_base()
193
193
require_stacking = (stacked_on is not None)
194
194
format = self.cloning_metadir(require_stacking)
195
# Bug: We create a metadir without knowing if it can support stacking,
196
# we should look up the policy needs first.
195
197
result = format.initialize_on_transport(transport)
196
198
repository_policy = None
387
389
stack_on_pwd=None, require_stacking=False):
388
390
"""Return an object representing a policy to use.
390
This controls whether a new repository is created, or a shared
391
repository used instead.
392
This controls whether a new repository is created, and the format of
393
that repository, or some existing shared repository used instead.
393
395
If stack_on is supplied, will not seek a containing shared repo.
2833
2835
# Always return a RemoteRepositoryFormat object, but if a specific bzr
2834
2836
# repository format has been asked for, tell the RemoteRepositoryFormat
2835
2837
# that it should use that for init() etc.
2836
result = remote.RemoteRepositoryFormat()
2838
result = remote.RemoteRepositoryFormat()
2837
2839
custom_format = getattr(self, '_repository_format', None)
2838
2840
if custom_format:
2839
# We will use the custom format to create repositories over the
2840
# wire; expose its details like rich_root_data for code to query
2841
2841
if isinstance(custom_format, remote.RemoteRepositoryFormat):
2842
result._custom_format = custom_format._custom_format
2842
return custom_format
2844
# We will use the custom format to create repositories over the
2845
# wire; expose its details like rich_root_data for code to
2844
2847
result._custom_format = custom_format
3149
3152
Creates the desired repository in the bzrdir we already have.
3154
stack_on = self._get_full_stack_on()
3156
# Stacking is desired. requested by the target, but does the place it
3157
# points at support stacking? If it doesn't then we should
3158
# not implicitly upgrade. We check this here.
3159
format = self._bzrdir._format
3160
if not (format.repository_format.supports_external_lookups
3161
and format.get_branch_format().supports_stacking()):
3162
# May need to upgrade - but only do if the target also
3163
# supports stacking. Note that this currently wastes
3164
# network round trips to check - but we only do this
3165
# when the source can't stack so it will fade away
3166
# as people do upgrade.
3168
target_dir = BzrDir.open(stack_on,
3169
possible_transports=[self._bzrdir.root_transport])
3170
except errors.NotBranchError:
3171
# Nothing there, don't change formats
3175
target_branch = target_dir.open_branch()
3176
except errors.NotBranchError:
3177
# No branch, don't change formats
3180
branch_format = target_branch._format
3181
repo_format = target_branch.repository._format
3182
if not (branch_format.supports_stacking()
3183
and repo_format.supports_external_lookups):
3184
# Doesn't stack itself, don't force an upgrade
3187
# Does support stacking, use its format.
3188
format.repository_format = repo_format
3189
format.set_branch_format(branch_format)
3190
note('Source format does not support stacking, '
3191
'using format: \'%s\'\n %s\n',
3192
branch_format.get_format_description(),
3193
repo_format.get_format_description())
3194
if not self._require_stacking:
3195
# We have picked up automatic stacking somewhere.
3196
note('Using default stacking branch %s at %s', self._stack_on,
3151
3198
repository = self._bzrdir.create_repository(shared=shared)
3152
3199
self._add_fallback(repository,
3153
3200
possible_transports=[self._bzrdir.transport])