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
fetch_spec = graph.PendingAncestryResult(
235
[revision_id], local_repo)
236
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
238
result_repo.fetch(local_repo, revision_id=revision_id)
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)
250
# If the result repository is in the same place as the
251
# resulting bzr dir, it will have no content, further if the
252
# result is not stacked then we know all content should be
253
# copied, and finally if we are copying up to a specific
254
# revision_id then we can use the pending-ancestry-result which
255
# does not require traversing all of history to describe it.
256
if (result_repo.bzrdir.root_transport.base ==
257
result.root_transport.base and not require_stacking and
258
revision_id is not None):
259
fetch_spec = graph.PendingAncestryResult(
260
[revision_id], local_repo)
261
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
263
result_repo.fetch(local_repo, revision_id=revision_id)
267
if result_repo is not None:
268
raise AssertionError('result_repo not None(%r)' % result_repo)
241
269
# 1 if there is a branch present
242
270
# make sure its content is available in the target repository
1821
1859
self._supply_sub_formats_to(remote_format)
1822
1860
return remote_format.initialize_on_transport(transport)
1862
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1863
create_prefix=False, force_new_repo=False, stacked_on=None,
1864
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1865
shared_repo=False, vfs_only=False):
1866
"""Create this format on transport.
1868
The directory to initialize will be created.
1870
:param force_new_repo: Do not use a shared repository for the target,
1871
even if one is available.
1872
:param create_prefix: Create any missing directories leading up to
1874
:param use_existing_dir: Use an existing directory if one exists.
1875
:param stacked_on: A url to stack any created branch on, None to follow
1876
any target stacking policy.
1877
:param stack_on_pwd: If stack_on is relative, the location it is
1879
:param repo_format_name: If non-None, a repository will be
1880
made-or-found. Should none be found, or if force_new_repo is True
1881
the repo_format_name is used to select the format of repository to
1883
:param make_working_trees: Control the setting of make_working_trees
1884
for a new shared repository when one is made. None to use whatever
1885
default the format has.
1886
:param shared_repo: Control whether made repositories are shared or
1888
:param vfs_only: If True do not attempt to use a smart server
1889
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1890
None if none was created or found, bzrdir is always valid.
1891
require_stacking is the result of examining the stacked_on
1892
parameter and any stacking policy found for the target.
1895
# Try to hand off to a smart server
1897
client_medium = transport.get_smart_medium()
1898
except errors.NoSmartMedium:
1901
# TODO: lookup the local format from a server hint.
1902
remote_dir_format = RemoteBzrDirFormat()
1903
remote_dir_format._network_name = self.network_name()
1904
self._supply_sub_formats_to(remote_dir_format)
1905
return remote_dir_format.initialize_on_transport_ex(transport,
1906
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1907
force_new_repo=force_new_repo, stacked_on=stacked_on,
1908
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1909
make_working_trees=make_working_trees, shared_repo=shared_repo)
1910
# XXX: Refactor the create_prefix/no_create_prefix code into a
1911
# common helper function
1912
# The destination may not exist - if so make it according to policy.
1913
def make_directory(transport):
1914
transport.mkdir('.')
1916
def redirected(transport, e, redirection_notice):
1917
note(redirection_notice)
1918
return transport._redirected_to(e.source, e.target)
1920
transport = do_catching_redirections(make_directory, transport,
1922
except errors.FileExists:
1923
if not use_existing_dir:
1925
except errors.NoSuchFile:
1926
if not create_prefix:
1928
transport.create_prefix()
1930
require_stacking = (stacked_on is not None)
1931
# Now the target directory exists, but doesn't have a .bzr
1932
# directory. So we need to create it, along with any work to create
1933
# all of the dependent branches, etc.
1935
result = self.initialize_on_transport(transport)
1936
if repo_format_name:
1938
# use a custom format
1939
result._format.repository_format = \
1940
repository.network_format_registry.get(repo_format_name)
1941
except AttributeError:
1942
# The format didn't permit it to be set.
1944
# A repository is desired, either in-place or shared.
1945
repository_policy = result.determine_repository_policy(
1946
force_new_repo, stacked_on, stack_on_pwd,
1947
require_stacking=require_stacking)
1948
result_repo, is_new_repo = repository_policy.acquire_repository(
1949
make_working_trees, shared_repo)
1950
if not require_stacking and repository_policy._require_stacking:
1951
require_stacking = True
1952
result._format.require_stacking()
1953
result_repo.lock_write()
1956
repository_policy = None
1957
return result_repo, result, require_stacking, repository_policy
1824
1959
def _initialize_on_transport_vfs(self, transport):
1825
1960
"""Initialize a new bzrdir using VFS calls.
2038
2173
repository_format = property(__return_repository_format)
2041
class BzrDirFormat5(BzrDirFormat):
2176
class BzrDirFormatAllInOne(BzrDirFormat):
2177
"""Common class for formats before meta-dirs."""
2179
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2180
create_prefix=False, force_new_repo=False, stacked_on=None,
2181
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2183
"""See BzrDirFormat.initialize_on_transport_ex."""
2184
require_stacking = (stacked_on is not None)
2185
# Format 5 cannot stack, but we've been asked to - actually init
2187
if require_stacking:
2188
format = BzrDirMetaFormat1()
2189
return format.initialize_on_transport_ex(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)
2194
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2195
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2196
force_new_repo=force_new_repo, stacked_on=stacked_on,
2197
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2198
make_working_trees=make_working_trees, shared_repo=shared_repo)
2201
class BzrDirFormat5(BzrDirFormatAllInOne):
2042
2202
"""Bzr control format 5.
2044
2204
This format is a combined format for working tree, branch and repository.
2787
2952
while old != new:
2788
2953
if (old == _mod_branch.BzrBranchFormat5 and
2789
2954
new in (_mod_branch.BzrBranchFormat6,
2790
_mod_branch.BzrBranchFormat7)):
2955
_mod_branch.BzrBranchFormat7,
2956
_mod_branch.BzrBranchFormat8)):
2791
2957
branch_converter = _mod_branch.Converter5to6()
2792
2958
elif (old == _mod_branch.BzrBranchFormat6 and
2793
new == _mod_branch.BzrBranchFormat7):
2959
new in (_mod_branch.BzrBranchFormat7,
2960
_mod_branch.BzrBranchFormat8)):
2794
2961
branch_converter = _mod_branch.Converter6to7()
2962
elif (old == _mod_branch.BzrBranchFormat7 and
2963
new is _mod_branch.BzrBranchFormat8):
2964
branch_converter = _mod_branch.Converter7to8()
2796
2966
raise errors.BadConversionTarget("No converter", new)
2797
2967
branch_converter.convert(branch)
2886
3056
self._supply_sub_formats_to(format)
2887
3057
return remote.RemoteBzrDir(transport, format)
3059
def parse_NoneTrueFalse(self, arg):
3066
raise AssertionError("invalid arg %r" % arg)
3068
def _serialize_NoneTrueFalse(self, arg):
3075
def _serialize_NoneString(self, arg):
3078
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3079
create_prefix=False, force_new_repo=False, stacked_on=None,
3080
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3083
# hand off the request to the smart server
3084
client_medium = transport.get_smart_medium()
3085
except errors.NoSmartMedium:
3088
# Decline to open it if the server doesn't support our required
3089
# version (3) so that the VFS-based transport will do it.
3090
if client_medium.should_probe():
3092
server_version = client_medium.protocol_version()
3093
if server_version != '2':
3097
except errors.SmartProtocolError:
3098
# Apparently there's no usable smart server there, even though
3099
# the medium supports the smart protocol.
3104
client = _SmartClient(client_medium)
3105
path = client.remote_path_from_transport(transport)
3106
if client_medium._is_remote_before((1, 15)):
3109
# TODO: lookup the local format from a server hint.
3110
local_dir_format = BzrDirMetaFormat1()
3111
self._supply_sub_formats_to(local_dir_format)
3112
return local_dir_format.initialize_on_transport_ex(transport,
3113
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3114
force_new_repo=force_new_repo, stacked_on=stacked_on,
3115
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3116
make_working_trees=make_working_trees, shared_repo=shared_repo,
3119
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3120
args.append(self._serialize_NoneTrueFalse(create_prefix))
3121
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3122
args.append(self._serialize_NoneString(stacked_on))
3123
# stack_on_pwd is often/usually our transport
3126
stack_on_pwd = transport.relpath(stack_on_pwd)
3127
if not stack_on_pwd:
3129
except errors.PathNotChild:
3131
args.append(self._serialize_NoneString(stack_on_pwd))
3132
args.append(self._serialize_NoneString(repo_format_name))
3133
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3134
args.append(self._serialize_NoneTrueFalse(shared_repo))
3135
if self._network_name is None:
3136
self._network_name = \
3137
BzrDirFormat.get_default_format().network_name()
3139
response = client.call('BzrDirFormat.initialize_ex',
3140
self.network_name(), path, *args)
3141
except errors.UnknownSmartMethod:
3142
local_dir_format = BzrDirMetaFormat1()
3143
self._supply_sub_formats_to(local_dir_format)
3144
return local_dir_format.initialize_on_transport_ex(transport,
3145
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3146
force_new_repo=force_new_repo, stacked_on=stacked_on,
3147
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3148
make_working_trees=make_working_trees, shared_repo=shared_repo,
3150
repo_path = response[0]
3151
bzrdir_name = response[6]
3152
require_stacking = response[7]
3153
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3154
format = RemoteBzrDirFormat()
3155
format._network_name = bzrdir_name
3156
self._supply_sub_formats_to(format)
3157
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
3159
repo_format = remote.response_tuple_to_repo_format(response[1:])
3160
if repo_path == '.':
3163
repo_bzrdir_format = RemoteBzrDirFormat()
3164
repo_bzrdir_format._network_name = response[5]
3165
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3169
final_stack = response[8] or None
3170
final_stack_pwd = response[9] or None
3171
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3172
if len(response) > 10:
3173
# Updated server verb that locks remotely.
3174
repo_lock_token = response[10] or None
3175
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
3177
remote_repo.dont_leave_lock_in_place()
3179
remote_repo.lock_write()
3180
policy = UseExistingRepository(remote_repo, final_stack,
3181
final_stack_pwd, require_stacking)
3182
policy.acquire_repository()
3186
return remote_repo, bzrdir, require_stacking, policy
2889
3188
def _open(self, transport):
2890
3189
return remote.RemoteBzrDir(transport, self)
3245
3558
if not (branch_format.supports_stacking()
3246
3559
and repo_format.supports_external_lookups):
3247
3560
# Doesn't stack itself, don't force an upgrade
3250
# Does support stacking, use its format.
3251
format.repository_format = repo_format
3252
format.set_branch_format(branch_format)
3253
note('Source format does not support stacking, '
3254
'using format: \'%s\'\n %s\n',
3255
branch_format.get_format_description(),
3256
repo_format.get_format_description())
3561
branch_format = None
3563
if branch_format and repo_format:
3564
# Does support stacking, use its format.
3565
format.repository_format = repo_format
3566
format.set_branch_format(branch_format)
3567
note('Source format does not support stacking, '
3568
'using format: \'%s\'\n %s\n',
3569
branch_format.get_format_description(),
3570
repo_format.get_format_description())
3257
3571
if not self._require_stacking:
3258
3572
# We have picked up automatic stacking somewhere.
3259
3573
note('Using default stacking branch %s at %s', self._stack_on,