207
206
raise errors.NoColocatedBranchSupport(self)
209
def get_branch_transport(self, branch_format, name=None):
210
"""Get the transport for use by branch format in this ControlDir.
212
Note that bzr dirs that do not support format strings will raise
213
IncompatibleFormat if the branch format they are given has
214
a format string, and vice versa.
216
If branch_format is None, the transport is returned with no
217
checking. If it is not None, then the returned transport is
218
guaranteed to point to an existing directory ready for use.
220
raise NotImplementedError(self.get_branch_transport)
222
def get_repository_transport(self, repository_format):
223
"""Get the transport for use by repository format in this ControlDir.
225
Note that bzr dirs that do not support format strings will raise
226
IncompatibleFormat if the repository format they are given has
227
a format string, and vice versa.
229
If repository_format is None, the transport is returned with no
230
checking. If it is not None, then the returned transport is
231
guaranteed to point to an existing directory ready for use.
233
raise NotImplementedError(self.get_repository_transport)
235
def get_workingtree_transport(self, tree_format):
236
"""Get the transport for use by workingtree format in this ControlDir.
238
Note that bzr dirs that do not support format strings will raise
239
IncompatibleFormat if the workingtree format they are given has a
240
format string, and vice versa.
242
If workingtree_format is None, the transport is returned with no
243
checking. If it is not None, then the returned transport is
244
guaranteed to point to an existing directory ready for use.
246
raise NotImplementedError(self.get_workingtree_transport)
210
248
def open_branch(self, name=None, unsupported=False,
211
249
ignore_fallbacks=False):
212
250
"""Open the branch object at this ControlDir if one is present.
327
365
:param create_tree_if_local: If true, a working-tree will be created
328
366
when working locally.
330
raise NotImplementedError(self.sprout)
368
operation = cleanup.OperationWithCleanups(self._sprout)
369
return operation.run(url, revision_id=revision_id,
370
force_new_repo=force_new_repo, recurse=recurse,
371
possible_transports=possible_transports,
372
accelerator_tree=accelerator_tree, hardlink=hardlink,
373
stacked=stacked, source_branch=source_branch,
374
create_tree_if_local=create_tree_if_local)
376
def _sprout(self, op, url, revision_id=None, force_new_repo=False,
377
recurse='down', possible_transports=None,
378
accelerator_tree=None, hardlink=False, stacked=False,
379
source_branch=None, create_tree_if_local=True):
380
add_cleanup = op.add_cleanup
381
target_transport = get_transport(url, possible_transports)
382
target_transport.ensure_base()
383
cloning_format = self.cloning_metadir(stacked)
384
# Create/update the result branch
385
result = cloning_format.initialize_on_transport(target_transport)
386
# if a stacked branch wasn't requested, we don't create one
387
# even if the origin was stacked
388
stacked_branch_url = None
389
if source_branch is not None:
390
add_cleanup(source_branch.lock_read().unlock)
392
stacked_branch_url = self.root_transport.base
393
source_repository = source_branch.repository
396
source_branch = self.open_branch()
397
source_repository = source_branch.repository
399
stacked_branch_url = self.root_transport.base
400
except errors.NotBranchError:
403
source_repository = self.open_repository()
404
except errors.NoRepositoryPresent:
405
source_repository = None
407
add_cleanup(source_repository.lock_read().unlock)
409
add_cleanup(source_branch.lock_read().unlock)
410
repository_policy = result.determine_repository_policy(
411
force_new_repo, stacked_branch_url, require_stacking=stacked)
412
result_repo, is_new_repo = repository_policy.acquire_repository()
413
add_cleanup(result_repo.lock_write().unlock)
414
is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
415
if is_new_repo and revision_id is not None and not is_stacked:
416
fetch_spec = graph.PendingAncestryResult(
417
[revision_id], source_repository)
420
if source_repository is not None:
421
# Fetch while stacked to prevent unstacked fetch from
423
if fetch_spec is None:
424
result_repo.fetch(source_repository, revision_id=revision_id)
426
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
428
if source_branch is None:
429
# this is for sprouting a controldir without a branch; is that
431
# Not especially, but it's part of the contract.
432
result_branch = result.create_branch()
434
result_branch = source_branch.sprout(result,
435
revision_id=revision_id, repository_policy=repository_policy,
436
repository=result_repo)
437
mutter("created new branch %r" % (result_branch,))
439
# Create/update the result working tree
440
if (create_tree_if_local and
441
isinstance(target_transport, local.LocalTransport) and
442
(result_repo is None or result_repo.make_working_trees())):
443
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
444
hardlink=hardlink, from_branch=result_branch)
447
if wt.path2id('') is None:
449
wt.set_root_id(self.open_workingtree.get_root_id())
450
except errors.NoWorkingTree:
456
if recurse == 'down':
458
basis = wt.basis_tree()
460
subtrees = basis.iter_references()
461
elif result_branch is not None:
462
basis = result_branch.basis_tree()
464
subtrees = basis.iter_references()
465
elif source_branch is not None:
466
basis = source_branch.basis_tree()
468
subtrees = basis.iter_references()
473
for path, file_id in subtrees:
474
target = urlutils.join(url, urlutils.escape(path))
475
sublocation = source_branch.reference_parent(file_id, path)
476
sublocation.bzrdir.sprout(target,
477
basis.get_reference_revision(file_id, path),
478
force_new_repo=force_new_repo, recurse=recurse,
481
if basis is not None:
332
485
def push_branch(self, source, revision_id=None, overwrite=False,
333
486
remember=False, create_prefix=False):
436
585
:param preserve_stacking: When cloning a stacked branch, stack the
437
586
new branch on top of the other branch's stacked-on branch.
439
return self.clone_on_transport(_mod_transport.get_transport(url),
588
return self.clone_on_transport(get_transport(url),
440
589
revision_id=revision_id,
441
590
force_new_repo=force_new_repo,
442
591
preserve_stacking=preserve_stacking)
444
593
def clone_on_transport(self, transport, revision_id=None,
445
594
force_new_repo=False, preserve_stacking=False, stacked_on=None,
446
create_prefix=False, use_existing_dir=True, no_tree=False):
595
create_prefix=False, use_existing_dir=True):
447
596
"""Clone this bzrdir and its contents to transport verbatim.
449
598
:param transport: The transport for the location to produce the clone
458
607
:param create_prefix: Create any missing directories leading up to
460
609
:param use_existing_dir: Use an existing directory if one exists.
461
:param no_tree: If set to true prevents creation of a working tree.
463
611
raise NotImplementedError(self.clone_on_transport)
466
class ControlComponentFormat(object):
467
"""A component that can live inside of a .bzr meta directory."""
469
upgrade_recommended = False
471
def get_format_string(self):
472
"""Return the format of this format, if usable in meta directories."""
473
raise NotImplementedError(self.get_format_string)
475
def get_format_description(self):
476
"""Return the short description for this format."""
477
raise NotImplementedError(self.get_format_description)
479
def is_supported(self):
480
"""Is this format supported?
482
Supported formats must be initializable and openable.
483
Unsupported formats may not support initialization or committing or
484
some other features depending on the reason for not being supported.
488
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
490
"""Give an error or warning on old formats.
492
:param allow_unsupported: If true, allow opening
493
formats that are strongly deprecated, and which may
494
have limited functionality.
496
:param recommend_upgrade: If true (default), warn
497
the user through the ui object that they may wish
498
to upgrade the object.
500
if not allow_unsupported and not self.is_supported():
501
# see open_downlevel to open legacy branches.
502
raise errors.UnsupportedFormatError(format=self)
503
if recommend_upgrade and self.upgrade_recommended:
504
ui.ui_factory.recommend_upgrade(
505
self.get_format_description(), basedir)
508
class ControlComponentFormatRegistry(registry.FormatRegistry):
509
"""A registry for control components (branch, workingtree, repository)."""
511
def __init__(self, other_registry=None):
512
super(ControlComponentFormatRegistry, self).__init__(other_registry)
513
self._extra_formats = []
515
def register(self, format):
516
"""Register a new format."""
517
super(ControlComponentFormatRegistry, self).register(
518
format.get_format_string(), format)
520
def remove(self, format):
521
"""Remove a registered format."""
522
super(ControlComponentFormatRegistry, self).remove(
523
format.get_format_string())
525
def register_extra(self, format):
526
"""Register a format that can not be used in a metadir.
528
This is mainly useful to allow custom repository formats, such as older
529
Bazaar formats and foreign formats, to be tested.
531
self._extra_formats.append(registry._ObjectGetter(format))
533
def remove_extra(self, format):
534
"""Remove an extra format.
536
self._extra_formats.remove(registry._ObjectGetter(format))
538
def register_extra_lazy(self, module_name, member_name):
539
"""Register a format lazily.
541
self._extra_formats.append(
542
registry._LazyObjectGetter(module_name, member_name))
544
def _get_extra(self):
545
"""Return all "extra" formats, not usable in meta directories."""
547
for getter in self._extra_formats:
555
"""Return all formats, even those not usable in metadirs.
558
for name in self.keys():
563
return result + self._get_extra()
565
def _get_all_modules(self):
566
"""Return a set of the modules providing objects."""
568
for name in self.keys():
569
modules.add(self._get_module(name))
570
for getter in self._extra_formats:
571
modules.add(getter.get_module())
575
class Converter(object):
576
"""Converts a disk format object from one format to another."""
578
def convert(self, to_convert, pb):
579
"""Perform the conversion of to_convert, giving feedback via pb.
581
:param to_convert: The disk object to convert.
582
:param pb: a progress bar to use for progress information.
585
def step(self, message):
586
"""Update the pb by a step."""
588
self.pb.update(message, self.count, self.total)
591
614
class ControlDirFormat(object):
592
615
"""An encapsulation of the initialization and open routines for a format.
669
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
671
"""Give an error or warning on old formats.
673
:param allow_unsupported: If true, allow opening
674
formats that are strongly deprecated, and which may
675
have limited functionality.
677
:param recommend_upgrade: If true (default), warn
678
the user through the ui object that they may wish
679
to upgrade the object.
681
if not allow_unsupported and not self.is_supported():
682
# see open_downlevel to open legacy branches.
683
raise errors.UnsupportedFormatError(format=self)
684
if recommend_upgrade and self.upgrade_recommended:
685
ui.ui_factory.recommend_upgrade(
686
self.get_format_description(), basedir)
688
689
def same_model(self, target_format):
689
690
return (self.repository_format.rich_root_data ==
690
691
target_format.rich_root_data)