191
194
even if one is available.
192
195
:param preserve_stacking: When cloning a stacked branch, stack the
193
196
new branch on top of the other branch's stacked-on branch.
197
:param create_prefix: Create any missing directories leading up to
199
:param use_existing_dir: Use an existing directory if one exists.
195
transport.ensure_base()
201
# Overview: put together a broad description of what we want to end up
202
# with; then make as few api calls as possible to do it.
204
# We may want to create a repo/branch/tree, if we do so what format
205
# would we want for each:
196
206
require_stacking = (stacked_on is not None)
197
207
format = self.cloning_metadir(require_stacking)
198
# Bug: We create a metadir without knowing if it can support stacking,
199
# we should look up the policy needs first.
200
result = format.initialize_on_transport(transport)
201
repository_policy = None
209
# Figure out what objects we want:
203
211
local_repo = self.find_repository()
204
212
except errors.NoRepositoryPresent:
218
226
errors.UnstackableRepositoryFormat,
219
227
errors.NotStacked):
229
# Bug: We create a metadir without knowing if it can support stacking,
230
# we should look up the policy needs first, or just use it as a hint,
223
# may need to copy content in
224
repository_policy = result.determine_repository_policy(
225
force_new_repo, stacked_on, self.root_transport.base,
226
require_stacking=require_stacking)
227
233
make_working_trees = local_repo.make_working_trees()
228
result_repo, is_new_repo = repository_policy.acquire_repository(
229
make_working_trees, local_repo.is_shared())
230
if not require_stacking and repository_policy._require_stacking:
231
require_stacking = True
232
result._format.require_stacking()
233
if is_new_repo and not require_stacking and revision_id is not None:
234
want_shared = local_repo.is_shared()
235
repo_format_name = format.repository_format.network_name()
237
make_working_trees = False
239
repo_format_name = None
241
result_repo, result, require_stacking, repository_policy = \
242
format.initialize_on_transport_ex(transport,
243
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
244
force_new_repo=force_new_repo, stacked_on=stacked_on,
245
stack_on_pwd=self.root_transport.base,
246
repo_format_name=repo_format_name,
247
make_working_trees=make_working_trees, shared_repo=want_shared)
249
# If the result repository is in the same place as the resulting
250
# bzr dir, it will have no content, further if the result is not stacked
251
# then we know all content should be copied, and finally if we are
252
# copying up to a specific revision_id then we can use the
253
# pending-ancestry-result which does not require traversing all of
254
# history to describe it.
255
if (result_repo.bzrdir.root_transport.base ==
256
result.root_transport.base and not require_stacking and
257
revision_id is not None):
234
258
fetch_spec = graph.PendingAncestryResult(
235
259
[revision_id], local_repo)
236
260
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
1822
1855
self._supply_sub_formats_to(remote_format)
1823
1856
return remote_format.initialize_on_transport(transport)
1858
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1859
create_prefix=False, force_new_repo=False, stacked_on=None,
1860
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1861
shared_repo=False, vfs_only=False):
1862
"""Create this format on transport.
1864
The directory to initialize will be created.
1866
:param force_new_repo: Do not use a shared repository for the target,
1867
even if one is available.
1868
:param create_prefix: Create any missing directories leading up to
1870
:param use_existing_dir: Use an existing directory if one exists.
1871
:param stacked_on: A url to stack any created branch on, None to follow
1872
any target stacking policy.
1873
:param stack_on_pwd: If stack_on is relative, the location it is
1875
:param repo_format_name: If non-None, a repository will be
1876
made-or-found. Should none be found, or if force_new_repo is True
1877
the repo_format_name is used to select the format of repository to
1879
:param make_working_trees: Control the setting of make_working_trees
1880
for a new shared repository when one is made. None to use whatever
1881
default the format has.
1882
:param shared_repo: Control whether made repositories are shared or
1884
:param vfs_only: If True do not attempt to use a smart server
1885
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1886
None if none was created or found, bzrdir is always valid.
1887
require_stacking is the result of examining the stacked_on
1888
parameter and any stacking policy found for the target.
1891
# Try to hand off to a smart server
1893
client_medium = transport.get_smart_medium()
1894
except errors.NoSmartMedium:
1897
# TODO: lookup the local format from a server hint.
1898
remote_dir_format = RemoteBzrDirFormat()
1899
remote_dir_format._network_name = self.network_name()
1900
self._supply_sub_formats_to(remote_dir_format)
1901
return remote_dir_format.initialize_on_transport_ex(transport,
1902
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1903
force_new_repo=force_new_repo, stacked_on=stacked_on,
1904
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1905
make_working_trees=make_working_trees, shared_repo=shared_repo)
1906
# XXX: Refactor the create_prefix/no_create_prefix code into a
1907
# common helper function
1908
# The destination may not exist - if so make it according to policy.
1909
def make_directory(transport):
1910
transport.mkdir('.')
1912
def redirected(transport, e, redirection_notice):
1913
note(redirection_notice)
1914
return transport._redirected_to(e.source, e.target)
1916
transport = do_catching_redirections(make_directory, transport,
1918
except errors.FileExists:
1919
if not use_existing_dir:
1921
except errors.NoSuchFile:
1922
if not create_prefix:
1924
transport.create_prefix()
1926
require_stacking = (stacked_on is not None)
1927
# Now the target directory exists, but doesn't have a .bzr
1928
# directory. So we need to create it, along with any work to create
1929
# all of the dependent branches, etc.
1931
result = self.initialize_on_transport(transport)
1932
if repo_format_name:
1934
# use a custom format
1935
result._format.repository_format = \
1936
repository.network_format_registry.get(repo_format_name)
1937
except AttributeError:
1938
# The format didn't permit it to be set.
1940
# A repository is desired, either in-place or shared.
1941
repository_policy = result.determine_repository_policy(
1942
force_new_repo, stacked_on, stack_on_pwd,
1943
require_stacking=require_stacking)
1944
result_repo, is_new_repo = repository_policy.acquire_repository(
1945
make_working_trees, shared_repo)
1946
if not require_stacking and repository_policy._require_stacking:
1947
require_stacking = True
1948
result._format.require_stacking()
1951
repository_policy = None
1952
return result_repo, result, require_stacking, repository_policy
1825
1954
def _initialize_on_transport_vfs(self, transport):
1826
1955
"""Initialize a new bzrdir using VFS calls.
2039
2168
repository_format = property(__return_repository_format)
2042
class BzrDirFormat5(BzrDirFormat):
2171
class BzrDirFormatAllInOne(BzrDirFormat):
2172
"""Common class for formats before meta-dirs."""
2174
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2175
create_prefix=False, force_new_repo=False, stacked_on=None,
2176
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2178
"""See BzrDirFormat.initialize_on_transport_ex."""
2179
require_stacking = (stacked_on is not None)
2180
# Format 5 cannot stack, but we've been asked to - actually init
2182
if require_stacking:
2183
format = BzrDirMetaFormat1()
2184
return format.initialize_on_transport_ex(transport,
2185
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2186
force_new_repo=force_new_repo, stacked_on=stacked_on,
2187
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2188
make_working_trees=make_working_trees, shared_repo=shared_repo)
2189
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2190
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2191
force_new_repo=force_new_repo, stacked_on=stacked_on,
2192
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2193
make_working_trees=make_working_trees, shared_repo=shared_repo)
2196
class BzrDirFormat5(BzrDirFormatAllInOne):
2043
2197
"""Bzr control format 5.
2045
2199
This format is a combined format for working tree, branch and repository.
2892
3051
self._supply_sub_formats_to(format)
2893
3052
return remote.RemoteBzrDir(transport, format)
3054
def parse_NoneTrueFalse(self, arg):
3061
raise AssertionError("invalid arg %r" % arg)
3063
def _serialize_NoneTrueFalse(self, arg):
3070
def _serialize_NoneString(self, arg):
3073
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3074
create_prefix=False, force_new_repo=False, stacked_on=None,
3075
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3078
# hand off the request to the smart server
3079
client_medium = transport.get_smart_medium()
3080
except errors.NoSmartMedium:
3083
# Decline to open it if the server doesn't support our required
3084
# version (3) so that the VFS-based transport will do it.
3085
if client_medium.should_probe():
3087
server_version = client_medium.protocol_version()
3088
if server_version != '2':
3092
except errors.SmartProtocolError:
3093
# Apparently there's no usable smart server there, even though
3094
# the medium supports the smart protocol.
3099
client = _SmartClient(client_medium)
3100
path = client.remote_path_from_transport(transport)
3101
if client_medium._is_remote_before((1, 15)):
3104
# TODO: lookup the local format from a server hint.
3105
local_dir_format = BzrDirMetaFormat1()
3106
self._supply_sub_formats_to(local_dir_format)
3107
return local_dir_format.initialize_on_transport_ex(transport,
3108
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3109
force_new_repo=force_new_repo, stacked_on=stacked_on,
3110
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3111
make_working_trees=make_working_trees, shared_repo=shared_repo,
3114
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3115
args.append(self._serialize_NoneTrueFalse(create_prefix))
3116
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3117
args.append(self._serialize_NoneString(stacked_on))
3118
# stack_on_pwd is often/usually our transport
3121
stack_on_pwd = transport.relpath(stack_on_pwd)
3122
if not stack_on_pwd:
3124
except errors.PathNotChild:
3126
args.append(self._serialize_NoneString(stack_on_pwd))
3127
args.append(self._serialize_NoneString(repo_format_name))
3128
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3129
args.append(self._serialize_NoneTrueFalse(shared_repo))
3130
if self._network_name is None:
3131
self._network_name = \
3132
BzrDirFormat.get_default_format().network_name()
3134
response = client.call('BzrDirFormat.initialize_ex',
3135
self.network_name(), path, *args)
3136
except errors.UnknownSmartMethod:
3137
local_dir_format = BzrDirMetaFormat1()
3138
self._supply_sub_formats_to(local_dir_format)
3139
return local_dir_format.initialize_on_transport_ex(transport,
3140
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3141
force_new_repo=force_new_repo, stacked_on=stacked_on,
3142
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3143
make_working_trees=make_working_trees, shared_repo=shared_repo,
3145
repo_path = response[0]
3146
bzrdir_name = response[6]
3147
require_stacking = response[7]
3148
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3149
format = RemoteBzrDirFormat()
3150
format._network_name = bzrdir_name
3151
self._supply_sub_formats_to(format)
3152
bzrdir = remote.RemoteBzrDir(transport, format)
3154
repo_format = remote.response_tuple_to_repo_format(response[1:])
3155
if repo_path == '.':
3158
repo_bzrdir_format = RemoteBzrDirFormat()
3159
repo_bzrdir_format._network_name = response[5]
3160
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3164
final_stack = response[8] or None
3165
final_stack_pwd = response[9] or None
3166
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3167
policy = UseExistingRepository(remote_repo, final_stack,
3168
final_stack_pwd, require_stacking)
3169
policy.acquire_repository()
3173
return remote_repo, bzrdir, require_stacking, policy
2895
3175
def _open(self, transport):
2896
3176
return remote.RemoteBzrDir(transport, self)
3251
3545
if not (branch_format.supports_stacking()
3252
3546
and repo_format.supports_external_lookups):
3253
3547
# Doesn't stack itself, don't force an upgrade
3256
# Does support stacking, use its format.
3257
format.repository_format = repo_format
3258
format.set_branch_format(branch_format)
3259
note('Source format does not support stacking, '
3260
'using format: \'%s\'\n %s\n',
3261
branch_format.get_format_description(),
3262
repo_format.get_format_description())
3548
branch_format = None
3550
if branch_format and repo_format:
3551
# Does support stacking, use its format.
3552
format.repository_format = repo_format
3553
format.set_branch_format(branch_format)
3554
note('Source format does not support stacking, '
3555
'using format: \'%s\'\n %s\n',
3556
branch_format.get_format_description(),
3557
repo_format.get_format_description())
3263
3558
if not self._require_stacking:
3264
3559
# We have picked up automatic stacking somewhere.
3265
3560
note('Using default stacking branch %s at %s', self._stack_on,