215
234
errors.UnstackableRepositoryFormat,
216
235
errors.NotStacked):
237
# Bug: We create a metadir without knowing if it can support stacking,
238
# we should look up the policy needs first, or just use it as a hint,
220
# may need to copy content in
221
repository_policy = result.determine_repository_policy(
222
force_new_repo, stacked_on, self.root_transport.base,
223
require_stacking=require_stacking)
224
241
make_working_trees = local_repo.make_working_trees()
225
result_repo = repository_policy.acquire_repository(
226
make_working_trees, local_repo.is_shared())
227
result_repo.fetch(local_repo, revision_id=revision_id)
242
want_shared = local_repo.is_shared()
243
repo_format_name = format.repository_format.network_name()
245
make_working_trees = False
247
repo_format_name = None
249
result_repo, result, require_stacking, repository_policy = \
250
format.initialize_on_transport_ex(transport,
251
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
252
force_new_repo=force_new_repo, stacked_on=stacked_on,
253
stack_on_pwd=self.root_transport.base,
254
repo_format_name=repo_format_name,
255
make_working_trees=make_working_trees, shared_repo=want_shared)
258
# If the result repository is in the same place as the
259
# resulting bzr dir, it will have no content, further if the
260
# result is not stacked then we know all content should be
261
# copied, and finally if we are copying up to a specific
262
# revision_id then we can use the pending-ancestry-result which
263
# does not require traversing all of history to describe it.
264
if (result_repo.bzrdir.root_transport.base ==
265
result.root_transport.base and not require_stacking and
266
revision_id is not None):
267
fetch_spec = graph.PendingAncestryResult(
268
[revision_id], local_repo)
269
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
271
result_repo.fetch(local_repo, revision_id=revision_id)
275
if result_repo is not None:
276
raise AssertionError('result_repo not None(%r)' % result_repo)
230
277
# 1 if there is a branch present
231
278
# make sure its content is available in the target repository
233
280
if local_branch is not None:
234
result_branch = local_branch.clone(result, revision_id=revision_id)
235
if repository_policy is not None:
236
repository_policy.configure_branch(result_branch)
237
if result_repo is None or result_repo.make_working_trees():
281
result_branch = local_branch.clone(result, revision_id=revision_id,
282
repository_policy=repository_policy)
284
# Cheaper to check if the target is not local, than to try making
286
result.root_transport.local_abspath('.')
287
if result_repo is None or result_repo.make_working_trees():
239
288
self.open_workingtree().clone(result)
240
except (errors.NoWorkingTree, errors.NotLocalUrl):
289
except (errors.NoWorkingTree, errors.NotLocalUrl):
244
293
# TODO: This should be given a Transport, and should chdir up; otherwise
323
381
except errors.NoRepositoryPresent:
326
return False, (None, repository)
328
branch = bzrdir.open_branch()
329
except errors.NotBranchError:
330
return True, (None, None)
332
return True, (branch, None)
334
for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
384
return False, ([], repository)
385
return True, (bzrdir.list_branches(), None)
387
for branches, repo in BzrDir.find_bzrdirs(transport,
335
389
if repo is not None:
336
branches.extend(repo.find_branches())
337
if branch is not None:
338
branches.append(branch)
390
ret.extend(repo.find_branches())
391
if branches is not None:
341
395
def destroy_repository(self):
342
396
"""Destroy the repository in this BzrDir"""
343
397
raise NotImplementedError(self.destroy_repository)
345
def create_branch(self):
399
def create_branch(self, name=None):
346
400
"""Create a branch in this BzrDir.
402
:param name: Name of the colocated branch to create, None for
348
405
The bzrdir's format will control what branch format is created.
349
406
For more control see BranchFormatXX.create(a_bzrdir).
351
408
raise NotImplementedError(self.create_branch)
353
def destroy_branch(self):
354
"""Destroy the branch in this BzrDir"""
410
def destroy_branch(self, name=None):
411
"""Destroy a branch in this BzrDir.
413
:param name: Name of the branch to destroy, None for the default
355
416
raise NotImplementedError(self.destroy_branch)
779
870
:param transport: Transport containing the bzrdir.
780
871
:param _unsupported: private.
873
for hook in BzrDir.hooks['pre_open']:
875
# Keep initial base since 'transport' may be modified while following
782
877
base = transport.base
784
878
def find_format(transport):
785
879
return transport, BzrDirFormat.find_format(
786
880
transport, _server_formats=_server_formats)
788
882
def redirected(transport, e, redirection_notice):
789
qualified_source = e.get_source_url()
790
relpath = transport.relpath(qualified_source)
791
if not e.target.endswith(relpath):
792
# Not redirected to a branch-format, not a branch
793
raise errors.NotBranchError(path=e.target)
794
target = e.target[:-len(relpath)]
883
redirected_transport = transport._redirected_to(e.source, e.target)
884
if redirected_transport is None:
885
raise errors.NotBranchError(base)
795
886
note('%s is%s redirected to %s',
796
transport.base, e.permanently, target)
797
# Let's try with a new transport
798
# FIXME: If 'transport' has a qualifier, this should
799
# be applied again to the new transport *iff* the
800
# schemes used are the same. Uncomment this code
801
# once the function (and tests) exist.
803
#target = urlutils.copy_url_qualifiers(original, target)
804
return get_transport(target)
887
transport.base, e.permanently, redirected_transport.base)
888
return redirected_transport
807
891
transport, format = do_catching_redirections(find_format,
1088
1161
where possible.
1089
1162
:param stacked: If true, create a stacked branch referring to the
1090
1163
location of this control directory.
1164
:param create_tree_if_local: If true, a working-tree will be created
1165
when working locally.
1092
1167
target_transport = get_transport(url, possible_transports)
1093
1168
target_transport.ensure_base()
1094
1169
cloning_format = self.cloning_metadir(stacked)
1095
1170
# Create/update the result branch
1096
1171
result = cloning_format.initialize_on_transport(target_transport)
1098
source_branch = self.open_branch()
1099
source_repository = source_branch.repository
1172
# if a stacked branch wasn't requested, we don't create one
1173
# even if the origin was stacked
1174
stacked_branch_url = None
1175
if source_branch is not None:
1101
1177
stacked_branch_url = self.root_transport.base
1103
# if a stacked branch wasn't requested, we don't create one
1104
# even if the origin was stacked
1105
stacked_branch_url = None
1106
except errors.NotBranchError:
1107
source_branch = None
1178
source_repository = source_branch.repository
1109
source_repository = self.open_repository()
1110
except errors.NoRepositoryPresent:
1111
source_repository = None
1112
stacked_branch_url = None
1181
source_branch = self.open_branch()
1182
source_repository = source_branch.repository
1184
stacked_branch_url = self.root_transport.base
1185
except errors.NotBranchError:
1186
source_branch = None
1188
source_repository = self.open_repository()
1189
except errors.NoRepositoryPresent:
1190
source_repository = None
1113
1191
repository_policy = result.determine_repository_policy(
1114
1192
force_new_repo, stacked_branch_url, require_stacking=stacked)
1115
result_repo = repository_policy.acquire_repository()
1193
result_repo, is_new_repo = repository_policy.acquire_repository()
1194
if is_new_repo and revision_id is not None and not stacked:
1195
fetch_spec = graph.PendingAncestryResult(
1196
[revision_id], source_repository)
1116
1199
if source_repository is not None:
1117
1200
# Fetch while stacked to prevent unstacked fetch from
1118
1201
# Branch.sprout.
1119
result_repo.fetch(source_repository, revision_id=revision_id)
1202
if fetch_spec is None:
1203
result_repo.fetch(source_repository, revision_id=revision_id)
1205
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1121
1207
if source_branch is None:
1122
1208
# this is for sprouting a bzrdir without a branch; is that
1263
def push_branch(self, source, revision_id=None, overwrite=False,
1264
remember=False, create_prefix=False):
1265
"""Push the source branch into this BzrDir."""
1267
# If we can open a branch, use its direct repository, otherwise see
1268
# if there is a repository without a branch.
1270
br_to = self.open_branch()
1271
except errors.NotBranchError:
1272
# Didn't find a branch, can we find a repository?
1273
repository_to = self.find_repository()
1275
# Found a branch, so we must have found a repository
1276
repository_to = br_to.repository
1278
push_result = PushResult()
1279
push_result.source_branch = source
1281
# We have a repository but no branch, copy the revisions, and then
1283
repository_to.fetch(source.repository, revision_id=revision_id)
1284
br_to = source.clone(self, revision_id=revision_id)
1285
if source.get_push_location() is None or remember:
1286
source.set_push_location(br_to.base)
1287
push_result.stacked_on = None
1288
push_result.branch_push_result = None
1289
push_result.old_revno = None
1290
push_result.old_revid = _mod_revision.NULL_REVISION
1291
push_result.target_branch = br_to
1292
push_result.master_branch = None
1293
push_result.workingtree_updated = False
1295
# We have successfully opened the branch, remember if necessary:
1296
if source.get_push_location() is None or remember:
1297
source.set_push_location(br_to.base)
1299
tree_to = self.open_workingtree()
1300
except errors.NotLocalUrl:
1301
push_result.branch_push_result = source.push(br_to,
1302
overwrite, stop_revision=revision_id)
1303
push_result.workingtree_updated = False
1304
except errors.NoWorkingTree:
1305
push_result.branch_push_result = source.push(br_to,
1306
overwrite, stop_revision=revision_id)
1307
push_result.workingtree_updated = None # Not applicable
1309
tree_to.lock_write()
1311
push_result.branch_push_result = source.push(
1312
tree_to.branch, overwrite, stop_revision=revision_id)
1316
push_result.workingtree_updated = True
1317
push_result.old_revno = push_result.branch_push_result.old_revno
1318
push_result.old_revid = push_result.branch_push_result.old_revid
1319
push_result.target_branch = \
1320
push_result.branch_push_result.target_branch
1324
class BzrDirHooks(hooks.Hooks):
1325
"""Hooks for BzrDir operations."""
1328
"""Create the default hooks."""
1329
hooks.Hooks.__init__(self)
1330
self.create_hook(hooks.HookPoint('pre_open',
1331
"Invoked before attempting to open a BzrDir with the transport "
1332
"that the open will use.", (1, 14), None))
1334
# install the default hooks
1335
BzrDir.hooks = BzrDirHooks()
1185
1338
class BzrDirPreSplitOut(BzrDir):
1186
1339
"""A common class for the all-in-one formats."""
1324
1482
# if the format is not the same as the system default,
1325
1483
# an upgrade is needed.
1326
1484
if format is None:
1485
symbol_versioning.warn(symbol_versioning.deprecated_in((1, 13, 0))
1486
% 'needs_format_conversion(format=None)')
1327
1487
format = BzrDirFormat.get_default_format()
1328
1488
return not isinstance(self._format, format.__class__)
1330
def open_branch(self, unsupported=False):
1490
def open_branch(self, name=None, unsupported=False,
1491
ignore_fallbacks=False):
1331
1492
"""See BzrDir.open_branch."""
1332
1493
from bzrlib.branch import BzrBranchFormat4
1333
1494
format = BzrBranchFormat4()
1334
1495
self._check_supported(format, unsupported)
1335
return format.open(self, _found=True)
1496
return format.open(self, name, _found=True)
1337
1498
def sprout(self, url, revision_id=None, force_new_repo=False,
1338
1499
possible_transports=None, accelerator_tree=None,
1339
hardlink=False, stacked=False):
1500
hardlink=False, stacked=False, create_tree_if_local=True,
1501
source_branch=None):
1340
1502
"""See BzrDir.sprout()."""
1503
if source_branch is not None:
1504
my_branch = self.open_branch()
1505
if source_branch.base != my_branch.base:
1506
raise AssertionError(
1507
"source branch %r is not within %r with branch %r" %
1508
(source_branch, self, my_branch))
1342
1510
raise errors.UnstackableBranchFormat(
1343
1511
self._format, self.root_transport.base)
1512
if not create_tree_if_local:
1513
raise errors.MustHaveWorkingTree(
1514
self._format, self.root_transport.base)
1344
1515
from bzrlib.workingtree import WorkingTreeFormat2
1345
1516
self._make_tail(url)
1346
1517
result = self._format._initialize_for_clone(url)
1695
1913
def initialize_on_transport(self, transport):
1696
1914
"""Initialize a new bzrdir in the base directory of a Transport."""
1697
# Since we don't have a .bzr directory, inherit the
1916
# can we hand off the request to the smart server rather than using
1918
client_medium = transport.get_smart_medium()
1919
except errors.NoSmartMedium:
1920
return self._initialize_on_transport_vfs(transport)
1922
# Current RPC's only know how to create bzr metadir1 instances, so
1923
# we still delegate to vfs methods if the requested format is not a
1925
if type(self) != BzrDirMetaFormat1:
1926
return self._initialize_on_transport_vfs(transport)
1927
remote_format = RemoteBzrDirFormat()
1928
self._supply_sub_formats_to(remote_format)
1929
return remote_format.initialize_on_transport(transport)
1931
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1932
create_prefix=False, force_new_repo=False, stacked_on=None,
1933
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1934
shared_repo=False, vfs_only=False):
1935
"""Create this format on transport.
1937
The directory to initialize will be created.
1939
:param force_new_repo: Do not use a shared repository for the target,
1940
even if one is available.
1941
:param create_prefix: Create any missing directories leading up to
1943
:param use_existing_dir: Use an existing directory if one exists.
1944
:param stacked_on: A url to stack any created branch on, None to follow
1945
any target stacking policy.
1946
:param stack_on_pwd: If stack_on is relative, the location it is
1948
:param repo_format_name: If non-None, a repository will be
1949
made-or-found. Should none be found, or if force_new_repo is True
1950
the repo_format_name is used to select the format of repository to
1952
:param make_working_trees: Control the setting of make_working_trees
1953
for a new shared repository when one is made. None to use whatever
1954
default the format has.
1955
:param shared_repo: Control whether made repositories are shared or
1957
:param vfs_only: If True do not attempt to use a smart server
1958
:return: repo, bzrdir, require_stacking, repository_policy. repo is
1959
None if none was created or found, bzrdir is always valid.
1960
require_stacking is the result of examining the stacked_on
1961
parameter and any stacking policy found for the target.
1964
# Try to hand off to a smart server
1966
client_medium = transport.get_smart_medium()
1967
except errors.NoSmartMedium:
1970
# TODO: lookup the local format from a server hint.
1971
remote_dir_format = RemoteBzrDirFormat()
1972
remote_dir_format._network_name = self.network_name()
1973
self._supply_sub_formats_to(remote_dir_format)
1974
return remote_dir_format.initialize_on_transport_ex(transport,
1975
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1976
force_new_repo=force_new_repo, stacked_on=stacked_on,
1977
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1978
make_working_trees=make_working_trees, shared_repo=shared_repo)
1979
# XXX: Refactor the create_prefix/no_create_prefix code into a
1980
# common helper function
1981
# The destination may not exist - if so make it according to policy.
1982
def make_directory(transport):
1983
transport.mkdir('.')
1985
def redirected(transport, e, redirection_notice):
1986
note(redirection_notice)
1987
return transport._redirected_to(e.source, e.target)
1989
transport = do_catching_redirections(make_directory, transport,
1991
except errors.FileExists:
1992
if not use_existing_dir:
1994
except errors.NoSuchFile:
1995
if not create_prefix:
1997
transport.create_prefix()
1999
require_stacking = (stacked_on is not None)
2000
# Now the target directory exists, but doesn't have a .bzr
2001
# directory. So we need to create it, along with any work to create
2002
# all of the dependent branches, etc.
2004
result = self.initialize_on_transport(transport)
2005
if repo_format_name:
2007
# use a custom format
2008
result._format.repository_format = \
2009
repository.network_format_registry.get(repo_format_name)
2010
except AttributeError:
2011
# The format didn't permit it to be set.
2013
# A repository is desired, either in-place or shared.
2014
repository_policy = result.determine_repository_policy(
2015
force_new_repo, stacked_on, stack_on_pwd,
2016
require_stacking=require_stacking)
2017
result_repo, is_new_repo = repository_policy.acquire_repository(
2018
make_working_trees, shared_repo)
2019
if not require_stacking and repository_policy._require_stacking:
2020
require_stacking = True
2021
result._format.require_stacking()
2022
result_repo.lock_write()
2025
repository_policy = None
2026
return result_repo, result, require_stacking, repository_policy
2028
def _initialize_on_transport_vfs(self, transport):
2029
"""Initialize a new bzrdir using VFS calls.
2031
:param transport: The transport to create the .bzr directory in.
2034
# Since we are creating a .bzr directory, inherit the
1698
2035
# mode from the root directory
1699
2036
temp_control = lockable_files.LockableFiles(transport,
1700
2037
'', lockable_files.TransportLock)
1875
2242
repository_format = property(__return_repository_format)
1878
class BzrDirFormat5(BzrDirFormat):
2245
class BzrDirFormatAllInOne(BzrDirFormat):
2246
"""Common class for formats before meta-dirs."""
2248
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
2249
create_prefix=False, force_new_repo=False, stacked_on=None,
2250
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
2252
"""See BzrDirFormat.initialize_on_transport_ex."""
2253
require_stacking = (stacked_on is not None)
2254
# Format 5 cannot stack, but we've been asked to - actually init
2256
if require_stacking:
2257
format = BzrDirMetaFormat1()
2258
return format.initialize_on_transport_ex(transport,
2259
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2260
force_new_repo=force_new_repo, stacked_on=stacked_on,
2261
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2262
make_working_trees=make_working_trees, shared_repo=shared_repo)
2263
return BzrDirFormat.initialize_on_transport_ex(self, transport,
2264
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
2265
force_new_repo=force_new_repo, stacked_on=stacked_on,
2266
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
2267
make_working_trees=make_working_trees, shared_repo=shared_repo)
2270
class BzrDirFormat5(BzrDirFormatAllInOne):
1879
2271
"""Bzr control format 5.
1881
2273
This format is a combined format for working tree, branch and repository.
1883
- Format 2 working trees [always]
1884
- Format 4 branches [always]
2275
- Format 2 working trees [always]
2276
- Format 4 branches [always]
1885
2277
- Format 5 repositories [always]
1886
2278
Unhashed stores in the repository.
2028
2427
def set_branch_format(self, format):
2029
2428
self._branch_format = format
2430
def require_stacking(self, stack_on=None, possible_transports=None,
2432
"""We have a request to stack, try to ensure the formats support it.
2434
:param stack_on: If supplied, it is the URL to a branch that we want to
2435
stack on. Check to see if that format supports stacking before
2438
# Stacking is desired. requested by the target, but does the place it
2439
# points at support stacking? If it doesn't then we should
2440
# not implicitly upgrade. We check this here.
2441
new_repo_format = None
2442
new_branch_format = None
2444
# a bit of state for get_target_branch so that we don't try to open it
2445
# 2 times, for both repo *and* branch
2446
target = [None, False, None] # target_branch, checked, upgrade anyway
2447
def get_target_branch():
2449
# We've checked, don't check again
2451
if stack_on is None:
2452
# No target format, that means we want to force upgrading
2453
target[:] = [None, True, True]
2456
target_dir = BzrDir.open(stack_on,
2457
possible_transports=possible_transports)
2458
except errors.NotBranchError:
2459
# Nothing there, don't change formats
2460
target[:] = [None, True, False]
2462
except errors.JailBreak:
2463
# JailBreak, JFDI and upgrade anyway
2464
target[:] = [None, True, True]
2467
target_branch = target_dir.open_branch()
2468
except errors.NotBranchError:
2469
# No branch, don't upgrade formats
2470
target[:] = [None, True, False]
2472
target[:] = [target_branch, True, False]
2475
if (not _skip_repo and
2476
not self.repository_format.supports_external_lookups):
2477
# We need to upgrade the Repository.
2478
target_branch, _, do_upgrade = get_target_branch()
2479
if target_branch is None:
2480
# We don't have a target branch, should we upgrade anyway?
2482
# stack_on is inaccessible, JFDI.
2483
# TODO: bad monkey, hard-coded formats...
2484
if self.repository_format.rich_root_data:
2485
new_repo_format = pack_repo.RepositoryFormatKnitPack5RichRoot()
2487
new_repo_format = pack_repo.RepositoryFormatKnitPack5()
2489
# If the target already supports stacking, then we know the
2490
# project is already able to use stacking, so auto-upgrade
2492
new_repo_format = target_branch.repository._format
2493
if not new_repo_format.supports_external_lookups:
2494
# target doesn't, source doesn't, so don't auto upgrade
2496
new_repo_format = None
2497
if new_repo_format is not None:
2498
self.repository_format = new_repo_format
2499
note('Source repository format does not support stacking,'
2500
' using format:\n %s',
2501
new_repo_format.get_format_description())
2503
if not self.get_branch_format().supports_stacking():
2504
# We just checked the repo, now lets check if we need to
2505
# upgrade the branch format
2506
target_branch, _, do_upgrade = get_target_branch()
2507
if target_branch is None:
2509
# TODO: bad monkey, hard-coded formats...
2510
new_branch_format = branch.BzrBranchFormat7()
2512
new_branch_format = target_branch._format
2513
if not new_branch_format.supports_stacking():
2514
new_branch_format = None
2515
if new_branch_format is not None:
2516
# Does support stacking, use its format.
2517
self.set_branch_format(new_branch_format)
2518
note('Source branch format does not support stacking,'
2519
' using format:\n %s',
2520
new_branch_format.get_format_description())
2031
2522
def get_converter(self, format=None):
2032
2523
"""See BzrDirFormat.get_converter()."""
2033
2524
if format is None:
2045
2536
"""See BzrDirFormat.get_format_description()."""
2046
2537
return "Meta directory format 1"
2539
def network_name(self):
2540
return self.get_format_string()
2048
2542
def _open(self, transport):
2049
2543
"""See BzrDirFormat._open."""
2050
return BzrDirMeta1(transport, self)
2544
# Create a new format instance because otherwise initialisation of new
2545
# metadirs share the global default format object leading to alias
2547
format = BzrDirMetaFormat1()
2548
self._supply_sub_formats_to(format)
2549
return BzrDirMeta1(transport, format)
2052
2551
def __return_repository_format(self):
2053
2552
"""Circular import protection."""
2054
if getattr(self, '_repository_format', None):
2553
if self._repository_format:
2055
2554
return self._repository_format
2056
2555
from bzrlib.repository import RepositoryFormat
2057
2556
return RepositoryFormat.get_default_format()
2059
def __set_repository_format(self, value):
2558
def _set_repository_format(self, value):
2060
2559
"""Allow changing the repository format for metadir formats."""
2061
2560
self._repository_format = value
2063
repository_format = property(__return_repository_format, __set_repository_format)
2562
repository_format = property(__return_repository_format,
2563
_set_repository_format)
2565
def _supply_sub_formats_to(self, other_format):
2566
"""Give other_format the same values for sub formats as this has.
2568
This method is expected to be used when parameterising a
2569
RemoteBzrDirFormat instance with the parameters from a
2570
BzrDirMetaFormat1 instance.
2572
:param other_format: other_format is a format which should be
2573
compatible with whatever sub formats are supported by self.
2576
if getattr(self, '_repository_format', None) is not None:
2577
other_format.repository_format = self.repository_format
2578
if self._branch_format is not None:
2579
other_format._branch_format = self._branch_format
2580
if self._workingtree_format is not None:
2581
other_format.workingtree_format = self.workingtree_format
2065
2583
def __get_workingtree_format(self):
2066
2584
if self._workingtree_format is None:
2588
3121
# TODO: conversions of Branch and Tree should be done by
2589
3122
# InterXFormat lookups
2590
3123
if (isinstance(tree, workingtree.WorkingTree3) and
2591
not isinstance(tree, workingtree_4.WorkingTree4) and
3124
not isinstance(tree, workingtree_4.DirStateWorkingTree) and
2592
3125
isinstance(self.target_format.workingtree_format,
2593
workingtree_4.WorkingTreeFormat4)):
3126
workingtree_4.DirStateWorkingTreeFormat)):
2594
3127
workingtree_4.Converter3to4().convert(tree)
3128
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3129
not isinstance(tree, workingtree_4.WorkingTree5) and
3130
isinstance(self.target_format.workingtree_format,
3131
workingtree_4.WorkingTreeFormat5)):
3132
workingtree_4.Converter4to5().convert(tree)
3133
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
3134
not isinstance(tree, workingtree_4.WorkingTree6) and
3135
isinstance(self.target_format.workingtree_format,
3136
workingtree_4.WorkingTreeFormat6)):
3137
workingtree_4.Converter4or5to6().convert(tree)
2595
3139
return to_convert
2598
# This is not in remote.py because it's small, and needs to be registered.
2599
# Putting it in remote.py creates a circular import problem.
3142
# This is not in remote.py because it's relatively small, and needs to be
3143
# registered. Putting it in remote.py creates a circular import problem.
2600
3144
# we can make it a lazy object if the control formats is turned into something
2601
3145
# like a registry.
2602
3146
class RemoteBzrDirFormat(BzrDirMetaFormat1):
2603
3147
"""Format representing bzrdirs accessed via a smart server"""
3150
BzrDirMetaFormat1.__init__(self)
3151
# XXX: It's a bit ugly that the network name is here, because we'd
3152
# like to believe that format objects are stateless or at least
3153
# immutable, However, we do at least avoid mutating the name after
3154
# it's returned. See <https://bugs.edge.launchpad.net/bzr/+bug/504102>
3155
self._network_name = None
3158
return "%s(_network_name=%r)" % (self.__class__.__name__,
2605
3161
def get_format_description(self):
3162
if self._network_name:
3163
real_format = network_format_registry.get(self._network_name)
3164
return 'Remote: ' + real_format.get_format_description()
2606
3165
return 'bzr remote bzrdir'
3167
def get_format_string(self):
3168
raise NotImplementedError(self.get_format_string)
3170
def network_name(self):
3171
if self._network_name:
3172
return self._network_name
3174
raise AssertionError("No network name set.")
2609
3177
def probe_transport(klass, transport):
2610
3178
"""Return a RemoteBzrDirFormat object if it looks possible."""
2639
3207
return local_dir_format.initialize_on_transport(transport)
2640
3208
client = _SmartClient(client_medium)
2641
3209
path = client.remote_path_from_transport(transport)
2642
response = client.call('BzrDirFormat.initialize', path)
3211
response = client.call('BzrDirFormat.initialize', path)
3212
except errors.ErrorFromSmartServer, err:
3213
remote._translate_error(err, path=path)
2643
3214
if response[0] != 'ok':
2644
3215
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2645
return remote.RemoteBzrDir(transport)
3216
format = RemoteBzrDirFormat()
3217
self._supply_sub_formats_to(format)
3218
return remote.RemoteBzrDir(transport, format)
3220
def parse_NoneTrueFalse(self, arg):
3227
raise AssertionError("invalid arg %r" % arg)
3229
def _serialize_NoneTrueFalse(self, arg):
3236
def _serialize_NoneString(self, arg):
3239
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
3240
create_prefix=False, force_new_repo=False, stacked_on=None,
3241
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
3244
# hand off the request to the smart server
3245
client_medium = transport.get_smart_medium()
3246
except errors.NoSmartMedium:
3249
# Decline to open it if the server doesn't support our required
3250
# version (3) so that the VFS-based transport will do it.
3251
if client_medium.should_probe():
3253
server_version = client_medium.protocol_version()
3254
if server_version != '2':
3258
except errors.SmartProtocolError:
3259
# Apparently there's no usable smart server there, even though
3260
# the medium supports the smart protocol.
3265
client = _SmartClient(client_medium)
3266
path = client.remote_path_from_transport(transport)
3267
if client_medium._is_remote_before((1, 16)):
3270
# TODO: lookup the local format from a server hint.
3271
local_dir_format = BzrDirMetaFormat1()
3272
self._supply_sub_formats_to(local_dir_format)
3273
return local_dir_format.initialize_on_transport_ex(transport,
3274
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3275
force_new_repo=force_new_repo, stacked_on=stacked_on,
3276
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3277
make_working_trees=make_working_trees, shared_repo=shared_repo,
3279
return self._initialize_on_transport_ex_rpc(client, path, transport,
3280
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3281
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
3283
def _initialize_on_transport_ex_rpc(self, client, path, transport,
3284
use_existing_dir, create_prefix, force_new_repo, stacked_on,
3285
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
3287
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
3288
args.append(self._serialize_NoneTrueFalse(create_prefix))
3289
args.append(self._serialize_NoneTrueFalse(force_new_repo))
3290
args.append(self._serialize_NoneString(stacked_on))
3291
# stack_on_pwd is often/usually our transport
3294
stack_on_pwd = transport.relpath(stack_on_pwd)
3295
if not stack_on_pwd:
3297
except errors.PathNotChild:
3299
args.append(self._serialize_NoneString(stack_on_pwd))
3300
args.append(self._serialize_NoneString(repo_format_name))
3301
args.append(self._serialize_NoneTrueFalse(make_working_trees))
3302
args.append(self._serialize_NoneTrueFalse(shared_repo))
3303
request_network_name = self._network_name or \
3304
BzrDirFormat.get_default_format().network_name()
3306
response = client.call('BzrDirFormat.initialize_ex_1.16',
3307
request_network_name, path, *args)
3308
except errors.UnknownSmartMethod:
3309
client._medium._remember_remote_is_before((1,16))
3310
local_dir_format = BzrDirMetaFormat1()
3311
self._supply_sub_formats_to(local_dir_format)
3312
return local_dir_format.initialize_on_transport_ex(transport,
3313
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
3314
force_new_repo=force_new_repo, stacked_on=stacked_on,
3315
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
3316
make_working_trees=make_working_trees, shared_repo=shared_repo,
3318
except errors.ErrorFromSmartServer, err:
3319
remote._translate_error(err, path=path)
3320
repo_path = response[0]
3321
bzrdir_name = response[6]
3322
require_stacking = response[7]
3323
require_stacking = self.parse_NoneTrueFalse(require_stacking)
3324
format = RemoteBzrDirFormat()
3325
format._network_name = bzrdir_name
3326
self._supply_sub_formats_to(format)
3327
bzrdir = remote.RemoteBzrDir(transport, format, _client=client)
3329
repo_format = remote.response_tuple_to_repo_format(response[1:])
3330
if repo_path == '.':
3333
repo_bzrdir_format = RemoteBzrDirFormat()
3334
repo_bzrdir_format._network_name = response[5]
3335
repo_bzr = remote.RemoteBzrDir(transport.clone(repo_path),
3339
final_stack = response[8] or None
3340
final_stack_pwd = response[9] or None
3342
final_stack_pwd = urlutils.join(
3343
transport.base, final_stack_pwd)
3344
remote_repo = remote.RemoteRepository(repo_bzr, repo_format)
3345
if len(response) > 10:
3346
# Updated server verb that locks remotely.
3347
repo_lock_token = response[10] or None
3348
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
3350
remote_repo.dont_leave_lock_in_place()
3352
remote_repo.lock_write()
3353
policy = UseExistingRepository(remote_repo, final_stack,
3354
final_stack_pwd, require_stacking)
3355
policy.acquire_repository()
3359
bzrdir._format.set_branch_format(self.get_branch_format())
3360
if require_stacking:
3361
# The repo has already been created, but we need to make sure that
3362
# we'll make a stackable branch.
3363
bzrdir._format.require_stacking(_skip_repo=True)
3364
return remote_repo, bzrdir, require_stacking, policy
2647
3366
def _open(self, transport):
2648
return remote.RemoteBzrDir(transport)
3367
return remote.RemoteBzrDir(transport, self)
2650
3369
def __eq__(self, other):
2651
3370
if not isinstance(other, RemoteBzrDirFormat):
2653
3372
return self.get_format_description() == other.get_format_description()
3374
def __return_repository_format(self):
3375
# Always return a RemoteRepositoryFormat object, but if a specific bzr
3376
# repository format has been asked for, tell the RemoteRepositoryFormat
3377
# that it should use that for init() etc.
3378
result = remote.RemoteRepositoryFormat()
3379
custom_format = getattr(self, '_repository_format', None)
3381
if isinstance(custom_format, remote.RemoteRepositoryFormat):
3382
return custom_format
3384
# We will use the custom format to create repositories over the
3385
# wire; expose its details like rich_root_data for code to
3387
result._custom_format = custom_format
3390
def get_branch_format(self):
3391
result = BzrDirMetaFormat1.get_branch_format(self)
3392
if not isinstance(result, remote.RemoteBranchFormat):
3393
new_result = remote.RemoteBranchFormat()
3394
new_result._custom_format = result
3396
self.set_branch_format(new_result)
3400
repository_format = property(__return_repository_format,
3401
BzrDirMetaFormat1._set_repository_format) #.im_func)
2656
3404
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
2952
3737
def acquire_repository(self, make_working_trees=None, shared=False):
2953
3738
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
2955
Returns an existing repository to use
3740
Returns an existing repository to use.
2957
self._add_fallback(self._repository)
2958
return self._repository
3742
self._add_fallback(self._repository,
3743
possible_transports=[self._repository.bzrdir.transport])
3744
return self._repository, False
3747
# Please register new formats after old formats so that formats
3748
# appear in chronological order and format descriptions can build
2961
3750
format_registry = BzrDirFormatRegistry()
3751
# The pre-0.8 formats have their repository format network name registered in
3752
# repository.py. MetaDir formats have their repository format network name
3753
# inferred from their disk format string.
2962
3754
format_registry.register('weave', BzrDirFormat6,
2963
3755
'Pre-0.8 format. Slower than knit and does not'
2964
3756
' support checkouts or shared repositories.',
2965
3758
deprecated=True)
2966
format_registry.register_metadir('knit',
2967
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
2968
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
2969
branch_format='bzrlib.branch.BzrBranchFormat5',
2970
tree_format='bzrlib.workingtree.WorkingTreeFormat3')
2971
3759
format_registry.register_metadir('metaweave',
2972
3760
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
2973
3761
'Transitional format in 0.8. Slower than knit.',
2974
3762
branch_format='bzrlib.branch.BzrBranchFormat5',
2975
3763
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3766
format_registry.register_metadir('knit',
3767
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3768
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3769
branch_format='bzrlib.branch.BzrBranchFormat5',
3770
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
2976
3772
deprecated=True)
2977
3773
format_registry.register_metadir('dirstate',
2978
3774
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3035
3830
format_registry.register_metadir('rich-root-pack',
3036
3831
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3037
help='New in 1.0: Pack-based format with data compatible with '
3038
'rich-root format repositories. Incompatible with'
3832
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3833
'(needed for bzr-svn and bzr-git).',
3040
3834
branch_format='bzrlib.branch.BzrBranchFormat6',
3041
3835
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3043
3838
format_registry.register_metadir('1.6',
3044
3839
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3045
help='A branch and pack based repository that supports stacking. ',
3840
help='A format that allows a branch to indicate that there is another '
3841
'(stacked) repository that should be used to access data that is '
3842
'not present locally.',
3046
3843
branch_format='bzrlib.branch.BzrBranchFormat7',
3047
3844
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3049
3847
format_registry.register_metadir('1.6.1-rich-root',
3050
3848
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3051
help='A branch and pack based repository that supports stacking '
3052
'and rich root data (needed for bzr-svn). ',
3053
branch_format='bzrlib.branch.BzrBranchFormat7',
3054
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3056
# The following two formats should always just be aliases.
3057
format_registry.register_metadir('development',
3058
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3059
help='Current development format. Can convert data to and from pack-0.92 '
3060
'(and anything compatible with pack-0.92) format repositories. '
3061
'Repositories and branches in this format can only be read by bzr.dev. '
3063
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3849
help='A variant of 1.6 that supports rich-root data '
3850
'(needed for bzr-svn and bzr-git).',
3851
branch_format='bzrlib.branch.BzrBranchFormat7',
3852
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3855
format_registry.register_metadir('1.9',
3856
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3857
help='A repository format using B+tree indexes. These indexes '
3858
'are smaller in size, have smarter caching and provide faster '
3859
'performance for most operations.',
3860
branch_format='bzrlib.branch.BzrBranchFormat7',
3861
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3864
format_registry.register_metadir('1.9-rich-root',
3865
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3866
help='A variant of 1.9 that supports rich-root data '
3867
'(needed for bzr-svn and bzr-git).',
3868
branch_format='bzrlib.branch.BzrBranchFormat7',
3869
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3872
format_registry.register_metadir('1.14',
3873
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3874
help='A working-tree format that supports content filtering.',
3875
branch_format='bzrlib.branch.BzrBranchFormat7',
3876
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3878
format_registry.register_metadir('1.14-rich-root',
3879
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3880
help='A variant of 1.14 that supports rich-root data '
3881
'(needed for bzr-svn and bzr-git).',
3882
branch_format='bzrlib.branch.BzrBranchFormat7',
3883
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3885
# The following un-numbered 'development' formats should always just be aliases.
3886
format_registry.register_metadir('development-rich-root',
3887
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3888
help='Current development format. Supports rich roots. Can convert data '
3889
'to and from rich-root-pack (and anything compatible with '
3890
'rich-root-pack) format repositories. Repositories and branches in '
3891
'this format can only be read by bzr.dev. Please read '
3892
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3065
3894
branch_format='bzrlib.branch.BzrBranchFormat7',
3066
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3895
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3067
3896
experimental=True,
3070
3900
format_registry.register_metadir('development-subtree',
3071
3901
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3073
3903
'from pack-0.92-subtree (and anything compatible with '
3074
3904
'pack-0.92-subtree) format repositories. Repositories and branches in '
3075
3905
'this format can only be read by bzr.dev. Please read '
3076
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3906
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3078
3908
branch_format='bzrlib.branch.BzrBranchFormat7',
3079
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3909
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3080
3910
experimental=True,
3912
alias=False, # Restore to being an alias when an actual development subtree format is added
3913
# This current non-alias status is simply because we did not introduce a
3914
# chk based subtree format.
3083
3917
# And the development formats above will have aliased one of the following:
3084
format_registry.register_metadir('development2',
3085
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2',
3086
help='1.6.1 with B+Tree based index. '
3088
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3090
branch_format='bzrlib.branch.BzrBranchFormat7',
3091
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3095
format_registry.register_metadir('development2-subtree',
3096
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3097
help='1.6.1-subtree with B+Tree based index. '
3099
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3101
branch_format='bzrlib.branch.BzrBranchFormat7',
3102
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3918
format_registry.register_metadir('development6-rich-root',
3919
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3920
help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3922
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3924
branch_format='bzrlib.branch.BzrBranchFormat7',
3925
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3930
format_registry.register_metadir('development7-rich-root',
3931
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3932
help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3933
'rich roots. Please read '
3934
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3936
branch_format='bzrlib.branch.BzrBranchFormat7',
3937
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3942
format_registry.register_metadir('2a',
3943
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3944
help='First format for bzr 2.0 series.\n'
3945
'Uses group-compress storage.\n'
3946
'Provides rich roots which are a one-way transition.\n',
3947
# 'storage in packs, 255-way hashed CHK inventory, bencode revision, group compress, '
3948
# 'rich roots. Supported by bzr 1.16 and later.',
3949
branch_format='bzrlib.branch.BzrBranchFormat7',
3950
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3954
# The following format should be an alias for the rich root equivalent
3955
# of the default format
3956
format_registry.register_metadir('default-rich-root',
3957
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3958
branch_format='bzrlib.branch.BzrBranchFormat7',
3959
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3106
3964
# The current format that is made on 'bzr init'.
3107
format_registry.set_default('pack-0.92')
3965
format_registry.set_default('2a')