140
135
raise NotImplementedError(self.needs_format_conversion)
137
def create_repository(self, shared=False):
138
"""Create a new repository in this control directory.
140
:param shared: If a shared repository should be created
141
:return: The newly created repository
143
raise NotImplementedError(self.create_repository)
142
145
def destroy_repository(self):
143
146
"""Destroy the repository in this ControlDir."""
144
147
raise NotImplementedError(self.destroy_repository)
146
def create_branch(self, name=None):
149
def create_branch(self, name=None, repository=None,
150
append_revisions_only=None):
147
151
"""Create a branch in this ControlDir.
149
153
:param name: Name of the colocated branch to create, None for
150
154
the default branch.
155
:param append_revisions_only: Whether this branch should only allow
156
appending new revisions to its history.
152
158
The controldirs format will control what branch format is created.
153
159
For more control see BranchFormatXX.create(a_controldir).
205
218
raise errors.NoColocatedBranchSupport(self)
208
def get_branch_transport(self, branch_format, name=None):
209
"""Get the transport for use by branch format in this ControlDir.
211
Note that bzr dirs that do not support format strings will raise
212
IncompatibleFormat if the branch format they are given has
213
a format string, and vice versa.
215
If branch_format is None, the transport is returned with no
216
checking. If it is not None, then the returned transport is
217
guaranteed to point to an existing directory ready for use.
219
raise NotImplementedError(self.get_branch_transport)
221
def get_repository_transport(self, repository_format):
222
"""Get the transport for use by repository format in this ControlDir.
224
Note that bzr dirs that do not support format strings will raise
225
IncompatibleFormat if the repository format they are given has
226
a format string, and vice versa.
228
If repository_format is None, the transport is returned with no
229
checking. If it is not None, then the returned transport is
230
guaranteed to point to an existing directory ready for use.
232
raise NotImplementedError(self.get_repository_transport)
234
def get_workingtree_transport(self, tree_format):
235
"""Get the transport for use by workingtree format in this ControlDir.
237
Note that bzr dirs that do not support format strings will raise
238
IncompatibleFormat if the workingtree format they are given has a
239
format string, and vice versa.
241
If workingtree_format is None, the transport is returned with no
242
checking. If it is not None, then the returned transport is
243
guaranteed to point to an existing directory ready for use.
245
raise NotImplementedError(self.get_workingtree_transport)
247
221
def open_branch(self, name=None, unsupported=False,
248
222
ignore_fallbacks=False):
249
223
"""Open the branch object at this ControlDir if one is present.
364
349
:param create_tree_if_local: If true, a working-tree will be created
365
350
when working locally.
367
target_transport = get_transport(url, possible_transports)
368
target_transport.ensure_base()
369
cloning_format = self.cloning_metadir(stacked)
370
# Create/update the result branch
371
result = cloning_format.initialize_on_transport(target_transport)
372
# if a stacked branch wasn't requested, we don't create one
373
# even if the origin was stacked
374
stacked_branch_url = None
375
if source_branch is not None:
377
stacked_branch_url = self.root_transport.base
378
source_repository = source_branch.repository
381
source_branch = self.open_branch()
382
source_repository = source_branch.repository
384
stacked_branch_url = self.root_transport.base
385
except errors.NotBranchError:
388
source_repository = self.open_repository()
389
except errors.NoRepositoryPresent:
390
source_repository = None
391
repository_policy = result.determine_repository_policy(
392
force_new_repo, stacked_branch_url, require_stacking=stacked)
393
result_repo, is_new_repo = repository_policy.acquire_repository()
394
is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
395
if is_new_repo and revision_id is not None and not is_stacked:
396
fetch_spec = graph.PendingAncestryResult(
397
[revision_id], source_repository)
400
if source_repository is not None:
401
# Fetch while stacked to prevent unstacked fetch from
403
if fetch_spec is None:
404
result_repo.fetch(source_repository, revision_id=revision_id)
406
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
408
if source_branch is None:
409
# this is for sprouting a controldir without a branch; is that
411
# Not especially, but it's part of the contract.
412
result_branch = result.create_branch()
414
result_branch = source_branch.sprout(result,
415
revision_id=revision_id, repository_policy=repository_policy)
416
mutter("created new branch %r" % (result_branch,))
418
# Create/update the result working tree
419
if (create_tree_if_local and
420
isinstance(target_transport, local.LocalTransport) and
421
(result_repo is None or result_repo.make_working_trees())):
422
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
426
if wt.path2id('') is None:
428
wt.set_root_id(self.open_workingtree.get_root_id())
429
except errors.NoWorkingTree:
435
if recurse == 'down':
437
basis = wt.basis_tree()
439
subtrees = basis.iter_references()
440
elif result_branch is not None:
441
basis = result_branch.basis_tree()
443
subtrees = basis.iter_references()
444
elif source_branch is not None:
445
basis = source_branch.basis_tree()
447
subtrees = basis.iter_references()
452
for path, file_id in subtrees:
453
target = urlutils.join(url, urlutils.escape(path))
454
sublocation = source_branch.reference_parent(file_id, path)
455
sublocation.bzrdir.sprout(target,
456
basis.get_reference_revision(file_id, path),
457
force_new_repo=force_new_repo, recurse=recurse,
460
if basis is not None:
352
raise NotImplementedError(self.sprout)
464
354
def push_branch(self, source, revision_id=None, overwrite=False,
465
355
remember=False, create_prefix=False):
564
458
:param preserve_stacking: When cloning a stacked branch, stack the
565
459
new branch on top of the other branch's stacked-on branch.
567
return self.clone_on_transport(get_transport(url),
461
return self.clone_on_transport(_mod_transport.get_transport(url),
568
462
revision_id=revision_id,
569
463
force_new_repo=force_new_repo,
570
464
preserve_stacking=preserve_stacking)
572
466
def clone_on_transport(self, transport, revision_id=None,
573
467
force_new_repo=False, preserve_stacking=False, stacked_on=None,
574
create_prefix=False, use_existing_dir=True):
468
create_prefix=False, use_existing_dir=True, no_tree=False):
575
469
"""Clone this bzrdir and its contents to transport verbatim.
577
471
:param transport: The transport for the location to produce the clone
586
480
:param create_prefix: Create any missing directories leading up to
588
482
:param use_existing_dir: Use an existing directory if one exists.
483
:param no_tree: If set to true prevents creation of a working tree.
590
485
raise NotImplementedError(self.clone_on_transport)
488
class ControlComponentFormat(object):
489
"""A component that can live inside of a .bzr meta directory."""
491
upgrade_recommended = False
493
def get_format_string(self):
494
"""Return the format of this format, if usable in meta directories."""
495
raise NotImplementedError(self.get_format_string)
497
def get_format_description(self):
498
"""Return the short description for this format."""
499
raise NotImplementedError(self.get_format_description)
501
def is_supported(self):
502
"""Is this format supported?
504
Supported formats must be initializable and openable.
505
Unsupported formats may not support initialization or committing or
506
some other features depending on the reason for not being supported.
510
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
512
"""Give an error or warning on old formats.
514
:param allow_unsupported: If true, allow opening
515
formats that are strongly deprecated, and which may
516
have limited functionality.
518
:param recommend_upgrade: If true (default), warn
519
the user through the ui object that they may wish
520
to upgrade the object.
522
if not allow_unsupported and not self.is_supported():
523
# see open_downlevel to open legacy branches.
524
raise errors.UnsupportedFormatError(format=self)
525
if recommend_upgrade and self.upgrade_recommended:
526
ui.ui_factory.recommend_upgrade(
527
self.get_format_description(), basedir)
530
class ControlComponentFormatRegistry(registry.FormatRegistry):
531
"""A registry for control components (branch, workingtree, repository)."""
533
def __init__(self, other_registry=None):
534
super(ControlComponentFormatRegistry, self).__init__(other_registry)
535
self._extra_formats = []
537
def register(self, format):
538
"""Register a new format."""
539
super(ControlComponentFormatRegistry, self).register(
540
format.get_format_string(), format)
542
def remove(self, format):
543
"""Remove a registered format."""
544
super(ControlComponentFormatRegistry, self).remove(
545
format.get_format_string())
547
def register_extra(self, format):
548
"""Register a format that can not be used in a metadir.
550
This is mainly useful to allow custom repository formats, such as older
551
Bazaar formats and foreign formats, to be tested.
553
self._extra_formats.append(registry._ObjectGetter(format))
555
def remove_extra(self, format):
556
"""Remove an extra format.
558
self._extra_formats.remove(registry._ObjectGetter(format))
560
def register_extra_lazy(self, module_name, member_name):
561
"""Register a format lazily.
563
self._extra_formats.append(
564
registry._LazyObjectGetter(module_name, member_name))
566
def _get_extra(self):
567
"""Return all "extra" formats, not usable in meta directories."""
569
for getter in self._extra_formats:
577
"""Return all formats, even those not usable in metadirs.
580
for name in self.keys():
585
return result + self._get_extra()
587
def _get_all_modules(self):
588
"""Return a set of the modules providing objects."""
590
for name in self.keys():
591
modules.add(self._get_module(name))
592
for getter in self._extra_formats:
593
modules.add(getter.get_module())
597
class Converter(object):
598
"""Converts a disk format object from one format to another."""
600
def convert(self, to_convert, pb):
601
"""Perform the conversion of to_convert, giving feedback via pb.
603
:param to_convert: The disk object to convert.
604
:param pb: a progress bar to use for progress information.
607
def step(self, message):
608
"""Update the pb by a step."""
610
self.pb.update(message, self.count, self.total)
593
613
class ControlDirFormat(object):
594
614
"""An encapsulation of the initialization and open routines for a format.
691
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
693
"""Give an error or warning on old formats.
695
:param allow_unsupported: If true, allow opening
696
formats that are strongly deprecated, and which may
697
have limited functionality.
699
:param recommend_upgrade: If true (default), warn
700
the user through the ui object that they may wish
701
to upgrade the object.
703
if not allow_unsupported and not self.is_supported():
704
# see open_downlevel to open legacy branches.
705
raise errors.UnsupportedFormatError(format=self)
706
if recommend_upgrade and self.upgrade_recommended:
707
ui.ui_factory.recommend_upgrade(
708
self.get_format_description(), basedir)
668
710
def same_model(self, target_format):
669
711
return (self.repository_format.rich_root_data ==
670
712
target_format.rich_root_data)
810
853
class Prober(object):
811
"""Abstract class that can be used to detect a particular kind of
854
"""Abstract class that can be used to detect a particular kind of
812
855
control directory.
814
At the moment this just contains a single method to probe a particular
815
transport, but it may be extended in the future to e.g. avoid
857
At the moment this just contains a single method to probe a particular
858
transport, but it may be extended in the future to e.g. avoid
816
859
multiple levels of probing for Subversion repositories.
861
See BzrProber and RemoteBzrProber in bzrlib.bzrdir for the
862
probers that detect .bzr/ directories and Bazaar smart servers,
865
Probers should be registered using the register_server_prober or
866
register_prober methods on ControlDirFormat.
819
869
def probe_transport(self, transport):