1
# Copyright (C) 2010 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(), """
33
revision as _mod_revision,
37
from bzrlib.push import (
40
from bzrlib.trace import (
43
from bzrlib.transport import (
51
class ControlComponent(object):
52
"""Abstract base class for control directory components.
54
This provides interfaces that are common across controldirs,
55
repositories, branches, and workingtree control directories.
57
They all expose two urls and transports: the *user* URL is the
58
one that stops above the control directory (eg .bzr) and that
59
should normally be used in messages, and the *control* URL is
60
under that in eg .bzr/checkout and is used to read the control
63
This can be used as a mixin and is intended to fit with
68
def control_transport(self):
69
raise NotImplementedError
72
def control_url(self):
73
return self.control_transport.base
76
def user_transport(self):
77
raise NotImplementedError
81
return self.user_transport.base
84
class ControlDir(ControlComponent):
85
"""A control directory.
87
While this represents a generic control directory, there are a few
88
features that are present in this interface that are currently only
89
supported by one of its implementations, BzrDir.
91
These features (bound branches, stacked branches) are currently only
92
supported by Bazaar, but could be supported by other version control
93
systems as well. Implementations are required to raise the appropriate
94
exceptions when an operation is requested that is not supported.
96
This also makes life easier for API users who can rely on the
97
implementation always allowing a particular feature to be requested but
98
raising an exception when it is not supported, rather than requiring the
99
API users to check for magic attributes to see what features are supported.
102
def can_convert_format(self):
103
"""Return true if this controldir is one whose format we can convert
107
def list_branches(self):
108
"""Return a sequence of all branches local to this control directory.
112
return [self.open_branch()]
113
except (errors.NotBranchError, errors.NoRepositoryPresent):
116
def is_control_filename(self, filename):
117
"""True if filename is the name of a path which is reserved for
120
:param filename: A filename within the root transport of this
123
This is true IF and ONLY IF the filename is part of the namespace reserved
124
for bzr control dirs. Currently this is the '.bzr' directory in the root
125
of the root_transport. it is expected that plugins will need to extend
126
this in the future - for instance to make bzr talk with svn working
129
raise NotImplementedError(self.is_control_filename)
131
def needs_format_conversion(self, format=None):
132
"""Return true if this controldir needs convert_format run on it.
134
For instance, if the repository format is out of date but the
135
branch and working tree are not, this should return True.
137
:param format: Optional parameter indicating a specific desired
138
format we plan to arrive at.
140
raise NotImplementedError(self.needs_format_conversion)
142
def destroy_repository(self):
143
"""Destroy the repository in this ControlDir."""
144
raise NotImplementedError(self.destroy_repository)
146
def create_branch(self, name=None):
147
"""Create a branch in this ControlDir.
149
:param name: Name of the colocated branch to create, None for
152
The controldirs format will control what branch format is created.
153
For more control see BranchFormatXX.create(a_controldir).
155
raise NotImplementedError(self.create_branch)
157
def destroy_branch(self, name=None):
158
"""Destroy a branch in this ControlDir.
160
:param name: Name of the branch to destroy, None for the default
163
raise NotImplementedError(self.destroy_branch)
165
def create_workingtree(self, revision_id=None, from_branch=None,
166
accelerator_tree=None, hardlink=False):
167
"""Create a working tree at this ControlDir.
169
:param revision_id: create it as of this revision id.
170
:param from_branch: override controldir branch
171
(for lightweight checkouts)
172
:param accelerator_tree: A tree which can be used for retrieving file
173
contents more quickly than the revision tree, i.e. a workingtree.
174
The revision tree will be used for cases where accelerator_tree's
175
content is different.
177
raise NotImplementedError(self.create_workingtree)
179
def destroy_workingtree(self):
180
"""Destroy the working tree at this ControlDir.
182
Formats that do not support this may raise UnsupportedOperation.
184
raise NotImplementedError(self.destroy_workingtree)
186
def destroy_workingtree_metadata(self):
187
"""Destroy the control files for the working tree at this ControlDir.
189
The contents of working tree files are not affected.
190
Formats that do not support this may raise UnsupportedOperation.
192
raise NotImplementedError(self.destroy_workingtree_metadata)
194
def get_branch_reference(self, name=None):
195
"""Return the referenced URL for the branch in this controldir.
197
:param name: Optional colocated branch name
198
:raises NotBranchError: If there is no Branch.
199
:raises NoColocatedBranchSupport: If a branch name was specified
200
but colocated branches are not supported.
201
:return: The URL the branch in this controldir references if it is a
202
reference branch, or None for regular branches.
205
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
def open_branch(self, name=None, unsupported=False,
248
ignore_fallbacks=False):
249
"""Open the branch object at this ControlDir if one is present.
251
If unsupported is True, then no longer supported branch formats can
254
TODO: static convenience version of this?
256
raise NotImplementedError(self.open_branch)
258
def open_repository(self, _unsupported=False):
259
"""Open the repository object at this ControlDir if one is present.
261
This will not follow the Branch object pointer - it's strictly a direct
262
open facility. Most client code should use open_branch().repository to
265
:param _unsupported: a private parameter, not part of the api.
266
TODO: static convenience version of this?
268
raise NotImplementedError(self.open_repository)
270
def find_repository(self):
271
"""Find the repository that should be used.
273
This does not require a branch as we use it to find the repo for
274
new branches as well as to hook existing branches up to their
277
raise NotImplementedError(self.find_repository)
279
def open_workingtree(self, _unsupported=False,
280
recommend_upgrade=True, from_branch=None):
281
"""Open the workingtree object at this ControlDir if one is present.
283
:param recommend_upgrade: Optional keyword parameter, when True (the
284
default), emit through the ui module a recommendation that the user
285
upgrade the working tree when the workingtree being opened is old
286
(but still fully supported).
287
:param from_branch: override controldir branch (for lightweight
290
raise NotImplementedError(self.open_workingtree)
292
def has_branch(self, name=None):
293
"""Tell if this controldir contains a branch.
295
Note: if you're going to open the branch, you should just go ahead
296
and try, and not ask permission first. (This method just opens the
297
branch and discards it, and that's somewhat expensive.)
300
self.open_branch(name)
302
except errors.NotBranchError:
305
def has_workingtree(self):
306
"""Tell if this controldir contains a working tree.
308
This will still raise an exception if the controldir has a workingtree
309
that is remote & inaccessible.
311
Note: if you're going to open the working tree, you should just go ahead
312
and try, and not ask permission first. (This method just opens the
313
workingtree and discards it, and that's somewhat expensive.)
316
self.open_workingtree(recommend_upgrade=False)
318
except errors.NoWorkingTree:
321
def cloning_metadir(self, require_stacking=False):
322
"""Produce a metadir suitable for cloning or sprouting with.
324
These operations may produce workingtrees (yes, even though they're
325
"cloning" something that doesn't have a tree), so a viable workingtree
326
format must be selected.
328
:require_stacking: If True, non-stackable formats will be upgraded
329
to similar stackable formats.
330
:returns: a ControlDirFormat with all component formats either set
331
appropriately or set to None if that component should not be
334
raise NotImplementedError(self.cloning_metadir)
336
def checkout_metadir(self):
337
"""Produce a metadir suitable for checkouts of this controldir."""
338
return self.cloning_metadir()
340
def sprout(self, url, revision_id=None, force_new_repo=False,
341
recurse='down', possible_transports=None,
342
accelerator_tree=None, hardlink=False, stacked=False,
343
source_branch=None, create_tree_if_local=True):
344
"""Create a copy of this controldir prepared for use as a new line of
347
If url's last component does not exist, it will be created.
349
Attributes related to the identity of the source branch like
350
branch nickname will be cleaned, a working tree is created
351
whether one existed before or not; and a local branch is always
354
if revision_id is not None, then the clone operation may tune
355
itself to download less data.
356
:param accelerator_tree: A tree which can be used for retrieving file
357
contents more quickly than the revision tree, i.e. a workingtree.
358
The revision tree will be used for cases where accelerator_tree's
359
content is different.
360
:param hardlink: If true, hard-link files from accelerator_tree,
362
:param stacked: If true, create a stacked branch referring to the
363
location of this control directory.
364
:param create_tree_if_local: If true, a working-tree will be created
365
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:
464
def push_branch(self, source, revision_id=None, overwrite=False,
465
remember=False, create_prefix=False):
466
"""Push the source branch into this ControlDir."""
468
# If we can open a branch, use its direct repository, otherwise see
469
# if there is a repository without a branch.
471
br_to = self.open_branch()
472
except errors.NotBranchError:
473
# Didn't find a branch, can we find a repository?
474
repository_to = self.find_repository()
476
# Found a branch, so we must have found a repository
477
repository_to = br_to.repository
479
push_result = PushResult()
480
push_result.source_branch = source
482
# We have a repository but no branch, copy the revisions, and then
484
repository_to.fetch(source.repository, revision_id=revision_id)
485
br_to = source.clone(self, revision_id=revision_id)
486
if source.get_push_location() is None or remember:
487
source.set_push_location(br_to.base)
488
push_result.stacked_on = None
489
push_result.branch_push_result = None
490
push_result.old_revno = None
491
push_result.old_revid = _mod_revision.NULL_REVISION
492
push_result.target_branch = br_to
493
push_result.master_branch = None
494
push_result.workingtree_updated = False
496
# We have successfully opened the branch, remember if necessary:
497
if source.get_push_location() is None or remember:
498
source.set_push_location(br_to.base)
500
tree_to = self.open_workingtree()
501
except errors.NotLocalUrl:
502
push_result.branch_push_result = source.push(br_to,
503
overwrite, stop_revision=revision_id)
504
push_result.workingtree_updated = False
505
except errors.NoWorkingTree:
506
push_result.branch_push_result = source.push(br_to,
507
overwrite, stop_revision=revision_id)
508
push_result.workingtree_updated = None # Not applicable
512
push_result.branch_push_result = source.push(
513
tree_to.branch, overwrite, stop_revision=revision_id)
517
push_result.workingtree_updated = True
518
push_result.old_revno = push_result.branch_push_result.old_revno
519
push_result.old_revid = push_result.branch_push_result.old_revid
520
push_result.target_branch = \
521
push_result.branch_push_result.target_branch
524
def _get_tree_branch(self, name=None):
525
"""Return the branch and tree, if any, for this bzrdir.
527
:param name: Name of colocated branch to open.
529
Return None for tree if not present or inaccessible.
530
Raise NotBranchError if no branch is present.
531
:return: (tree, branch)
534
tree = self.open_workingtree()
535
except (errors.NoWorkingTree, errors.NotLocalUrl):
537
branch = self.open_branch(name=name)
540
branch = self.open_branch(name=name)
545
def get_config(self):
546
"""Get configuration for this ControlDir."""
547
raise NotImplementedError(self.get_config)
549
def check_conversion_target(self, target_format):
550
"""Check that a bzrdir as a whole can be converted to a new format."""
551
raise NotImplementedError(self.check_conversion_target)
553
def clone(self, url, revision_id=None, force_new_repo=False,
554
preserve_stacking=False):
555
"""Clone this bzrdir and its contents to url verbatim.
557
:param url: The url create the clone at. If url's last component does
558
not exist, it will be created.
559
:param revision_id: The tip revision-id to use for any branch or
560
working tree. If not None, then the clone operation may tune
561
itself to download less data.
562
:param force_new_repo: Do not use a shared repository for the target
563
even if one is available.
564
:param preserve_stacking: When cloning a stacked branch, stack the
565
new branch on top of the other branch's stacked-on branch.
567
return self.clone_on_transport(get_transport(url),
568
revision_id=revision_id,
569
force_new_repo=force_new_repo,
570
preserve_stacking=preserve_stacking)
572
def clone_on_transport(self, transport, revision_id=None,
573
force_new_repo=False, preserve_stacking=False, stacked_on=None,
574
create_prefix=False, use_existing_dir=True):
575
"""Clone this bzrdir and its contents to transport verbatim.
577
:param transport: The transport for the location to produce the clone
578
at. If the target directory does not exist, it will be created.
579
:param revision_id: The tip revision-id to use for any branch or
580
working tree. If not None, then the clone operation may tune
581
itself to download less data.
582
:param force_new_repo: Do not use a shared repository for the target,
583
even if one is available.
584
:param preserve_stacking: When cloning a stacked branch, stack the
585
new branch on top of the other branch's stacked-on branch.
586
:param create_prefix: Create any missing directories leading up to
588
:param use_existing_dir: Use an existing directory if one exists.
590
raise NotImplementedError(self.clone_on_transport)
593
class ControlDirFormat(object):
594
"""An encapsulation of the initialization and open routines for a format.
596
Formats provide three things:
597
* An initialization routine,
601
Formats are placed in a dict by their format string for reference
602
during controldir opening. These should be subclasses of ControlDirFormat
605
Once a format is deprecated, just deprecate the initialize and open
606
methods on the format class. Do not deprecate the object, as the
607
object will be created every system load.
609
:cvar colocated_branches: Whether this formats supports colocated branches.
610
:cvar supports_workingtrees: This control directory can co-exist with a
614
_default_format = None
615
"""The default format used for new control directories."""
618
"""The registered control formats - .bzr, ....
620
This is a list of ControlDirFormat objects.
624
"""The registered server format probers, e.g. RemoteBzrProber.
626
This is a list of Prober-derived classes.
630
"""The registered format probers, e.g. BzrProber.
632
This is a list of Prober-derived classes.
635
colocated_branches = False
636
"""Whether co-located branches are supported for this control dir format.
639
supports_workingtrees = True
641
def get_format_description(self):
642
"""Return the short description for this format."""
643
raise NotImplementedError(self.get_format_description)
645
def get_converter(self, format=None):
646
"""Return the converter to use to convert controldirs needing converts.
648
This returns a bzrlib.controldir.Converter object.
650
This should return the best upgrader to step this format towards the
651
current default format. In the case of plugins we can/should provide
652
some means for them to extend the range of returnable converters.
654
:param format: Optional format to override the default format of the
657
raise NotImplementedError(self.get_converter)
659
def is_supported(self):
660
"""Is this format supported?
662
Supported formats must be initializable and openable.
663
Unsupported formats may not support initialization or committing or
664
some other features depending on the reason for not being supported.
668
def same_model(self, target_format):
669
return (self.repository_format.rich_root_data ==
670
target_format.rich_root_data)
673
def register_format(klass, format):
674
"""Register a format that does not use '.bzr' for its control dir.
677
klass._formats.append(format)
680
def register_prober(klass, prober):
681
"""Register a prober that can look for a control dir.
684
klass._probers.append(prober)
687
def unregister_prober(klass, prober):
688
"""Unregister a prober.
691
klass._probers.remove(prober)
694
def register_server_prober(klass, prober):
695
"""Register a control format prober for client-server environments.
697
These probers will be used before ones registered with
698
register_prober. This gives implementations that decide to the
699
chance to grab it before anything looks at the contents of the format
702
klass._server_probers.append(prober)
706
return self.get_format_description().rstrip()
709
def unregister_format(klass, format):
710
klass._formats.remove(format)
713
def known_formats(klass):
714
"""Return all the known formats.
716
return set(klass._formats)
719
def find_format(klass, transport, _server_formats=True):
720
"""Return the format present at transport."""
722
_probers = klass._server_probers + klass._probers
724
_probers = klass._probers
725
for prober_kls in _probers:
726
prober = prober_kls()
728
return prober.probe_transport(transport)
729
except errors.NotBranchError:
730
# this format does not find a control dir here.
732
raise errors.NotBranchError(path=transport.base)
734
def initialize(self, url, possible_transports=None):
735
"""Create a control dir at this url and return an opened copy.
737
While not deprecated, this method is very specific and its use will
738
lead to many round trips to setup a working environment. See
739
initialize_on_transport_ex for a [nearly] all-in-one method.
741
Subclasses should typically override initialize_on_transport
742
instead of this method.
744
return self.initialize_on_transport(get_transport(url,
745
possible_transports))
746
def initialize_on_transport(self, transport):
747
"""Initialize a new controldir in the base directory of a Transport."""
748
raise NotImplementedError(self.initialize_on_transport)
750
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
751
create_prefix=False, force_new_repo=False, stacked_on=None,
752
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
753
shared_repo=False, vfs_only=False):
754
"""Create this format on transport.
756
The directory to initialize will be created.
758
:param force_new_repo: Do not use a shared repository for the target,
759
even if one is available.
760
:param create_prefix: Create any missing directories leading up to
762
:param use_existing_dir: Use an existing directory if one exists.
763
:param stacked_on: A url to stack any created branch on, None to follow
764
any target stacking policy.
765
:param stack_on_pwd: If stack_on is relative, the location it is
767
:param repo_format_name: If non-None, a repository will be
768
made-or-found. Should none be found, or if force_new_repo is True
769
the repo_format_name is used to select the format of repository to
771
:param make_working_trees: Control the setting of make_working_trees
772
for a new shared repository when one is made. None to use whatever
773
default the format has.
774
:param shared_repo: Control whether made repositories are shared or
776
:param vfs_only: If True do not attempt to use a smart server
777
:return: repo, controldir, require_stacking, repository_policy. repo is
778
None if none was created or found, controldir is always valid.
779
require_stacking is the result of examining the stacked_on
780
parameter and any stacking policy found for the target.
782
raise NotImplementedError(self.initialize_on_transport_ex)
784
def network_name(self):
785
"""A simple byte string uniquely identifying this format for RPC calls.
787
Bzr control formats use this disk format string to identify the format
788
over the wire. Its possible that other control formats have more
789
complex detection requirements, so we permit them to use any unique and
790
immutable string they desire.
792
raise NotImplementedError(self.network_name)
794
def open(self, transport, _found=False):
795
"""Return an instance of this format for the dir transport points at.
797
raise NotImplementedError(self.open)
800
def _set_default_format(klass, format):
801
"""Set default format (for testing behavior of defaults only)"""
802
klass._default_format = format
805
def get_default_format(klass):
806
"""Return the current default format."""
807
return klass._default_format
810
class Prober(object):
811
"""Abstract class that can be used to detect a particular kind of
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
816
multiple levels of probing for Subversion repositories.
819
def probe_transport(self, transport):
820
"""Return the controldir style format present in a directory.
822
:raise UnknownFormatError: If a control dir was found but is
823
in an unknown format.
824
:raise NotBranchError: If no control directory was found.
825
:return: A ControlDirFormat instance.
827
raise NotImplementedError(self.probe_transport)
830
class ControlDirFormatInfo(object):
832
def __init__(self, native, deprecated, hidden, experimental):
833
self.deprecated = deprecated
836
self.experimental = experimental
839
class ControlDirFormatRegistry(registry.Registry):
840
"""Registry of user-selectable ControlDir subformats.
842
Differs from ControlDirFormat._formats in that it provides sub-formats,
843
e.g. ControlDirMeta1 with weave repository. Also, it's more user-oriented.
847
"""Create a ControlDirFormatRegistry."""
848
self._aliases = set()
849
self._registration_order = list()
850
super(ControlDirFormatRegistry, self).__init__()
853
"""Return a set of the format names which are aliases."""
854
return frozenset(self._aliases)
856
def register(self, key, factory, help, native=True, deprecated=False,
857
hidden=False, experimental=False, alias=False):
858
"""Register a ControlDirFormat factory.
860
The factory must be a callable that takes one parameter: the key.
861
It must produce an instance of the ControlDirFormat when called.
863
This function mainly exists to prevent the info object from being
866
registry.Registry.register(self, key, factory, help,
867
ControlDirFormatInfo(native, deprecated, hidden, experimental))
869
self._aliases.add(key)
870
self._registration_order.append(key)
872
def register_lazy(self, key, module_name, member_name, help, native=True,
873
deprecated=False, hidden=False, experimental=False, alias=False):
874
registry.Registry.register_lazy(self, key, module_name, member_name,
875
help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
877
self._aliases.add(key)
878
self._registration_order.append(key)
880
def set_default(self, key):
881
"""Set the 'default' key to be a clone of the supplied key.
883
This method must be called once and only once.
885
registry.Registry.register(self, 'default', self.get(key),
886
self.get_help(key), info=self.get_info(key))
887
self._aliases.add('default')
889
def set_default_repository(self, key):
890
"""Set the FormatRegistry default and Repository default.
892
This is a transitional method while Repository.set_default_format
895
if 'default' in self:
896
self.remove('default')
897
self.set_default(key)
898
format = self.get('default')()
900
def make_bzrdir(self, key):
901
return self.get(key)()
903
def help_topic(self, topic):
905
default_realkey = None
906
default_help = self.get_help('default')
908
for key in self._registration_order:
911
help = self.get_help(key)
912
if help == default_help:
913
default_realkey = key
915
help_pairs.append((key, help))
917
def wrapped(key, help, info):
919
help = '(native) ' + help
920
return ':%s:\n%s\n\n' % (key,
921
textwrap.fill(help, initial_indent=' ',
922
subsequent_indent=' ',
923
break_long_words=False))
924
if default_realkey is not None:
925
output += wrapped(default_realkey, '(default) %s' % default_help,
926
self.get_info('default'))
927
deprecated_pairs = []
928
experimental_pairs = []
929
for key, help in help_pairs:
930
info = self.get_info(key)
933
elif info.deprecated:
934
deprecated_pairs.append((key, help))
935
elif info.experimental:
936
experimental_pairs.append((key, help))
938
output += wrapped(key, help, info)
939
output += "\nSee :doc:`formats-help` for more about storage formats."
941
if len(experimental_pairs) > 0:
942
other_output += "Experimental formats are shown below.\n\n"
943
for key, help in experimental_pairs:
944
info = self.get_info(key)
945
other_output += wrapped(key, help, info)
948
"No experimental formats are available.\n\n"
949
if len(deprecated_pairs) > 0:
950
other_output += "\nDeprecated formats are shown below.\n\n"
951
for key, help in deprecated_pairs:
952
info = self.get_info(key)
953
other_output += wrapped(key, help, info)
956
"\nNo deprecated formats are available.\n\n"
958
"\nSee :doc:`formats-help` for more about storage formats."
960
if topic == 'other-formats':
966
# Please register new formats after old formats so that formats
967
# appear in chronological order and format descriptions can build
969
format_registry = ControlDirFormatRegistry()
971
network_format_registry = registry.FormatRegistry()
972
"""Registry of formats indexed by their network name.
974
The network name for a ControlDirFormat is an identifier that can be used when
975
referring to formats with smart server operations. See
976
ControlDirFormat.network_name() for more detail.