32
32
from ..lazy_import import lazy_import
33
33
lazy_import(globals(), """
35
34
from breezy import (
36
35
branch as _mod_branch,
45
41
revision as _mod_revision,
46
42
transport as _mod_transport,
135
131
def check_conversion_target(self, target_format):
136
132
"""Check that a bzrdir as a whole can be converted to a new format."""
137
# The only current restriction is that the repository content can be
133
# The only current restriction is that the repository content can be
138
134
# fetched compatibly with the target.
139
135
target_repo_format = target_format.repository_format
147
143
def clone_on_transport(self, transport, revision_id=None,
148
force_new_repo=False, preserve_stacking=False, stacked_on=None,
149
create_prefix=False, use_existing_dir=True, no_tree=False):
144
force_new_repo=False, preserve_stacking=False, stacked_on=None,
145
create_prefix=False, use_existing_dir=True, no_tree=False):
150
146
"""Clone this bzrdir and its contents to transport verbatim.
152
148
:param transport: The transport for the location to produce the clone
195
191
# we should look up the policy needs first, or just use it as a hint,
198
make_working_trees = local_repo.make_working_trees() and not no_tree
194
make_working_trees = (local_repo.make_working_trees() and
199
196
want_shared = local_repo.is_shared()
200
197
repo_format_name = format.repository_format.network_name()
204
201
repo_format_name = None
206
203
result_repo, result, require_stacking, repository_policy = \
207
format.initialize_on_transport_ex(transport,
208
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
209
force_new_repo=force_new_repo, stacked_on=stacked_on,
210
stack_on_pwd=self.root_transport.base,
211
repo_format_name=repo_format_name,
212
make_working_trees=make_working_trees, shared_repo=want_shared)
204
format.initialize_on_transport_ex(
205
transport, use_existing_dir=use_existing_dir,
206
create_prefix=create_prefix, force_new_repo=force_new_repo,
207
stacked_on=stacked_on, stack_on_pwd=self.root_transport.base,
208
repo_format_name=repo_format_name,
209
make_working_trees=make_working_trees, shared_repo=want_shared)
213
210
if repo_format_name:
215
212
# If the result repository is in the same place as the
219
216
# revision_id then we can use the pending-ancestry-result which
220
217
# does not require traversing all of history to describe it.
221
218
if (result_repo.user_url == result.user_url
222
and not require_stacking and
223
revision_id is not None):
219
and not require_stacking
220
and revision_id is not None):
224
221
fetch_spec = vf_search.PendingAncestryResult(
225
222
[revision_id], local_repo)
226
223
result_repo.fetch(local_repo, fetch_spec=fetch_spec)
235
232
# make sure its content is available in the target repository
237
234
if local_branch is not None:
238
result_branch = local_branch.clone(result, revision_id=revision_id,
236
result, revision_id=revision_id,
239
237
repository_policy=repository_policy)
241
239
# Cheaper to check if the target is not local, than to try making
283
281
except errors.NoRepositoryPresent:
284
282
repository = None
286
if (found_bzrdir.user_url != self.user_url
287
and not repository.is_shared()):
284
if (found_bzrdir.user_url != self.user_url and
285
not repository.is_shared()):
288
286
# Don't look higher, can't use a higher shared repo.
289
287
repository = None
294
292
return None, False
296
return UseExistingRepository(repository, stack_on,
297
stack_on_pwd, require_stacking=require_stacking), True
294
return UseExistingRepository(
295
repository, stack_on, stack_on_pwd,
296
require_stacking=require_stacking), True
299
return CreateRepository(self, stack_on, stack_on_pwd,
298
return CreateRepository(
299
self, stack_on, stack_on_pwd,
300
300
require_stacking=require_stacking), True
302
302
if not force_new_repo:
309
309
return UseExistingRepository(
310
self.open_repository(), stack_on, stack_on_pwd,
311
require_stacking=require_stacking)
310
self.open_repository(), stack_on, stack_on_pwd,
311
require_stacking=require_stacking)
312
312
except errors.NoRepositoryPresent:
314
314
return CreateRepository(self, stack_on, stack_on_pwd,
322
322
def _find_source_repo(self, add_cleanup, source_branch):
323
323
"""Find the source branch and repo for a sprout operation.
325
325
This is helper intended for use by _sprout.
327
327
:returns: (source_branch, source_repository). Either or both may be
377
377
:return: The created control directory
379
379
operation = cleanup.OperationWithCleanups(self._sprout)
380
return operation.run(url, revision_id=revision_id,
381
force_new_repo=force_new_repo, recurse=recurse,
382
possible_transports=possible_transports,
380
return operation.run(
381
url, revision_id=revision_id, force_new_repo=force_new_repo,
382
recurse=recurse, possible_transports=possible_transports,
383
383
accelerator_tree=accelerator_tree, hardlink=hardlink,
384
384
stacked=stacked, source_branch=source_branch,
385
385
create_tree_if_local=create_tree_if_local)
387
387
def _sprout(self, op, url, revision_id=None, force_new_repo=False,
388
recurse='down', possible_transports=None,
389
accelerator_tree=None, hardlink=False, stacked=False,
390
source_branch=None, create_tree_if_local=True, lossy=False):
388
recurse='down', possible_transports=None,
389
accelerator_tree=None, hardlink=False, stacked=False,
390
source_branch=None, create_tree_if_local=True, lossy=False):
391
391
add_cleanup = op.add_cleanup
392
392
fetch_spec_factory = fetch.FetchSpecFactory()
393
393
if revision_id is not None:
399
399
possible_transports = list(possible_transports) + [
400
400
self.root_transport]
401
401
target_transport = _mod_transport.get_transport(url,
403
403
target_transport.ensure_base()
404
404
cloning_format = self.cloning_metadir(stacked)
405
405
# Create/update the result branch
407
result = controldir.ControlDir.open_from_transport(target_transport)
407
result = controldir.ControlDir.open_from_transport(
408
409
except errors.NotBranchError:
409
410
result = cloning_format.initialize_on_transport(target_transport)
410
411
source_branch, source_repository = self._find_source_repo(
440
441
# Not especially, but it's part of the contract.
441
442
result_branch = result.create_branch()
443
result_branch = source_branch.sprout(result,
444
revision_id=revision_id, repository_policy=repository_policy,
445
repository=result_repo)
444
result_branch = source_branch.sprout(
445
result, revision_id=revision_id,
446
repository_policy=repository_policy, repository=result_repo)
446
447
mutter("created new branch %r" % (result_branch,))
448
449
# Create/update the result working tree
449
if (create_tree_if_local and not result.has_workingtree() and
450
isinstance(target_transport, local.LocalTransport) and
451
(result_repo is None or result_repo.make_working_trees())):
452
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
453
hardlink=hardlink, from_branch=result_branch)
450
if (create_tree_if_local and not result.has_workingtree()
451
and isinstance(target_transport, local.LocalTransport)
452
and (result_repo is None or result_repo.make_working_trees())):
453
wt = result.create_workingtree(
454
accelerator_tree=accelerator_tree, hardlink=hardlink,
455
from_branch=result_branch)
454
456
with wt.lock_write():
455
457
if not wt.is_versioned(''):
475
477
for path, file_id in subtrees:
476
478
target = urlutils.join(url, urlutils.escape(path))
477
479
sublocation = source_branch.reference_parent(path, file_id)
478
sublocation.controldir.sprout(target,
479
basis.get_reference_revision(path, file_id),
480
sublocation.controldir.sprout(
481
target, basis.get_reference_revision(path),
480
482
force_new_repo=force_new_repo, recurse=recurse,
494
496
:return: Tuple with old path name and new path name
497
with ui.ui_factory.nested_progress_bar() as pb:
499
with ui.ui_factory.nested_progress_bar():
498
500
old_path = self.root_transport.abspath('.bzr')
499
501
backup_dir = self._available_backup_name('backup.bzr')
500
502
new_path = self.root_transport.abspath(backup_dir)
501
ui.ui_factory.note(gettext('making backup of {0}\n to {1}').format(
502
urlutils.unescape_for_display(old_path, 'utf-8'),
503
urlutils.unescape_for_display(new_path, 'utf-8')))
504
gettext('making backup of {0}\n to {1}').format(
505
urlutils.unescape_for_display(old_path, 'utf-8'),
506
urlutils.unescape_for_display(new_path, 'utf-8')))
504
507
self.root_transport.copy_tree('.bzr', backup_dir)
505
508
return (old_path, new_path)
645
648
:param _transport: the transport this dir is based at.
647
650
self._format = _format
648
# these are also under the more standard names of
651
# these are also under the more standard names of
649
652
# control_transport and user_transport
650
653
self.transport = _transport.clone('.bzr')
651
654
self.root_transport = _transport
652
655
self._mode_check_done = False
655
658
def user_transport(self):
656
659
return self.root_transport
665
668
:param filename: A filename within the root transport of this bzrdir.
667
This is true IF and ONLY IF the filename is part of the namespace reserved
668
for bzr control dirs. Currently this is the '.bzr' directory in the root
669
of the root_transport.
670
This is true IF and ONLY IF the filename is part of the namespace
671
reserved for bzr control dirs. Currently this is the '.bzr' directory
672
in the root of the root_transport.
671
674
# this might be better on the BzrDirFormat class because it refers to
672
675
# all the possible bzrdir disk formats.
673
676
# This method is tested via the workingtree is_control_filename tests-
674
# it was extracted from WorkingTree.is_control_filename. If the method's
675
# contract is extended beyond the current trivial implementation, please
676
# add new tests for it to the appropriate place.
677
# it was extracted from WorkingTree.is_control_filename. If the
678
# method's contract is extended beyond the current trivial
679
# implementation, please add new tests for it to the appropriate place.
677
680
return filename == '.bzr' or filename.startswith('.bzr/')
679
682
def _cloning_metadir(self):
688
691
source_repository = branch.repository
689
692
result_format._branch_format = branch._format
690
693
except errors.NotBranchError:
692
694
source_repository = self.open_repository()
693
695
except errors.NoRepositoryPresent:
694
696
source_repository = None
734
736
# We have a repository, so set a working tree? (Why? This seems to
735
737
# contradict the stated return value in the docstring).
736
tree_format = repository._format._matchingcontroldir.workingtree_format
739
repository._format._matchingcontroldir.workingtree_format)
737
740
format.workingtree_format = tree_format.__class__()
738
741
if require_stacking:
739
742
format.require_stacking()
790
793
if cls is not BzrDir:
791
794
raise AssertionError("BzrDir.create always creates the "
792
"default format, not one of %r" % cls)
793
return controldir.ControlDir.create(base, format=format,
794
possible_transports=possible_transports)
795
"default format, not one of %r" % cls)
796
return controldir.ControlDir.create(
797
base, format=format, possible_transports=possible_transports)
796
799
def __repr__(self):
797
800
return "<%s at %r>" % (self.__class__.__name__, self.user_url)
857
860
:param branches: List of utf-8 branch names to write
859
self.transport.put_bytes('branch-list',
860
b"".join([name.encode('utf-8')+b"\n" for name in branches]))
862
self.transport.put_bytes(
864
b"".join([name.encode('utf-8') + b"\n" for name in branches]))
862
866
def __init__(self, _transport, _format):
863
867
super(BzrDirMeta1, self).__init__(_transport, _format)
872
876
def create_branch(self, name=None, repository=None,
873
append_revisions_only=None):
877
append_revisions_only=None):
874
878
"""See ControlDir.create_branch."""
876
880
name = self._get_selected_branch()
877
return self._format.get_branch_format().initialize(self, name=name,
878
repository=repository,
879
append_revisions_only=append_revisions_only)
881
return self._format.get_branch_format().initialize(
882
self, name=name, repository=repository,
883
append_revisions_only=append_revisions_only)
881
885
def destroy_branch(self, name=None):
882
886
"""See ControlDir.destroy_branch."""
898
902
self.transport.delete_tree(path)
899
903
except errors.NoSuchFile:
900
raise errors.NotBranchError(path=urlutils.join(self.transport.base,
901
path), controldir=self)
904
raise errors.NotBranchError(
905
path=urlutils.join(self.transport.base, path), controldir=self)
903
907
def create_repository(self, shared=False):
904
908
"""See BzrDir.create_repository."""
926
930
# We ignore the conflicts returned by wt.revert since we're about to
927
931
# delete the wt metadata anyway, all that should be left here are
928
932
# detritus. But see bug #634470 about subtree .bzr dirs.
929
conflicts = wt.revert(old_tree=empty)
933
wt.revert(old_tree=empty)
930
934
self.destroy_workingtree_metadata()
932
936
def destroy_workingtree_metadata(self):
943
947
def _get_mkdir_mode(self):
944
948
"""Figure out the mode to use when creating a bzrdir subdir."""
945
temp_control = lockable_files.LockableFiles(self.transport, '',
946
lockable_files.TransportLock)
949
temp_control = lockable_files.LockableFiles(
950
self.transport, '', lockable_files.TransportLock)
947
951
return temp_control._dir_mode
949
953
def get_branch_reference(self, name=None):
955
959
def set_branch_reference(self, target_branch, name=None):
956
960
format = _mod_bzrbranch.BranchReferenceFormat()
957
if (self.control_url == target_branch.controldir.control_url and
958
name == target_branch.name):
961
if (self.control_url == target_branch.controldir.control_url
962
and name == target_branch.name):
959
963
raise controldir.BranchReferenceLoop(target_branch)
960
964
return format.initialize(self, target_branch=target_branch, name=name)
974
978
raise errors.IncompatibleFormat(branch_format, self._format)
976
980
branches = self._read_branch_list()
977
if not name in branches:
981
if name not in branches:
978
982
self.control_files.lock_write()
980
984
branches = self._read_branch_list()
982
986
if dirname != u"" and dirname in branches:
983
987
raise errors.ParentBranchExists(name)
984
988
child_branches = [
985
b.startswith(name+u"/") for b in branches]
989
b.startswith(name + u"/") for b in branches]
986
990
if any(child_branches):
987
991
raise errors.AlreadyBranchError(name)
988
992
branches.append(name)
1055
1059
def needs_format_conversion(self, format):
1056
1060
"""See BzrDir.needs_format_conversion()."""
1057
if (not isinstance(self._format, format.__class__) or
1058
self._format.get_format_string() != format.get_format_string()):
1061
if (not isinstance(self._format, format.__class__)
1062
or self._format.get_format_string() != format.get_format_string()):
1059
1063
# it is not a meta dir format, conversion is needed.
1061
1065
# we might want to push this down to the repository?
1089
1093
format = self.find_branch_format(name=name)
1090
1094
format.check_support_status(unsupported)
1091
1095
return format.open(self, name=name,
1092
_found=True, ignore_fallbacks=ignore_fallbacks,
1093
possible_transports=possible_transports)
1096
_found=True, ignore_fallbacks=ignore_fallbacks,
1097
possible_transports=possible_transports)
1095
1099
def open_repository(self, unsupported=False):
1096
1100
"""See BzrDir.open_repository."""
1100
1104
return format.open(self, _found=True)
1102
1106
def open_workingtree(self, unsupported=False,
1103
recommend_upgrade=True):
1107
recommend_upgrade=True):
1104
1108
"""See BzrDir.open_workingtree."""
1105
1109
from .workingtree import WorkingTreeFormatMetaDir
1106
1110
format = WorkingTreeFormatMetaDir.find_format(self)
1107
1111
format.check_support_status(unsupported, recommend_upgrade,
1108
basedir=self.root_transport.base)
1112
basedir=self.root_transport.base)
1109
1113
return format.open(self, _found=True)
1111
1115
def _get_config(self):
1157
1161
cls._present_features.remove(name)
1159
1163
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1161
1165
for name, necessity in viewitems(self.features):
1162
1166
if name in self._present_features:
1180
1184
def from_string(cls, text):
1181
1185
format_string = cls.get_format_string()
1182
1186
if not text.startswith(format_string):
1183
raise AssertionError("Invalid format header %r for %r" % (text, cls))
1187
raise AssertionError(
1188
"Invalid format header %r for %r" % (text, cls))
1184
1189
lines = text[len(format_string):].splitlines()
1186
1191
for lineno, line in enumerate(lines):
1188
1193
(necessity, feature) = line.split(b" ", 1)
1189
1194
except ValueError:
1190
raise errors.ParseFormatError(format=cls, lineno=lineno+2,
1191
line=line, text=text)
1195
raise errors.ParseFormatError(format=cls, lineno=lineno + 2,
1196
line=line, text=text)
1192
1197
ret.features[feature] = necessity
1204
1209
def _find_format(klass, registry, kind, format_string):
1206
first_line = format_string[:format_string.index(b"\n")+1]
1211
first_line = format_string[:format_string.index(b"\n") + 1]
1207
1212
except ValueError:
1208
1213
first_line = format_string
1220
1225
return self.as_string()
1222
1227
def __eq__(self, other):
1223
return (self.__class__ is other.__class__ and
1224
self.features == other.features)
1228
return (self.__class__ is other.__class__
1229
and self.features == other.features)
1226
1231
def _update_feature_flags(self, updated_flags):
1227
1232
"""Update the feature flags in this format.
1275
1280
return remote_format.initialize_on_transport(transport)
1277
1282
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
1278
create_prefix=False, force_new_repo=False, stacked_on=None,
1279
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1280
shared_repo=False, vfs_only=False):
1283
create_prefix=False, force_new_repo=False, stacked_on=None,
1284
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
1285
shared_repo=False, vfs_only=False):
1281
1286
"""Create this format on transport.
1283
1288
The directory to initialize will be created.
1307
1312
parameter and any stacking policy found for the target.
1309
1314
if not vfs_only:
1310
# Try to hand off to a smart server
1315
# Try to hand off to a smart server
1312
1317
client_medium = transport.get_smart_medium()
1313
1318
except errors.NoSmartMedium:
1319
1324
remote_dir_format._network_name = self.network_name()
1320
1325
self._supply_sub_formats_to(remote_dir_format)
1321
1326
return remote_dir_format.initialize_on_transport_ex(transport,
1322
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1323
force_new_repo=force_new_repo, stacked_on=stacked_on,
1324
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1325
make_working_trees=make_working_trees, shared_repo=shared_repo)
1327
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
1328
force_new_repo=force_new_repo, stacked_on=stacked_on,
1329
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
1330
make_working_trees=make_working_trees, shared_repo=shared_repo)
1326
1331
# XXX: Refactor the create_prefix/no_create_prefix code into a
1327
1332
# common helper function
1328
1333
# The destination may not exist - if so make it according to policy.
1329
1335
def make_directory(transport):
1330
1336
transport.mkdir('.')
1331
1337
return transport
1332
1339
def redirected(transport, e, redirection_notice):
1333
1340
note(redirection_notice)
1334
1341
return transport._redirected_to(e.source, e.target)
1336
1343
transport = do_catching_redirections(make_directory, transport,
1338
1345
except errors.FileExists:
1339
1346
if not use_existing_dir:
1381
1388
# Since we are creating a .bzr directory, inherit the
1382
1389
# mode from the root directory
1383
1390
temp_control = lockable_files.LockableFiles(transport,
1384
'', lockable_files.TransportLock)
1391
'', lockable_files.TransportLock)
1386
1393
temp_control._transport.mkdir('.bzr',
1387
# FIXME: RBC 20060121 don't peek under
1389
mode=temp_control._dir_mode)
1394
# FIXME: RBC 20060121 don't peek under
1396
mode=temp_control._dir_mode)
1390
1397
except errors.FileExists:
1391
1398
raise errors.AlreadyControlDirError(transport.base)
1392
1399
if sys.platform == 'win32' and isinstance(transport, local.LocalTransport):
1403
1410
# NB: no need to escape relative paths that are url safe.
1404
1411
control_files = lockable_files.LockableFiles(bzrdir_transport,
1405
self._lock_file_name, self._lock_class)
1412
self._lock_file_name, self._lock_class)
1406
1413
control_files.create_lock()
1407
1414
control_files.lock_write()
1409
1416
for (filename, content) in utf8_files:
1410
1417
bzrdir_transport.put_bytes(filename, content,
1413
1420
control_files.unlock()
1414
1421
return self.open(transport, _found=True)
1422
1429
found_format = controldir.ControlDirFormat.find_format(transport)
1423
1430
if not isinstance(found_format, self.__class__):
1424
1431
raise AssertionError("%s was asked to open %s, but it seems to need "
1426
% (self, transport, found_format))
1433
% (self, transport, found_format))
1427
1434
# Allow subclasses - use the found format.
1428
1435
self._supply_sub_formats_to(found_format)
1429
1436
return found_format._open(transport)
1457
1464
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
1459
1466
controldir.ControlDirFormat.check_support_status(self,
1460
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
1467
allow_unsupported=allow_unsupported, recommend_upgrade=recommend_upgrade,
1462
1469
BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
1463
recommend_upgrade=recommend_upgrade, basedir=basedir)
1470
recommend_upgrade=recommend_upgrade, basedir=basedir)
1466
1473
class BzrDirMetaFormat1(BzrDirFormat):
1512
1519
self._branch_format = format
1514
1521
def require_stacking(self, stack_on=None, possible_transports=None,
1516
1523
"""We have a request to stack, try to ensure the formats support it.
1518
1525
:param stack_on: If supplied, it is the URL to a branch that we want to
1528
1535
# a bit of state for get_target_branch so that we don't try to open it
1529
1536
# 2 times, for both repo *and* branch
1530
target = [None, False, None] # target_branch, checked, upgrade anyway
1537
target = [None, False, None] # target_branch, checked, upgrade anyway
1531
1539
def get_target_branch():
1533
1541
# We've checked, don't check again
1540
1548
target_dir = BzrDir.open(stack_on,
1541
possible_transports=possible_transports)
1549
possible_transports=possible_transports)
1542
1550
except errors.NotBranchError:
1543
1551
# Nothing there, don't change formats
1544
1552
target[:] = [None, True, False]
1556
1564
target[:] = [target_branch, True, False]
1559
if (not _skip_repo and
1560
not self.repository_format.supports_external_lookups):
1568
and not self.repository_format.supports_external_lookups):
1561
1569
# We need to upgrade the Repository.
1562
1570
target_branch, _, do_upgrade = get_target_branch()
1563
1571
if target_branch is None:
1581
1589
if new_repo_format is not None:
1582
1590
self.repository_format = new_repo_format
1583
1591
note(gettext('Source repository format does not support stacking,'
1584
' using format:\n %s'),
1592
' using format:\n %s'),
1585
1593
new_repo_format.get_format_description())
1587
1595
if not self.get_branch_format().supports_stacking():
1601
1609
# Does support stacking, use its format.
1602
1610
self.set_branch_format(new_branch_format)
1603
1611
note(gettext('Source branch format does not support stacking,'
1604
' using format:\n %s'),
1612
' using format:\n %s'),
1605
1613
new_branch_format.get_format_description())
1607
1615
def get_converter(self, format=None):
1608
1616
"""See BzrDirFormat.get_converter()."""
1609
1617
if format is None:
1610
1618
format = BzrDirFormat.get_default_format()
1611
if (isinstance(self, BzrDirMetaFormat1) and
1612
isinstance(format, BzrDirMetaFormat1Colo)):
1619
if (isinstance(self, BzrDirMetaFormat1)
1620
and isinstance(format, BzrDirMetaFormat1Colo)):
1613
1621
return ConvertMetaToColo(format)
1614
if (isinstance(self, BzrDirMetaFormat1Colo) and
1615
isinstance(format, BzrDirMetaFormat1)):
1622
if (isinstance(self, BzrDirMetaFormat1Colo)
1623
and isinstance(format, BzrDirMetaFormat1)):
1616
1624
return ConvertMetaToColo(format)
1617
1625
if not isinstance(self, format.__class__):
1618
1626
# converting away from metadir is not implemented
1649
1657
self._repository_format = value
1651
1659
repository_format = property(__return_repository_format,
1652
_set_repository_format)
1660
_set_repository_format)
1654
1662
def _supply_sub_formats_to(self, other_format):
1655
1663
"""Give other_format the same values for sub formats as this has.
1740
1748
ui.ui_factory.note(gettext('starting repository conversion'))
1741
1749
if not repo_fmt.supports_overriding_transport:
1742
1750
raise AssertionError(
1743
"Repository in metadir does not support "
1744
"overriding transport")
1751
"Repository in metadir does not support "
1752
"overriding transport")
1745
1753
converter = CopyConverter(self.target_format.repository_format)
1746
1754
converter.convert(repo, pb)
1747
1755
for branch in self.controldir.list_branches():
1751
1759
old = branch._format.__class__
1752
1760
new = self.target_format.get_branch_format().__class__
1753
1761
while old != new:
1754
if (old == fullhistorybranch.BzrBranchFormat5 and
1755
new in (_mod_bzrbranch.BzrBranchFormat6,
1756
_mod_bzrbranch.BzrBranchFormat7,
1757
_mod_bzrbranch.BzrBranchFormat8)):
1762
if (old == fullhistorybranch.BzrBranchFormat5
1763
and new in (_mod_bzrbranch.BzrBranchFormat6,
1764
_mod_bzrbranch.BzrBranchFormat7,
1765
_mod_bzrbranch.BzrBranchFormat8)):
1758
1766
branch_converter = _mod_bzrbranch.Converter5to6()
1759
elif (old == _mod_bzrbranch.BzrBranchFormat6 and
1760
new in (_mod_bzrbranch.BzrBranchFormat7,
1761
_mod_bzrbranch.BzrBranchFormat8)):
1767
elif (old == _mod_bzrbranch.BzrBranchFormat6
1768
and new in (_mod_bzrbranch.BzrBranchFormat7,
1769
_mod_bzrbranch.BzrBranchFormat8)):
1762
1770
branch_converter = _mod_bzrbranch.Converter6to7()
1763
elif (old == _mod_bzrbranch.BzrBranchFormat7 and
1764
new is _mod_bzrbranch.BzrBranchFormat8):
1771
elif (old == _mod_bzrbranch.BzrBranchFormat7
1772
and new is _mod_bzrbranch.BzrBranchFormat8):
1765
1773
branch_converter = _mod_bzrbranch.Converter7to8()
1767
1775
raise errors.BadConversionTarget("No converter", new,
1769
1777
branch_converter.convert(branch)
1770
1778
branch = self.controldir.open_branch()
1771
1779
old = branch._format.__class__
1777
1785
# TODO: conversions of Branch and Tree should be done by
1778
1786
# InterXFormat lookups
1779
if (isinstance(tree, workingtree_3.WorkingTree3) and
1780
not isinstance(tree, workingtree_4.DirStateWorkingTree) and
1781
isinstance(self.target_format.workingtree_format,
1782
workingtree_4.DirStateWorkingTreeFormat)):
1787
if (isinstance(tree, workingtree_3.WorkingTree3)
1788
and not isinstance(tree, workingtree_4.DirStateWorkingTree)
1789
and isinstance(self.target_format.workingtree_format,
1790
workingtree_4.DirStateWorkingTreeFormat)):
1783
1791
workingtree_4.Converter3to4().convert(tree)
1784
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
1785
not isinstance(tree, workingtree_4.WorkingTree5) and
1786
isinstance(self.target_format.workingtree_format,
1787
workingtree_4.WorkingTreeFormat5)):
1792
if (isinstance(tree, workingtree_4.DirStateWorkingTree)
1793
and not isinstance(tree, workingtree_4.WorkingTree5)
1794
and isinstance(self.target_format.workingtree_format,
1795
workingtree_4.WorkingTreeFormat5)):
1788
1796
workingtree_4.Converter4to5().convert(tree)
1789
if (isinstance(tree, workingtree_4.DirStateWorkingTree) and
1790
not isinstance(tree, workingtree_4.WorkingTree6) and
1791
isinstance(self.target_format.workingtree_format,
1792
workingtree_4.WorkingTreeFormat6)):
1797
if (isinstance(tree, workingtree_4.DirStateWorkingTree)
1798
and not isinstance(tree, workingtree_4.WorkingTree6)
1799
and isinstance(self.target_format.workingtree_format,
1800
workingtree_4.WorkingTreeFormat6)):
1793
1801
workingtree_4.Converter4or5to6().convert(tree)
1794
1802
self.pb.finished()
1795
1803
return to_convert
1808
1816
def convert(self, to_convert, pb):
1809
1817
"""See Converter.convert()."""
1810
1818
to_convert.transport.put_bytes('branch-format',
1811
self.target_format.as_string())
1819
self.target_format.as_string())
1812
1820
return BzrDir.open_from_transport(to_convert.root_transport)
1826
1834
def convert(self, to_convert, pb):
1827
1835
"""See Converter.convert()."""
1828
1836
to_convert.transport.put_bytes('branch-format',
1829
self.target_format.as_string())
1837
self.target_format.as_string())
1830
1838
return BzrDir.open_from_transport(to_convert.root_transport)
1845
1853
super(CreateRepository, self).__init__(
1846
stack_on, stack_on_pwd, require_stacking)
1854
stack_on, stack_on_pwd, require_stacking)
1847
1855
self._controldir = controldir
1849
1857
def acquire_repository(self, make_working_trees=None, shared=False,
1850
possible_transports=None):
1858
possible_transports=None):
1851
1859
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
1853
1861
Creates the desired repository in the controldir we already have.
1889
1897
super(UseExistingRepository, self).__init__(
1890
stack_on, stack_on_pwd, require_stacking)
1898
stack_on, stack_on_pwd, require_stacking)
1891
1899
self._repository = repository
1893
1901
def acquire_repository(self, make_working_trees=None, shared=False,
1894
possible_transports=None):
1902
possible_transports=None):
1895
1903
"""Implementation of RepositoryAcquisitionPolicy.acquire_repository
1897
1905
Returns an existing repository to use.
1902
1910
possible_transports = list(possible_transports)
1903
1911
possible_transports.append(self._repository.controldir.transport)
1904
1912
self._add_fallback(self._repository,
1905
possible_transports=possible_transports)
1913
possible_transports=possible_transports)
1906
1914
return self._repository, False