1
# Copyright (C) 2010, 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""ControlDir is the basic control directory class.
19
The ControlDir class is the base for the control directory used
20
by all bzr and foreign formats. For the ".bzr" implementation,
21
see bzrlib.bzrdir.BzrDir.
25
from bzrlib.lazy_import import lazy_import
26
lazy_import(globals(), """
31
revision as _mod_revision,
32
transport as _mod_transport,
36
from bzrlib.push import (
42
from bzrlib import registry
45
class ControlComponent(object):
46
"""Abstract base class for control directory components.
48
This provides interfaces that are common across controldirs,
49
repositories, branches, and workingtree control directories.
51
They all expose two urls and transports: the *user* URL is the
52
one that stops above the control directory (eg .bzr) and that
53
should normally be used in messages, and the *control* URL is
54
under that in eg .bzr/checkout and is used to read the control
57
This can be used as a mixin and is intended to fit with
62
def control_transport(self):
63
raise NotImplementedError
66
def control_url(self):
67
return self.control_transport.base
70
def user_transport(self):
71
raise NotImplementedError
75
return self.user_transport.base
78
class ControlDir(ControlComponent):
79
"""A control directory.
81
While this represents a generic control directory, there are a few
82
features that are present in this interface that are currently only
83
supported by one of its implementations, BzrDir.
85
These features (bound branches, stacked branches) are currently only
86
supported by Bazaar, but could be supported by other version control
87
systems as well. Implementations are required to raise the appropriate
88
exceptions when an operation is requested that is not supported.
90
This also makes life easier for API users who can rely on the
91
implementation always allowing a particular feature to be requested but
92
raising an exception when it is not supported, rather than requiring the
93
API users to check for magic attributes to see what features are supported.
96
def can_convert_format(self):
97
"""Return true if this controldir is one whose format we can convert
101
def list_branches(self):
102
"""Return a sequence of all branches local to this control directory.
106
return [self.open_branch()]
107
except (errors.NotBranchError, errors.NoRepositoryPresent):
110
def is_control_filename(self, filename):
111
"""True if filename is the name of a path which is reserved for
114
:param filename: A filename within the root transport of this
117
This is true IF and ONLY IF the filename is part of the namespace reserved
118
for bzr control dirs. Currently this is the '.bzr' directory in the root
119
of the root_transport. it is expected that plugins will need to extend
120
this in the future - for instance to make bzr talk with svn working
123
raise NotImplementedError(self.is_control_filename)
125
def needs_format_conversion(self, format=None):
126
"""Return true if this controldir needs convert_format run on it.
128
For instance, if the repository format is out of date but the
129
branch and working tree are not, this should return True.
131
:param format: Optional parameter indicating a specific desired
132
format we plan to arrive at.
134
raise NotImplementedError(self.needs_format_conversion)
136
def create_repository(self, shared=False):
137
"""Create a new repository in this control directory.
139
:param shared: If a shared repository should be created
140
:return: The newly created repository
142
raise NotImplementedError(self.create_repository)
144
def destroy_repository(self):
145
"""Destroy the repository in this ControlDir."""
146
raise NotImplementedError(self.destroy_repository)
148
def create_branch(self, name=None, repository=None,
149
append_revisions_only=None):
150
"""Create a branch in this ControlDir.
152
:param name: Name of the colocated branch to create, None for
154
:param append_revisions_only: Whether this branch should only allow
155
appending new revisions to its history.
157
The controldirs format will control what branch format is created.
158
For more control see BranchFormatXX.create(a_controldir).
160
raise NotImplementedError(self.create_branch)
162
def destroy_branch(self, name=None):
163
"""Destroy a branch in this ControlDir.
165
:param name: Name of the branch to destroy, None for the default
168
raise NotImplementedError(self.destroy_branch)
170
def create_workingtree(self, revision_id=None, from_branch=None,
171
accelerator_tree=None, hardlink=False):
172
"""Create a working tree at this ControlDir.
174
:param revision_id: create it as of this revision id.
175
:param from_branch: override controldir branch
176
(for lightweight checkouts)
177
:param accelerator_tree: A tree which can be used for retrieving file
178
contents more quickly than the revision tree, i.e. a workingtree.
179
The revision tree will be used for cases where accelerator_tree's
180
content is different.
182
raise NotImplementedError(self.create_workingtree)
184
def destroy_workingtree(self):
185
"""Destroy the working tree at this ControlDir.
187
Formats that do not support this may raise UnsupportedOperation.
189
raise NotImplementedError(self.destroy_workingtree)
191
def destroy_workingtree_metadata(self):
192
"""Destroy the control files for the working tree at this ControlDir.
194
The contents of working tree files are not affected.
195
Formats that do not support this may raise UnsupportedOperation.
197
raise NotImplementedError(self.destroy_workingtree_metadata)
199
def find_branch_format(self, name=None):
200
"""Find the branch 'format' for this bzrdir.
202
This might be a synthetic object for e.g. RemoteBranch and SVN.
204
raise NotImplementedError(self.find_branch_format)
206
def get_branch_reference(self, name=None):
207
"""Return the referenced URL for the branch in this controldir.
209
:param name: Optional colocated branch name
210
:raises NotBranchError: If there is no Branch.
211
:raises NoColocatedBranchSupport: If a branch name was specified
212
but colocated branches are not supported.
213
:return: The URL the branch in this controldir references if it is a
214
reference branch, or None for regular branches.
217
raise errors.NoColocatedBranchSupport(self)
220
def open_branch(self, name=None, unsupported=False,
221
ignore_fallbacks=False):
222
"""Open the branch object at this ControlDir if one is present.
224
If unsupported is True, then no longer supported branch formats can
227
TODO: static convenience version of this?
229
raise NotImplementedError(self.open_branch)
231
def open_repository(self, _unsupported=False):
232
"""Open the repository object at this ControlDir if one is present.
234
This will not follow the Branch object pointer - it's strictly a direct
235
open facility. Most client code should use open_branch().repository to
238
:param _unsupported: a private parameter, not part of the api.
240
TODO: static convenience version of this?
242
raise NotImplementedError(self.open_repository)
244
def find_repository(self):
245
"""Find the repository that should be used.
247
This does not require a branch as we use it to find the repo for
248
new branches as well as to hook existing branches up to their
251
raise NotImplementedError(self.find_repository)
253
def open_workingtree(self, _unsupported=False,
254
recommend_upgrade=True, from_branch=None):
255
"""Open the workingtree object at this ControlDir if one is present.
257
:param recommend_upgrade: Optional keyword parameter, when True (the
258
default), emit through the ui module a recommendation that the user
259
upgrade the working tree when the workingtree being opened is old
260
(but still fully supported).
261
:param from_branch: override controldir branch (for lightweight
264
raise NotImplementedError(self.open_workingtree)
266
def has_branch(self, name=None):
267
"""Tell if this controldir contains a branch.
269
Note: if you're going to open the branch, you should just go ahead
270
and try, and not ask permission first. (This method just opens the
271
branch and discards it, and that's somewhat expensive.)
274
self.open_branch(name)
276
except errors.NotBranchError:
279
def _get_selected_branch(self):
280
"""Return the name of the branch selected by the user.
282
:return: Name of the branch selected by the user, or None.
284
branch = self.root_transport.get_segment_parameters().get("branch")
285
if branch is not None:
286
branch = urlutils.unescape(branch)
289
def has_workingtree(self):
290
"""Tell if this controldir contains a working tree.
292
This will still raise an exception if the controldir has a workingtree
293
that is remote & inaccessible.
295
Note: if you're going to open the working tree, you should just go ahead
296
and try, and not ask permission first. (This method just opens the
297
workingtree and discards it, and that's somewhat expensive.)
300
self.open_workingtree(recommend_upgrade=False)
302
except errors.NoWorkingTree:
305
def cloning_metadir(self, require_stacking=False):
306
"""Produce a metadir suitable for cloning or sprouting with.
308
These operations may produce workingtrees (yes, even though they're
309
"cloning" something that doesn't have a tree), so a viable workingtree
310
format must be selected.
312
:require_stacking: If True, non-stackable formats will be upgraded
313
to similar stackable formats.
314
:returns: a ControlDirFormat with all component formats either set
315
appropriately or set to None if that component should not be
318
raise NotImplementedError(self.cloning_metadir)
320
def checkout_metadir(self):
321
"""Produce a metadir suitable for checkouts of this controldir."""
322
return self.cloning_metadir()
324
def sprout(self, url, revision_id=None, force_new_repo=False,
325
recurse='down', possible_transports=None,
326
accelerator_tree=None, hardlink=False, stacked=False,
327
source_branch=None, create_tree_if_local=True):
328
"""Create a copy of this controldir prepared for use as a new line of
331
If url's last component does not exist, it will be created.
333
Attributes related to the identity of the source branch like
334
branch nickname will be cleaned, a working tree is created
335
whether one existed before or not; and a local branch is always
338
:param revision_id: if revision_id is not None, then the clone
339
operation may tune itself to download less data.
340
:param accelerator_tree: A tree which can be used for retrieving file
341
contents more quickly than the revision tree, i.e. a workingtree.
342
The revision tree will be used for cases where accelerator_tree's
343
content is different.
344
:param hardlink: If true, hard-link files from accelerator_tree,
346
:param stacked: If true, create a stacked branch referring to the
347
location of this control directory.
348
:param create_tree_if_local: If true, a working-tree will be created
349
when working locally.
351
raise NotImplementedError(self.sprout)
353
def push_branch(self, source, revision_id=None, overwrite=False,
354
remember=False, create_prefix=False):
355
"""Push the source branch into this ControlDir."""
357
# If we can open a branch, use its direct repository, otherwise see
358
# if there is a repository without a branch.
360
br_to = self.open_branch()
361
except errors.NotBranchError:
362
# Didn't find a branch, can we find a repository?
363
repository_to = self.find_repository()
365
# Found a branch, so we must have found a repository
366
repository_to = br_to.repository
368
push_result = PushResult()
369
push_result.source_branch = source
371
# We have a repository but no branch, copy the revisions, and then
373
if revision_id is None:
374
# No revision supplied by the user, default to the branch
376
revision_id = source.last_revision()
377
repository_to.fetch(source.repository, revision_id=revision_id)
378
br_to = source.clone(self, revision_id=revision_id)
379
if source.get_push_location() is None or remember:
380
source.set_push_location(br_to.base)
381
push_result.stacked_on = None
382
push_result.branch_push_result = None
383
push_result.old_revno = None
384
push_result.old_revid = _mod_revision.NULL_REVISION
385
push_result.target_branch = br_to
386
push_result.master_branch = None
387
push_result.workingtree_updated = False
389
# We have successfully opened the branch, remember if necessary:
390
if source.get_push_location() is None or remember:
391
source.set_push_location(br_to.base)
393
tree_to = self.open_workingtree()
394
except errors.NotLocalUrl:
395
push_result.branch_push_result = source.push(br_to,
396
overwrite, stop_revision=revision_id)
397
push_result.workingtree_updated = False
398
except errors.NoWorkingTree:
399
push_result.branch_push_result = source.push(br_to,
400
overwrite, stop_revision=revision_id)
401
push_result.workingtree_updated = None # Not applicable
405
push_result.branch_push_result = source.push(
406
tree_to.branch, overwrite, stop_revision=revision_id)
410
push_result.workingtree_updated = True
411
push_result.old_revno = push_result.branch_push_result.old_revno
412
push_result.old_revid = push_result.branch_push_result.old_revid
413
push_result.target_branch = \
414
push_result.branch_push_result.target_branch
417
def _get_tree_branch(self, name=None):
418
"""Return the branch and tree, if any, for this bzrdir.
420
:param name: Name of colocated branch to open.
422
Return None for tree if not present or inaccessible.
423
Raise NotBranchError if no branch is present.
424
:return: (tree, branch)
427
tree = self.open_workingtree()
428
except (errors.NoWorkingTree, errors.NotLocalUrl):
430
branch = self.open_branch(name=name)
433
branch = self.open_branch(name=name)
438
def get_config(self):
439
"""Get configuration for this ControlDir."""
440
raise NotImplementedError(self.get_config)
442
def check_conversion_target(self, target_format):
443
"""Check that a bzrdir as a whole can be converted to a new format."""
444
raise NotImplementedError(self.check_conversion_target)
446
def clone(self, url, revision_id=None, force_new_repo=False,
447
preserve_stacking=False):
448
"""Clone this bzrdir and its contents to url verbatim.
450
:param url: The url create the clone at. If url's last component does
451
not exist, it will be created.
452
:param revision_id: The tip revision-id to use for any branch or
453
working tree. If not None, then the clone operation may tune
454
itself to download less data.
455
:param force_new_repo: Do not use a shared repository for the target
456
even if one is available.
457
:param preserve_stacking: When cloning a stacked branch, stack the
458
new branch on top of the other branch's stacked-on branch.
460
return self.clone_on_transport(_mod_transport.get_transport(url),
461
revision_id=revision_id,
462
force_new_repo=force_new_repo,
463
preserve_stacking=preserve_stacking)
465
def clone_on_transport(self, transport, revision_id=None,
466
force_new_repo=False, preserve_stacking=False, stacked_on=None,
467
create_prefix=False, use_existing_dir=True, no_tree=False):
468
"""Clone this bzrdir and its contents to transport verbatim.
470
:param transport: The transport for the location to produce the clone
471
at. If the target directory does not exist, it will be created.
472
:param revision_id: The tip revision-id to use for any branch or
473
working tree. If not None, then the clone operation may tune
474
itself to download less data.
475
:param force_new_repo: Do not use a shared repository for the target,
476
even if one is available.
477
:param preserve_stacking: When cloning a stacked branch, stack the
478
new branch on top of the other branch's stacked-on branch.
479
:param create_prefix: Create any missing directories leading up to
481
:param use_existing_dir: Use an existing directory if one exists.
482
:param no_tree: If set to true prevents creation of a working tree.
484
raise NotImplementedError(self.clone_on_transport)
487
class ControlComponentFormat(object):
488
"""A component that can live inside of a .bzr meta directory."""
490
upgrade_recommended = False
492
def get_format_string(self):
493
"""Return the format of this format, if usable in meta directories."""
494
raise NotImplementedError(self.get_format_string)
496
def get_format_description(self):
497
"""Return the short description for this format."""
498
raise NotImplementedError(self.get_format_description)
500
def is_supported(self):
501
"""Is this format supported?
503
Supported formats must be initializable and openable.
504
Unsupported formats may not support initialization or committing or
505
some other features depending on the reason for not being supported.
509
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
511
"""Give an error or warning on old formats.
513
:param allow_unsupported: If true, allow opening
514
formats that are strongly deprecated, and which may
515
have limited functionality.
517
:param recommend_upgrade: If true (default), warn
518
the user through the ui object that they may wish
519
to upgrade the object.
521
if not allow_unsupported and not self.is_supported():
522
# see open_downlevel to open legacy branches.
523
raise errors.UnsupportedFormatError(format=self)
524
if recommend_upgrade and self.upgrade_recommended:
525
ui.ui_factory.recommend_upgrade(
526
self.get_format_description(), basedir)
529
class ControlComponentFormatRegistry(registry.FormatRegistry):
530
"""A registry for control components (branch, workingtree, repository)."""
532
def __init__(self, other_registry=None):
533
super(ControlComponentFormatRegistry, self).__init__(other_registry)
534
self._extra_formats = []
536
def register(self, format):
537
"""Register a new format."""
538
super(ControlComponentFormatRegistry, self).register(
539
format.get_format_string(), format)
541
def remove(self, format):
542
"""Remove a registered format."""
543
super(ControlComponentFormatRegistry, self).remove(
544
format.get_format_string())
546
def register_extra(self, format):
547
"""Register a format that can not be used in a metadir.
549
This is mainly useful to allow custom repository formats, such as older
550
Bazaar formats and foreign formats, to be tested.
552
self._extra_formats.append(registry._ObjectGetter(format))
554
def remove_extra(self, format):
555
"""Remove an extra format.
557
self._extra_formats.remove(registry._ObjectGetter(format))
559
def register_extra_lazy(self, module_name, member_name):
560
"""Register a format lazily.
562
self._extra_formats.append(
563
registry._LazyObjectGetter(module_name, member_name))
565
def _get_extra(self):
566
"""Return all "extra" formats, not usable in meta directories."""
568
for getter in self._extra_formats:
576
"""Return all formats, even those not usable in metadirs.
579
for name in self.keys():
584
return result + self._get_extra()
586
def _get_all_modules(self):
587
"""Return a set of the modules providing objects."""
589
for name in self.keys():
590
modules.add(self._get_module(name))
591
for getter in self._extra_formats:
592
modules.add(getter.get_module())
596
class Converter(object):
597
"""Converts a disk format object from one format to another."""
599
def convert(self, to_convert, pb):
600
"""Perform the conversion of to_convert, giving feedback via pb.
602
:param to_convert: The disk object to convert.
603
:param pb: a progress bar to use for progress information.
606
def step(self, message):
607
"""Update the pb by a step."""
609
self.pb.update(message, self.count, self.total)
612
class ControlDirFormat(object):
613
"""An encapsulation of the initialization and open routines for a format.
615
Formats provide three things:
616
* An initialization routine,
620
Formats are placed in a dict by their format string for reference
621
during controldir opening. These should be subclasses of ControlDirFormat
624
Once a format is deprecated, just deprecate the initialize and open
625
methods on the format class. Do not deprecate the object, as the
626
object will be created every system load.
628
:cvar colocated_branches: Whether this formats supports colocated branches.
629
:cvar supports_workingtrees: This control directory can co-exist with a
633
_default_format = None
634
"""The default format used for new control directories."""
637
"""The registered server format probers, e.g. RemoteBzrProber.
639
This is a list of Prober-derived classes.
643
"""The registered format probers, e.g. BzrProber.
645
This is a list of Prober-derived classes.
648
colocated_branches = False
649
"""Whether co-located branches are supported for this control dir format.
652
supports_workingtrees = True
653
"""Whether working trees can exist in control directories of this format.
656
fixed_components = False
657
"""Whether components can not change format independent of the control dir.
660
upgrade_recommended = False
661
"""Whether an upgrade from this format is recommended."""
663
def get_format_description(self):
664
"""Return the short description for this format."""
665
raise NotImplementedError(self.get_format_description)
667
def get_converter(self, format=None):
668
"""Return the converter to use to convert controldirs needing converts.
670
This returns a bzrlib.controldir.Converter object.
672
This should return the best upgrader to step this format towards the
673
current default format. In the case of plugins we can/should provide
674
some means for them to extend the range of returnable converters.
676
:param format: Optional format to override the default format of the
679
raise NotImplementedError(self.get_converter)
681
def is_supported(self):
682
"""Is this format supported?
684
Supported formats must be initializable and openable.
685
Unsupported formats may not support initialization or committing or
686
some other features depending on the reason for not being supported.
690
def check_support_status(self, allow_unsupported, recommend_upgrade=True,
692
"""Give an error or warning on old formats.
694
:param allow_unsupported: If true, allow opening
695
formats that are strongly deprecated, and which may
696
have limited functionality.
698
:param recommend_upgrade: If true (default), warn
699
the user through the ui object that they may wish
700
to upgrade the object.
702
if not allow_unsupported and not self.is_supported():
703
# see open_downlevel to open legacy branches.
704
raise errors.UnsupportedFormatError(format=self)
705
if recommend_upgrade and self.upgrade_recommended:
706
ui.ui_factory.recommend_upgrade(
707
self.get_format_description(), basedir)
709
def same_model(self, target_format):
710
return (self.repository_format.rich_root_data ==
711
target_format.rich_root_data)
714
def register_format(klass, format):
715
"""Register a format that does not use '.bzr' for its control dir.
718
raise errors.BzrError("ControlDirFormat.register_format() has been "
719
"removed in Bazaar 2.4. Please upgrade your plugins.")
722
def register_prober(klass, prober):
723
"""Register a prober that can look for a control dir.
726
klass._probers.append(prober)
729
def unregister_prober(klass, prober):
730
"""Unregister a prober.
733
klass._probers.remove(prober)
736
def register_server_prober(klass, prober):
737
"""Register a control format prober for client-server environments.
739
These probers will be used before ones registered with
740
register_prober. This gives implementations that decide to the
741
chance to grab it before anything looks at the contents of the format
744
klass._server_probers.append(prober)
748
return self.get_format_description().rstrip()
751
def known_formats(klass):
752
"""Return all the known formats.
755
for prober_kls in klass._probers + klass._server_probers:
756
result.update(prober_kls.known_formats())
760
def find_format(klass, transport, _server_formats=True):
761
"""Return the format present at transport."""
763
_probers = klass._server_probers + klass._probers
765
_probers = klass._probers
766
for prober_kls in _probers:
767
prober = prober_kls()
769
return prober.probe_transport(transport)
770
except errors.NotBranchError:
771
# this format does not find a control dir here.
773
raise errors.NotBranchError(path=transport.base)
775
def initialize(self, url, possible_transports=None):
776
"""Create a control dir at this url and return an opened copy.
778
While not deprecated, this method is very specific and its use will
779
lead to many round trips to setup a working environment. See
780
initialize_on_transport_ex for a [nearly] all-in-one method.
782
Subclasses should typically override initialize_on_transport
783
instead of this method.
785
return self.initialize_on_transport(
786
_mod_transport.get_transport(url, possible_transports))
788
def initialize_on_transport(self, transport):
789
"""Initialize a new controldir in the base directory of a Transport."""
790
raise NotImplementedError(self.initialize_on_transport)
792
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
793
create_prefix=False, force_new_repo=False, stacked_on=None,
794
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
795
shared_repo=False, vfs_only=False):
796
"""Create this format on transport.
798
The directory to initialize will be created.
800
:param force_new_repo: Do not use a shared repository for the target,
801
even if one is available.
802
:param create_prefix: Create any missing directories leading up to
804
:param use_existing_dir: Use an existing directory if one exists.
805
:param stacked_on: A url to stack any created branch on, None to follow
806
any target stacking policy.
807
:param stack_on_pwd: If stack_on is relative, the location it is
809
:param repo_format_name: If non-None, a repository will be
810
made-or-found. Should none be found, or if force_new_repo is True
811
the repo_format_name is used to select the format of repository to
813
:param make_working_trees: Control the setting of make_working_trees
814
for a new shared repository when one is made. None to use whatever
815
default the format has.
816
:param shared_repo: Control whether made repositories are shared or
818
:param vfs_only: If True do not attempt to use a smart server
819
:return: repo, controldir, require_stacking, repository_policy. repo is
820
None if none was created or found, controldir is always valid.
821
require_stacking is the result of examining the stacked_on
822
parameter and any stacking policy found for the target.
824
raise NotImplementedError(self.initialize_on_transport_ex)
826
def network_name(self):
827
"""A simple byte string uniquely identifying this format for RPC calls.
829
Bzr control formats use this disk format string to identify the format
830
over the wire. Its possible that other control formats have more
831
complex detection requirements, so we permit them to use any unique and
832
immutable string they desire.
834
raise NotImplementedError(self.network_name)
836
def open(self, transport, _found=False):
837
"""Return an instance of this format for the dir transport points at.
839
raise NotImplementedError(self.open)
842
def _set_default_format(klass, format):
843
"""Set default format (for testing behavior of defaults only)"""
844
klass._default_format = format
847
def get_default_format(klass):
848
"""Return the current default format."""
849
return klass._default_format
852
class Prober(object):
853
"""Abstract class that can be used to detect a particular kind of
856
At the moment this just contains a single method to probe a particular
857
transport, but it may be extended in the future to e.g. avoid
858
multiple levels of probing for Subversion repositories.
860
See BzrProber and RemoteBzrProber in bzrlib.bzrdir for the
861
probers that detect .bzr/ directories and Bazaar smart servers,
864
Probers should be registered using the register_server_prober or
865
register_prober methods on ControlDirFormat.
868
def probe_transport(self, transport):
869
"""Return the controldir style format present in a directory.
871
:raise UnknownFormatError: If a control dir was found but is
872
in an unknown format.
873
:raise NotBranchError: If no control directory was found.
874
:return: A ControlDirFormat instance.
876
raise NotImplementedError(self.probe_transport)
879
def known_formats(cls):
880
"""Return the control dir formats known by this prober.
882
Multiple probers can return the same formats, so this should
885
:return: A set of known formats.
887
raise NotImplementedError(cls.known_formats)
890
class ControlDirFormatInfo(object):
892
def __init__(self, native, deprecated, hidden, experimental):
893
self.deprecated = deprecated
896
self.experimental = experimental
899
class ControlDirFormatRegistry(registry.Registry):
900
"""Registry of user-selectable ControlDir subformats.
902
Differs from ControlDirFormat._formats in that it provides sub-formats,
903
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
907
"""Create a ControlDirFormatRegistry."""
908
self._aliases = set()
909
self._registration_order = list()
910
super(ControlDirFormatRegistry, self).__init__()
913
"""Return a set of the format names which are aliases."""
914
return frozenset(self._aliases)
916
def register(self, key, factory, help, native=True, deprecated=False,
917
hidden=False, experimental=False, alias=False):
918
"""Register a ControlDirFormat factory.
920
The factory must be a callable that takes one parameter: the key.
921
It must produce an instance of the ControlDirFormat when called.
923
This function mainly exists to prevent the info object from being
926
registry.Registry.register(self, key, factory, help,
927
ControlDirFormatInfo(native, deprecated, hidden, experimental))
929
self._aliases.add(key)
930
self._registration_order.append(key)
932
def register_lazy(self, key, module_name, member_name, help, native=True,
933
deprecated=False, hidden=False, experimental=False, alias=False):
934
registry.Registry.register_lazy(self, key, module_name, member_name,
935
help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
937
self._aliases.add(key)
938
self._registration_order.append(key)
940
def set_default(self, key):
941
"""Set the 'default' key to be a clone of the supplied key.
943
This method must be called once and only once.
945
registry.Registry.register(self, 'default', self.get(key),
946
self.get_help(key), info=self.get_info(key))
947
self._aliases.add('default')
949
def set_default_repository(self, key):
950
"""Set the FormatRegistry default and Repository default.
952
This is a transitional method while Repository.set_default_format
955
if 'default' in self:
956
self.remove('default')
957
self.set_default(key)
958
format = self.get('default')()
960
def make_bzrdir(self, key):
961
return self.get(key)()
963
def help_topic(self, topic):
965
default_realkey = None
966
default_help = self.get_help('default')
968
for key in self._registration_order:
971
help = self.get_help(key)
972
if help == default_help:
973
default_realkey = key
975
help_pairs.append((key, help))
977
def wrapped(key, help, info):
979
help = '(native) ' + help
980
return ':%s:\n%s\n\n' % (key,
981
textwrap.fill(help, initial_indent=' ',
982
subsequent_indent=' ',
983
break_long_words=False))
984
if default_realkey is not None:
985
output += wrapped(default_realkey, '(default) %s' % default_help,
986
self.get_info('default'))
987
deprecated_pairs = []
988
experimental_pairs = []
989
for key, help in help_pairs:
990
info = self.get_info(key)
993
elif info.deprecated:
994
deprecated_pairs.append((key, help))
995
elif info.experimental:
996
experimental_pairs.append((key, help))
998
output += wrapped(key, help, info)
999
output += "\nSee :doc:`formats-help` for more about storage formats."
1001
if len(experimental_pairs) > 0:
1002
other_output += "Experimental formats are shown below.\n\n"
1003
for key, help in experimental_pairs:
1004
info = self.get_info(key)
1005
other_output += wrapped(key, help, info)
1008
"No experimental formats are available.\n\n"
1009
if len(deprecated_pairs) > 0:
1010
other_output += "\nDeprecated formats are shown below.\n\n"
1011
for key, help in deprecated_pairs:
1012
info = self.get_info(key)
1013
other_output += wrapped(key, help, info)
1016
"\nNo deprecated formats are available.\n\n"
1018
"\nSee :doc:`formats-help` for more about storage formats."
1020
if topic == 'other-formats':
1026
# Please register new formats after old formats so that formats
1027
# appear in chronological order and format descriptions can build
1029
format_registry = ControlDirFormatRegistry()
1031
network_format_registry = registry.FormatRegistry()
1032
"""Registry of formats indexed by their network name.
1034
The network name for a ControlDirFormat is an identifier that can be used when
1035
referring to formats with smart server operations. See
1036
ControlDirFormat.network_name() for more detail.