225
218
errors.UnstackableRepositoryFormat,
226
219
errors.NotStacked):
228
# Bug: We create a metadir without knowing if it can support stacking,
229
# 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)
232
227
make_working_trees = local_repo.make_working_trees()
233
want_shared = local_repo.is_shared()
234
repo_format_name = format.repository_format.network_name()
236
make_working_trees = False
238
repo_format_name = None
240
result_repo, result, require_stacking, repository_policy = \
241
format.initialize_on_transport_ex(transport,
242
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
243
force_new_repo=force_new_repo, stacked_on=stacked_on,
244
stack_on_pwd=self.root_transport.base,
245
repo_format_name=repo_format_name,
246
make_working_trees=make_working_trees, shared_repo=want_shared)
249
# If the result repository is in the same place as the
250
# resulting bzr dir, it will have no content, further if the
251
# result is not stacked then we know all content should be
252
# copied, and finally if we are copying up to a specific
253
# revision_id then we can use the pending-ancestry-result which
254
# does not require traversing all of 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):
258
fetch_spec = graph.PendingAncestryResult(
259
[revision_id], local_repo)
260
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
262
result_repo.fetch(local_repo, revision_id=revision_id)
266
if result_repo is not None:
267
raise AssertionError('result_repo not None(%r)' % result_repo)
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)
268
241
# 1 if there is a branch present
269
242
# make sure its content is available in the target repository
1863
1821
self._supply_sub_formats_to(remote_format)
1864
1822
return remote_format.initialize_on_transport(transport)
1866
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1867
create_prefix=False, force_new_repo=False, stacked_on=None,
1868
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1869
shared_repo=False, vfs_only=False):
1870
"""Create this format on transport.
1872
The directory to initialize will be created.
1874
:param force_new_repo: Do not use a shared repository for the target,
1875
even if one is available.
1876
:param create_prefix: Create any missing directories leading up to
1878
:param use_existing_dir: Use an existing directory if one exists.
1879
:param stacked_on: A url to stack any created branch on, None to follow
1880
any target stacking policy.
1881
:param stack_on_pwd: If stack_on is relative, the location it is
1883
:param repo_format_name: If non-None, a repository will be
1884
made-or-found. Should none be found, or if force_new_repo is True
1885
the repo_format_name is used to select the format of repository to
1887
:param make_working_trees: Control the setting of make_working_trees
1888
for a new shared repository when one is made. None to use whatever
1889
default the format has.
1890
:param shared_repo: Control whether made repositories are shared or
1892
:param vfs_only: If True do not attempt to use a smart server
1893
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1894
None if none was created or found, bzrdir is always valid.
1895
require_stacking is the result of examining the stacked_on
1896
parameter and any stacking policy found for the target.
1899
# Try to hand off to a smart server
1901
client_medium = transport.get_smart_medium()
1902
except errors.NoSmartMedium:
1905
# TODO: lookup the local format from a server hint.
1906
remote_dir_format = RemoteBzrDirFormat()
1907
remote_dir_format._network_name = self.network_name()
1908
self._supply_sub_formats_to(remote_dir_format)
1909
return remote_dir_format.initialize_on_transport_ex(transport,
1910
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1911
force_new_repo=force_new_repo, stacked_on=stacked_on,
1912
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1913
make_working_trees=make_working_trees, shared_repo=shared_repo)
1914
# XXX: Refactor the create_prefix/no_create_prefix code into a
1915
# common helper function
1916
# The destination may not exist - if so make it according to policy.
1917
def make_directory(transport):
1918
transport.mkdir('.')
1920
def redirected(transport, e, redirection_notice):
1921
note(redirection_notice)
1922
return transport._redirected_to(e.source, e.target)
1924
transport = do_catching_redirections(make_directory, transport,
1926
except errors.FileExists:
1927
if not use_existing_dir:
1929
except errors.NoSuchFile:
1930
if not create_prefix:
1932
transport.create_prefix()
1934
require_stacking = (stacked_on is not None)
1935
# Now the target directory exists, but doesn't have a .bzr
1936
# directory. So we need to create it, along with any work to create
1937
# all of the dependent branches, etc.
1939
result = self.initialize_on_transport(transport)
1940
if repo_format_name:
1942
# use a custom format
1943
result._format.repository_format = \
1944
repository.network_format_registry.get(repo_format_name)
1945
except AttributeError:
1946
# The format didn't permit it to be set.
1948
# A repository is desired, either in-place or shared.
1949
repository_policy = result.determine_repository_policy(
1950
force_new_repo, stacked_on, stack_on_pwd,
1951
require_stacking=require_stacking)
1952
result_repo, is_new_repo = repository_policy.acquire_repository(
1953
make_working_trees, shared_repo)
1954
if not require_stacking and repository_policy._require_stacking:
1955
require_stacking = True
1956
result._format.require_stacking()
1957
result_repo.lock_write()
1960
repository_policy = None
1961
return result_repo, result, require_stacking, repository_policy
1963
1824
def _initialize_on_transport_vfs(self, transport):
1964
1825
"""Initialize a new bzrdir using VFS calls.
2177
2038
repository_format = property(__return_repository_format)
2180
class BzrDirFormatAllInOne(BzrDirFormat):
2181
"""Common class for formats before meta-dirs."""
2183
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2184
create_prefix=False, force_new_repo=False, stacked_on=None,
2185
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2187
"""See BzrDirFormat.initialize_on_transport_ex."""
2188
require_stacking = (stacked_on is not None)
2189
# Format 5 cannot stack, but we've been asked to - actually init
2191
if require_stacking:
2192
format = BzrDirMetaFormat1()
2193
return format.initialize_on_transport_ex(transport,
2194
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2195
force_new_repo=force_new_repo, stacked_on=stacked_on,
2196
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2197
make_working_trees=make_working_trees, shared_repo=shared_repo)
2198
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2199
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2200
force_new_repo=force_new_repo, stacked_on=stacked_on,
2201
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2202
make_working_trees=make_working_trees, shared_repo=shared_repo)
2205
class BzrDirFormat5(BzrDirFormatAllInOne):
2041
class BzrDirFormat5(BzrDirFormat):
2206
2042
"""Bzr control format 5.
2208
2044
This format is a combined format for working tree, branch and repository.
2362
2198
def set_branch_format(self, format):
2363
2199
self._branch_format = format
2365
def require_stacking(self, stack_on=None, possible_transports=None,
2367
"""We have a request to stack, try to ensure the formats support it.
2369
:param stack_on: If supplied, it is the URL to a branch that we want to
2370
stack on. Check to see if that format supports stacking before
2373
# Stacking is desired. requested by the target, but does the place it
2374
# points at support stacking? If it doesn't then we should
2375
# not implicitly upgrade. We check this here.
2376
new_repo_format = None
2377
new_branch_format = None
2379
# a bit of state for get_target_branch so that we don't try to open it
2380
# 2 times, for both repo *and* branch
2381
target = [None, False, None] # target_branch, checked, upgrade anyway
2382
def get_target_branch():
2384
# We've checked, don't check again
2386
if stack_on is None:
2387
# No target format, that means we want to force upgrading
2388
target[:] = [None, True, True]
2391
target_dir = BzrDir.open(stack_on,
2392
possible_transports=possible_transports)
2393
except errors.NotBranchError:
2394
# Nothing there, don't change formats
2395
target[:] = [None, True, False]
2397
except errors.JailBreak:
2398
# JailBreak, JFDI and upgrade anyway
2399
target[:] = [None, True, True]
2402
target_branch = target_dir.open_branch()
2403
except errors.NotBranchError:
2404
# No branch, don't upgrade formats
2405
target[:] = [None, True, False]
2407
target[:] = [target_branch, True, False]
2410
if (not _skip_repo and
2411
not self.repository_format.supports_external_lookups):
2412
# We need to upgrade the Repository.
2413
target_branch, _, do_upgrade = get_target_branch()
2414
if target_branch is None:
2415
# We don't have a target branch, should we upgrade anyway?
2417
# stack_on is inaccessible, JFDI.
2418
# TODO: bad monkey, hard-coded formats...
2419
if self.repository_format.rich_root_data:
2420
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2422
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2424
# If the target already supports stacking, then we know the
2425
# project is already able to use stacking, so auto-upgrade
2427
new_repo_format = target_branch.repository._format
2428
if not new_repo_format.supports_external_lookups:
2429
# target doesn't, source doesn't, so don't auto upgrade
2431
new_repo_format = None
2432
if new_repo_format is not None:
2433
self.repository_format = new_repo_format
2434
note('Source repository format does not support stacking,'
2435
' using format:\n %s',
2436
new_repo_format.get_format_description())
2201
def require_stacking(self):
2438
2202
if not self.get_branch_format().supports_stacking():
2439
# We just checked the repo, now lets check if we need to
2440
# upgrade the branch format
2441
target_branch, _, do_upgrade = get_target_branch()
2442
if target_branch is None:
2444
# TODO: bad monkey, hard-coded formats...
2445
new_branch_format = branch.BzrBranchFormat7()
2203
# We need to make a stacked branch, but the default format for the
2204
# target doesn't support stacking. So force a branch that *can*
2206
from bzrlib.branch import BzrBranchFormat7
2207
branch_format = BzrBranchFormat7()
2208
self.set_branch_format(branch_format)
2209
mutter("using %r for stacking" % (branch_format,))
2210
from bzrlib.repofmt import pack_repo
2211
if self.repository_format.rich_root_data:
2212
bzrdir_format_name = '1.6.1-rich-root'
2213
repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2447
new_branch_format = target_branch._format
2448
if not new_branch_format.supports_stacking():
2449
new_branch_format = None
2450
if new_branch_format is not None:
2451
# Does support stacking, use its format.
2452
self.set_branch_format(new_branch_format)
2453
note('Source branch format does not support stacking,'
2454
' using format:\n %s',
2455
new_branch_format.get_format_description())
2215
bzrdir_format_name = '1.6'
2216
repo_format = pack_repo.RepositoryFormatKnitPack5()
2217
note('Source format does not support stacking, using format:'
2219
bzrdir_format_name, repo_format.get_format_description())
2220
self.repository_format = repo_format
2457
2222
def get_converter(self, format=None):
2458
2223
"""See BzrDirFormat.get_converter()."""
3125
2879
return local_dir_format.initialize_on_transport(transport)
3126
2880
client = _SmartClient(client_medium)
3127
2881
path = client.remote_path_from_transport(transport)
3129
response = client.call('BzrDirFormat.initialize', path)
3130
except errors.ErrorFromSmartServer, err:
3131
remote._translate_error(err, path=path)
2882
response = client.call('BzrDirFormat.initialize', path)
3132
2883
if response[0] != 'ok':
3133
2884
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
3134
2885
format = RemoteBzrDirFormat()
3135
2886
self._supply_sub_formats_to(format)
3136
2887
return remote.RemoteBzrDir(transport, format)
3138
def parse_NoneTrueFalse(self, arg):
3145
raise AssertionError("invalid arg %r" % arg)
3147
def _serialize_NoneTrueFalse(self, arg):
3154
def _serialize_NoneString(self, arg):
3157
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3158
create_prefix=False, force_new_repo=False, stacked_on=None,
3159
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3162
# hand off the request to the smart server
3163
client_medium = transport.get_smart_medium()
3164
except errors.NoSmartMedium:
3167
# Decline to open it if the server doesn't support our required
3168
# version (3) so that the VFS-based transport will do it.
3169
if client_medium.should_probe():
3171
server_version = client_medium.protocol_version()
3172
if server_version != '2':
3176
except errors.SmartProtocolError:
3177
# Apparently there's no usable smart server there, even though
3178
# the medium supports the smart protocol.
3183
client = _SmartClient(client_medium)
3184
path = client.remote_path_from_transport(transport)
3185
if client_medium._is_remote_before((1, 16)):
3188
# TODO: lookup the local format from a server hint.
3189
local_dir_format = BzrDirMetaFormat1()
3190
self._supply_sub_formats_to(local_dir_format)
3191
return local_dir_format.initialize_on_transport_ex(transport,
3192
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3193
force_new_repo=force_new_repo, stacked_on=stacked_on,
3194
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3195
make_working_trees=make_working_trees, shared_repo=shared_repo,
3197
return self._initialize_on_transport_ex_rpc(client, path, transport,
3198
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3199
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3201
def _initialize_on_transport_ex_rpc(self, client, path, transport,
3202
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3203
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3205
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3206
args.append(self._serialize_NoneTrueFalse(create_prefix))
3207
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3208
args.append(self._serialize_NoneString(stacked_on))
3209
# stack_on_pwd is often/usually our transport
3212
stack_on_pwd = transport.relpath(stack_on_pwd)
3213
if not stack_on_pwd:
3215
except errors.PathNotChild:
3217
args.append(self._serialize_NoneString(stack_on_pwd))
3218
args.append(self._serialize_NoneString(repo_format_name))
3219
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3220
args.append(self._serialize_NoneTrueFalse(shared_repo))
3221
if self._network_name is None:
3222
self._network_name = \
3223
BzrDirFormat.get_default_format().network_name()
3225
response = client.call('BzrDirFormat.initialize_ex_1.16',
3226
self.network_name(), path, *args)
3227
except errors.UnknownSmartMethod:
3228
client._medium._remember_remote_is_before((1,16))
3229
local_dir_format = BzrDirMetaFormat1()
3230
self._supply_sub_formats_to(local_dir_format)
3231
return local_dir_format.initialize_on_transport_ex(transport,
3232
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3233
force_new_repo=force_new_repo, stacked_on=stacked_on,
3234
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3235
make_working_trees=make_working_trees, shared_repo=shared_repo,
3237
except errors.ErrorFromSmartServer, err:
3238
remote._translate_error(err, path=path)
3239
repo_path = response[0]
3240
bzrdir_name = response[6]
3241
require_stacking = response[7]
3242
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3243
format = RemoteBzrDirFormat()
3244
format._network_name = bzrdir_name
3245
self._supply_sub_formats_to(format)
3246
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
3248
repo_format = remote.response_tuple_to_repo_format(response[1:])
3249
if repo_path == '.':
3252
repo_bzrdir_format = RemoteBzrDirFormat()
3253
repo_bzrdir_format._network_name = response[5]
3254
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3258
final_stack = response[8] or None
3259
final_stack_pwd = response[9] or None
3261
final_stack_pwd = urlutils.join(
3262
transport.base, final_stack_pwd)
3263
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3264
if len(response) > 10:
3265
# Updated server verb that locks remotely.
3266
repo_lock_token = response[10] or None
3267
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
3269
remote_repo.dont_leave_lock_in_place()
3271
remote_repo.lock_write()
3272
policy = UseExistingRepository(remote_repo, final_stack,
3273
final_stack_pwd, require_stacking)
3274
policy.acquire_repository()
3278
bzrdir._format.set_branch_format(self.get_branch_format())
3279
if require_stacking:
3280
# The repo has already been created, but we need to make sure that
3281
# we'll make a stackable branch.
3282
bzrdir._format.require_stacking(_skip_repo=True)
3283
return remote_repo, bzrdir, require_stacking, policy
3285
2889
def _open(self, transport):
3286
2890
return remote.RemoteBzrDir(transport, self)
3623
3217
stack_on = self._get_full_stack_on()
3219
# Stacking is desired. requested by the target, but does the place it
3220
# points at support stacking? If it doesn't then we should
3221
# not implicitly upgrade. We check this here.
3625
3222
format = self._bzrdir._format
3626
format.require_stacking(stack_on=stack_on,
3627
possible_transports=[self._bzrdir.root_transport])
3223
if not (format.repository_format.supports_external_lookups
3224
and format.get_branch_format().supports_stacking()):
3225
# May need to upgrade - but only do if the target also
3226
# supports stacking. Note that this currently wastes
3227
# network round trips to check - but we only do this
3228
# when the source can't stack so it will fade away
3229
# as people do upgrade.
3231
target_dir = BzrDir.open(stack_on,
3232
possible_transports=[self._bzrdir.root_transport])
3233
except errors.NotBranchError:
3234
# Nothing there, don't change formats
3238
target_branch = target_dir.open_branch()
3239
except errors.NotBranchError:
3240
# No branch, don't change formats
3243
branch_format = target_branch._format
3244
repo_format = target_branch.repository._format
3245
if not (branch_format.supports_stacking()
3246
and repo_format.supports_external_lookups):
3247
# 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())
3628
3257
if not self._require_stacking:
3629
3258
# We have picked up automatic stacking somewhere.
3630
3259
note('Using default stacking branch %s at %s', self._stack_on,
3837
3466
experimental=True,
3840
format_registry.register_metadir('development7-rich-root',
3841
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3842
help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3843
'rich roots. Please read '
3844
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3846
branch_format='bzrlib.branch.BzrBranchFormat7',
3847
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3852
format_registry.register_metadir('2a',
3853
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3854
help='First format for bzr 2.0 series.\n'
3855
'Uses group-compress storage.\n'
3856
'Provides rich roots which are a one-way transition.\n',
3857
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3858
# 'rich roots. Supported by bzr 1.16 and later.',
3859
branch_format='bzrlib.branch.BzrBranchFormat7',
3860
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3864
3469
# The following format should be an alias for the rich root equivalent
3865
3470
# of the default format
3866
3471
format_registry.register_metadir('default-rich-root',
3867
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3868
branch_format='bzrlib.branch.BzrBranchFormat7',
3869
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3472
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3473
help='Default format, rich root variant. (needed for bzr-svn and bzr-git).',
3474
branch_format='bzrlib.branch.BzrBranchFormat6',
3475
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3873
3478
# The current format that is made on 'bzr init'.
3874
format_registry.set_default('2a')
3479
format_registry.set_default('pack-0.92')