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(), """
33
revision as _mod_revision,
34
transport as _mod_transport,
37
from bzrlib.push import (
40
from bzrlib.trace import (
43
from bzrlib.transport import (
49
from bzrlib import registry
52
class ControlComponent(object):
53
"""Abstract base class for control directory components.
55
This provides interfaces that are common across controldirs,
56
repositories, branches, and workingtree control directories.
58
They all expose two urls and transports: the *user* URL is the
59
one that stops above the control directory (eg .bzr) and that
60
should normally be used in messages, and the *control* URL is
61
under that in eg .bzr/checkout and is used to read the control
64
This can be used as a mixin and is intended to fit with
69
def control_transport(self):
70
raise NotImplementedError
73
def control_url(self):
74
return self.control_transport.base
77
def user_transport(self):
78
raise NotImplementedError
82
return self.user_transport.base
85
class ControlDir(ControlComponent):
86
"""A control directory.
88
While this represents a generic control directory, there are a few
89
features that are present in this interface that are currently only
90
supported by one of its implementations, BzrDir.
92
These features (bound branches, stacked branches) are currently only
93
supported by Bazaar, but could be supported by other version control
94
systems as well. Implementations are required to raise the appropriate
95
exceptions when an operation is requested that is not supported.
97
This also makes life easier for API users who can rely on the
98
implementation always allowing a particular feature to be requested but
99
raising an exception when it is not supported, rather than requiring the
100
API users to check for magic attributes to see what features are supported.
103
def can_convert_format(self):
104
"""Return true if this controldir is one whose format we can convert
108
def list_branches(self):
109
"""Return a sequence of all branches local to this control directory.
113
return [self.open_branch()]
114
except (errors.NotBranchError, errors.NoRepositoryPresent):
117
def is_control_filename(self, filename):
118
"""True if filename is the name of a path which is reserved for
121
:param filename: A filename within the root transport of this
124
This is true IF and ONLY IF the filename is part of the namespace reserved
125
for bzr control dirs. Currently this is the '.bzr' directory in the root
126
of the root_transport. it is expected that plugins will need to extend
127
this in the future - for instance to make bzr talk with svn working
130
raise NotImplementedError(self.is_control_filename)
132
def needs_format_conversion(self, format=None):
133
"""Return true if this controldir needs convert_format run on it.
135
For instance, if the repository format is out of date but the
136
branch and working tree are not, this should return True.
138
:param format: Optional parameter indicating a specific desired
139
format we plan to arrive at.
141
raise NotImplementedError(self.needs_format_conversion)
143
def destroy_repository(self):
144
"""Destroy the repository in this ControlDir."""
145
raise NotImplementedError(self.destroy_repository)
147
def create_branch(self, name=None, repository=None):
148
"""Create a branch in this ControlDir.
150
:param name: Name of the colocated branch to create, None for
153
The controldirs format will control what branch format is created.
154
For more control see BranchFormatXX.create(a_controldir).
156
raise NotImplementedError(self.create_branch)
158
def destroy_branch(self, name=None):
159
"""Destroy a branch in this ControlDir.
161
:param name: Name of the branch to destroy, None for the default
164
raise NotImplementedError(self.destroy_branch)
166
def create_workingtree(self, revision_id=None, from_branch=None,
167
accelerator_tree=None, hardlink=False):
168
"""Create a working tree at this ControlDir.
170
:param revision_id: create it as of this revision id.
171
:param from_branch: override controldir branch
172
(for lightweight checkouts)
173
:param accelerator_tree: A tree which can be used for retrieving file
174
contents more quickly than the revision tree, i.e. a workingtree.
175
The revision tree will be used for cases where accelerator_tree's
176
content is different.
178
raise NotImplementedError(self.create_workingtree)
180
def destroy_workingtree(self):
181
"""Destroy the working tree at this ControlDir.
183
Formats that do not support this may raise UnsupportedOperation.
185
raise NotImplementedError(self.destroy_workingtree)
187
def destroy_workingtree_metadata(self):
188
"""Destroy the control files for the working tree at this ControlDir.
190
The contents of working tree files are not affected.
191
Formats that do not support this may raise UnsupportedOperation.
193
raise NotImplementedError(self.destroy_workingtree_metadata)
195
def get_branch_reference(self, name=None):
196
"""Return the referenced URL for the branch in this controldir.
198
:param name: Optional colocated branch name
199
:raises NotBranchError: If there is no Branch.
200
:raises NoColocatedBranchSupport: If a branch name was specified
201
but colocated branches are not supported.
202
:return: The URL the branch in this controldir references if it is a
203
reference branch, or None for regular branches.
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)
248
def open_branch(self, name=None, unsupported=False,
249
ignore_fallbacks=False):
250
"""Open the branch object at this ControlDir if one is present.
252
If unsupported is True, then no longer supported branch formats can
255
TODO: static convenience version of this?
257
raise NotImplementedError(self.open_branch)
259
def open_repository(self, _unsupported=False):
260
"""Open the repository object at this ControlDir if one is present.
262
This will not follow the Branch object pointer - it's strictly a direct
263
open facility. Most client code should use open_branch().repository to
266
:param _unsupported: a private parameter, not part of the api.
267
TODO: static convenience version of this?
269
raise NotImplementedError(self.open_repository)
271
def find_repository(self):
272
"""Find the repository that should be used.
274
This does not require a branch as we use it to find the repo for
275
new branches as well as to hook existing branches up to their
278
raise NotImplementedError(self.find_repository)
280
def open_workingtree(self, _unsupported=False,
281
recommend_upgrade=True, from_branch=None):
282
"""Open the workingtree object at this ControlDir if one is present.
284
:param recommend_upgrade: Optional keyword parameter, when True (the
285
default), emit through the ui module a recommendation that the user
286
upgrade the working tree when the workingtree being opened is old
287
(but still fully supported).
288
:param from_branch: override controldir branch (for lightweight
291
raise NotImplementedError(self.open_workingtree)
293
def has_branch(self, name=None):
294
"""Tell if this controldir contains a branch.
296
Note: if you're going to open the branch, you should just go ahead
297
and try, and not ask permission first. (This method just opens the
298
branch and discards it, and that's somewhat expensive.)
301
self.open_branch(name)
303
except errors.NotBranchError:
306
def has_workingtree(self):
307
"""Tell if this controldir contains a working tree.
309
This will still raise an exception if the controldir has a workingtree
310
that is remote & inaccessible.
312
Note: if you're going to open the working tree, you should just go ahead
313
and try, and not ask permission first. (This method just opens the
314
workingtree and discards it, and that's somewhat expensive.)
317
self.open_workingtree(recommend_upgrade=False)
319
except errors.NoWorkingTree:
322
def cloning_metadir(self, require_stacking=False):
323
"""Produce a metadir suitable for cloning or sprouting with.
325
These operations may produce workingtrees (yes, even though they're
326
"cloning" something that doesn't have a tree), so a viable workingtree
327
format must be selected.
329
:require_stacking: If True, non-stackable formats will be upgraded
330
to similar stackable formats.
331
:returns: a ControlDirFormat with all component formats either set
332
appropriately or set to None if that component should not be
335
raise NotImplementedError(self.cloning_metadir)
337
def checkout_metadir(self):
338
"""Produce a metadir suitable for checkouts of this controldir."""
339
return self.cloning_metadir()
341
def sprout(self, url, revision_id=None, force_new_repo=False,
342
recurse='down', possible_transports=None,
343
accelerator_tree=None, hardlink=False, stacked=False,
344
source_branch=None, create_tree_if_local=True):
345
"""Create a copy of this controldir prepared for use as a new line of
348
If url's last component does not exist, it will be created.
350
Attributes related to the identity of the source branch like
351
branch nickname will be cleaned, a working tree is created
352
whether one existed before or not; and a local branch is always
355
if revision_id is not None, then the clone operation may tune
356
itself to download less data.
357
:param accelerator_tree: A tree which can be used for retrieving file
358
contents more quickly than the revision tree, i.e. a workingtree.
359
The revision tree will be used for cases where accelerator_tree's
360
content is different.
361
:param hardlink: If true, hard-link files from accelerator_tree,
363
:param stacked: If true, create a stacked branch referring to the
364
location of this control directory.
365
:param create_tree_if_local: If true, a working-tree will be created
366
when working locally.
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 = _mod_transport.get_transport(url,
383
target_transport.ensure_base()
384
cloning_format = self.cloning_metadir(stacked)
385
# Create/update the result branch
386
result = cloning_format.initialize_on_transport(target_transport)
387
# if a stacked branch wasn't requested, we don't create one
388
# even if the origin was stacked
389
stacked_branch_url = None
390
if source_branch is not None:
391
add_cleanup(source_branch.lock_read().unlock)
393
stacked_branch_url = self.root_transport.base
394
source_repository = source_branch.repository
397
source_branch = self.open_branch()
398
source_repository = source_branch.repository
400
stacked_branch_url = self.root_transport.base
401
except errors.NotBranchError:
404
source_repository = self.open_repository()
405
except errors.NoRepositoryPresent:
406
source_repository = None
408
add_cleanup(source_repository.lock_read().unlock)
410
add_cleanup(source_branch.lock_read().unlock)
411
repository_policy = result.determine_repository_policy(
412
force_new_repo, stacked_branch_url, require_stacking=stacked)
413
result_repo, is_new_repo = repository_policy.acquire_repository()
414
add_cleanup(result_repo.lock_write().unlock)
415
is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
416
if is_new_repo and revision_id is not None and not is_stacked:
417
fetch_spec = graph.PendingAncestryResult(
418
[revision_id], source_repository)
421
if source_repository is not None:
422
# Fetch while stacked to prevent unstacked fetch from
424
if fetch_spec is None:
425
result_repo.fetch(source_repository, revision_id=revision_id)
427
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
429
if source_branch is None:
430
# this is for sprouting a controldir without a branch; is that
432
# Not especially, but it's part of the contract.
433
result_branch = result.create_branch()
435
result_branch = source_branch.sprout(result,
436
revision_id=revision_id, repository_policy=repository_policy,
437
repository=result_repo)
438
mutter("created new branch %r" % (result_branch,))
440
# Create/update the result working tree
441
if (create_tree_if_local and
442
isinstance(target_transport, local.LocalTransport) and
443
(result_repo is None or result_repo.make_working_trees())):
444
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
445
hardlink=hardlink, from_branch=result_branch)
448
if wt.path2id('') is None:
450
wt.set_root_id(self.open_workingtree.get_root_id())
451
except errors.NoWorkingTree:
457
if recurse == 'down':
459
basis = wt.basis_tree()
461
subtrees = basis.iter_references()
462
elif result_branch is not None:
463
basis = result_branch.basis_tree()
465
subtrees = basis.iter_references()
466
elif source_branch is not None:
467
basis = source_branch.basis_tree()
469
subtrees = basis.iter_references()
474
for path, file_id in subtrees:
475
target = urlutils.join(url, urlutils.escape(path))
476
sublocation = source_branch.reference_parent(file_id, path)
477
sublocation.bzrdir.sprout(target,
478
basis.get_reference_revision(file_id, path),
479
force_new_repo=force_new_repo, recurse=recurse,
482
if basis is not None:
486
def push_branch(self, source, revision_id=None, overwrite=False,
487
remember=False, create_prefix=False):
488
"""Push the source branch into this ControlDir."""
490
# If we can open a branch, use its direct repository, otherwise see
491
# if there is a repository without a branch.
493
br_to = self.open_branch()
494
except errors.NotBranchError:
495
# Didn't find a branch, can we find a repository?
496
repository_to = self.find_repository()
498
# Found a branch, so we must have found a repository
499
repository_to = br_to.repository
501
push_result = PushResult()
502
push_result.source_branch = source
504
# We have a repository but no branch, copy the revisions, and then
506
repository_to.fetch(source.repository, revision_id=revision_id)
507
br_to = source.clone(self, revision_id=revision_id)
508
if source.get_push_location() is None or remember:
509
source.set_push_location(br_to.base)
510
push_result.stacked_on = None
511
push_result.branch_push_result = None
512
push_result.old_revno = None
513
push_result.old_revid = _mod_revision.NULL_REVISION
514
push_result.target_branch = br_to
515
push_result.master_branch = None
516
push_result.workingtree_updated = False
518
# We have successfully opened the branch, remember if necessary:
519
if source.get_push_location() is None or remember:
520
source.set_push_location(br_to.base)
522
tree_to = self.open_workingtree()
523
except errors.NotLocalUrl:
524
push_result.branch_push_result = source.push(br_to,
525
overwrite, stop_revision=revision_id)
526
push_result.workingtree_updated = False
527
except errors.NoWorkingTree:
528
push_result.branch_push_result = source.push(br_to,
529
overwrite, stop_revision=revision_id)
530
push_result.workingtree_updated = None # Not applicable
534
push_result.branch_push_result = source.push(
535
tree_to.branch, overwrite, stop_revision=revision_id)
539
push_result.workingtree_updated = True
540
push_result.old_revno = push_result.branch_push_result.old_revno
541
push_result.old_revid = push_result.branch_push_result.old_revid
542
push_result.target_branch = \
543
push_result.branch_push_result.target_branch
546
def _get_tree_branch(self, name=None):
547
"""Return the branch and tree, if any, for this bzrdir.
549
:param name: Name of colocated branch to open.
551
Return None for tree if not present or inaccessible.
552
Raise NotBranchError if no branch is present.
553
:return: (tree, branch)
556
tree = self.open_workingtree()
557
except (errors.NoWorkingTree, errors.NotLocalUrl):
559
branch = self.open_branch(name=name)
562
branch = self.open_branch(name=name)
567
def get_config(self):
568
"""Get configuration for this ControlDir."""
569
raise NotImplementedError(self.get_config)
571
def check_conversion_target(self, target_format):
572
"""Check that a bzrdir as a whole can be converted to a new format."""
573
raise NotImplementedError(self.check_conversion_target)
575
def clone(self, url, revision_id=None, force_new_repo=False,
576
preserve_stacking=False):
577
"""Clone this bzrdir and its contents to url verbatim.
579
:param url: The url create the clone at. If url's last component does
580
not exist, it will be created.
581
:param revision_id: The tip revision-id to use for any branch or
582
working tree. If not None, then the clone operation may tune
583
itself to download less data.
584
:param force_new_repo: Do not use a shared repository for the target
585
even if one is available.
586
:param preserve_stacking: When cloning a stacked branch, stack the
587
new branch on top of the other branch's stacked-on branch.
589
return self.clone_on_transport(_mod_transport.get_transport(url),
590
revision_id=revision_id,
591
force_new_repo=force_new_repo,
592
preserve_stacking=preserve_stacking)
594
def clone_on_transport(self, transport, revision_id=None,
595
force_new_repo=False, preserve_stacking=False, stacked_on=None,
596
create_prefix=False, use_existing_dir=True):
597
"""Clone this bzrdir and its contents to transport verbatim.
599
:param transport: The transport for the location to produce the clone
600
at. If the target directory does not exist, it will be created.
601
:param revision_id: The tip revision-id to use for any branch or
602
working tree. If not None, then the clone operation may tune
603
itself to download less data.
604
:param force_new_repo: Do not use a shared repository for the target,
605
even if one is available.
606
:param preserve_stacking: When cloning a stacked branch, stack the
607
new branch on top of the other branch's stacked-on branch.
608
:param create_prefix: Create any missing directories leading up to
610
:param use_existing_dir: Use an existing directory if one exists.
612
raise NotImplementedError(self.clone_on_transport)
615
class ControlDirFormat(object):
616
"""An encapsulation of the initialization and open routines for a format.
618
Formats provide three things:
619
* An initialization routine,
623
Formats are placed in a dict by their format string for reference
624
during controldir opening. These should be subclasses of ControlDirFormat
627
Once a format is deprecated, just deprecate the initialize and open
628
methods on the format class. Do not deprecate the object, as the
629
object will be created every system load.
631
:cvar colocated_branches: Whether this formats supports colocated branches.
632
:cvar supports_workingtrees: This control directory can co-exist with a
636
_default_format = None
637
"""The default format used for new control directories."""
640
"""The registered control formats - .bzr, ....
642
This is a list of ControlDirFormat objects.
646
"""The registered server format probers, e.g. RemoteBzrProber.
648
This is a list of Prober-derived classes.
652
"""The registered format probers, e.g. BzrProber.
654
This is a list of Prober-derived classes.
657
colocated_branches = False
658
"""Whether co-located branches are supported for this control dir format.
661
supports_workingtrees = True
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 same_model(self, target_format):
691
return (self.repository_format.rich_root_data ==
692
target_format.rich_root_data)
695
def register_format(klass, format):
696
"""Register a format that does not use '.bzr' for its control dir.
699
klass._formats.append(format)
702
def register_prober(klass, prober):
703
"""Register a prober that can look for a control dir.
706
klass._probers.append(prober)
709
def unregister_prober(klass, prober):
710
"""Unregister a prober.
713
klass._probers.remove(prober)
716
def register_server_prober(klass, prober):
717
"""Register a control format prober for client-server environments.
719
These probers will be used before ones registered with
720
register_prober. This gives implementations that decide to the
721
chance to grab it before anything looks at the contents of the format
724
klass._server_probers.append(prober)
728
return self.get_format_description().rstrip()
731
def unregister_format(klass, format):
732
klass._formats.remove(format)
735
def known_formats(klass):
736
"""Return all the known formats.
738
return set(klass._formats)
741
def find_format(klass, transport, _server_formats=True):
742
"""Return the format present at transport."""
744
_probers = klass._server_probers + klass._probers
746
_probers = klass._probers
747
for prober_kls in _probers:
748
prober = prober_kls()
750
return prober.probe_transport(transport)
751
except errors.NotBranchError:
752
# this format does not find a control dir here.
754
raise errors.NotBranchError(path=transport.base)
756
def initialize(self, url, possible_transports=None):
757
"""Create a control dir at this url and return an opened copy.
759
While not deprecated, this method is very specific and its use will
760
lead to many round trips to setup a working environment. See
761
initialize_on_transport_ex for a [nearly] all-in-one method.
763
Subclasses should typically override initialize_on_transport
764
instead of this method.
766
return self.initialize_on_transport(
767
_mod_transport.get_transport(url, possible_transports))
769
def initialize_on_transport(self, transport):
770
"""Initialize a new controldir in the base directory of a Transport."""
771
raise NotImplementedError(self.initialize_on_transport)
773
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
774
create_prefix=False, force_new_repo=False, stacked_on=None,
775
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
776
shared_repo=False, vfs_only=False):
777
"""Create this format on transport.
779
The directory to initialize will be created.
781
:param force_new_repo: Do not use a shared repository for the target,
782
even if one is available.
783
:param create_prefix: Create any missing directories leading up to
785
:param use_existing_dir: Use an existing directory if one exists.
786
:param stacked_on: A url to stack any created branch on, None to follow
787
any target stacking policy.
788
:param stack_on_pwd: If stack_on is relative, the location it is
790
:param repo_format_name: If non-None, a repository will be
791
made-or-found. Should none be found, or if force_new_repo is True
792
the repo_format_name is used to select the format of repository to
794
:param make_working_trees: Control the setting of make_working_trees
795
for a new shared repository when one is made. None to use whatever
796
default the format has.
797
:param shared_repo: Control whether made repositories are shared or
799
:param vfs_only: If True do not attempt to use a smart server
800
:return: repo, controldir, require_stacking, repository_policy. repo is
801
None if none was created or found, controldir is always valid.
802
require_stacking is the result of examining the stacked_on
803
parameter and any stacking policy found for the target.
805
raise NotImplementedError(self.initialize_on_transport_ex)
807
def network_name(self):
808
"""A simple byte string uniquely identifying this format for RPC calls.
810
Bzr control formats use this disk format string to identify the format
811
over the wire. Its possible that other control formats have more
812
complex detection requirements, so we permit them to use any unique and
813
immutable string they desire.
815
raise NotImplementedError(self.network_name)
817
def open(self, transport, _found=False):
818
"""Return an instance of this format for the dir transport points at.
820
raise NotImplementedError(self.open)
823
def _set_default_format(klass, format):
824
"""Set default format (for testing behavior of defaults only)"""
825
klass._default_format = format
828
def get_default_format(klass):
829
"""Return the current default format."""
830
return klass._default_format
833
class Prober(object):
834
"""Abstract class that can be used to detect a particular kind of
837
At the moment this just contains a single method to probe a particular
838
transport, but it may be extended in the future to e.g. avoid
839
multiple levels of probing for Subversion repositories.
842
def probe_transport(self, transport):
843
"""Return the controldir style format present in a directory.
845
:raise UnknownFormatError: If a control dir was found but is
846
in an unknown format.
847
:raise NotBranchError: If no control directory was found.
848
:return: A ControlDirFormat instance.
850
raise NotImplementedError(self.probe_transport)
853
class ControlDirFormatInfo(object):
855
def __init__(self, native, deprecated, hidden, experimental):
856
self.deprecated = deprecated
859
self.experimental = experimental
862
class ControlDirFormatRegistry(registry.Registry):
863
"""Registry of user-selectable ControlDir subformats.
865
Differs from ControlDirFormat._formats in that it provides sub-formats,
866
e.g. ControlDirMeta1 with weave repository. Also, it's more user-oriented.
870
"""Create a ControlDirFormatRegistry."""
871
self._aliases = set()
872
self._registration_order = list()
873
super(ControlDirFormatRegistry, self).__init__()
876
"""Return a set of the format names which are aliases."""
877
return frozenset(self._aliases)
879
def register(self, key, factory, help, native=True, deprecated=False,
880
hidden=False, experimental=False, alias=False):
881
"""Register a ControlDirFormat factory.
883
The factory must be a callable that takes one parameter: the key.
884
It must produce an instance of the ControlDirFormat when called.
886
This function mainly exists to prevent the info object from being
889
registry.Registry.register(self, key, factory, help,
890
ControlDirFormatInfo(native, deprecated, hidden, experimental))
892
self._aliases.add(key)
893
self._registration_order.append(key)
895
def register_lazy(self, key, module_name, member_name, help, native=True,
896
deprecated=False, hidden=False, experimental=False, alias=False):
897
registry.Registry.register_lazy(self, key, module_name, member_name,
898
help, ControlDirFormatInfo(native, deprecated, hidden, experimental))
900
self._aliases.add(key)
901
self._registration_order.append(key)
903
def set_default(self, key):
904
"""Set the 'default' key to be a clone of the supplied key.
906
This method must be called once and only once.
908
registry.Registry.register(self, 'default', self.get(key),
909
self.get_help(key), info=self.get_info(key))
910
self._aliases.add('default')
912
def set_default_repository(self, key):
913
"""Set the FormatRegistry default and Repository default.
915
This is a transitional method while Repository.set_default_format
918
if 'default' in self:
919
self.remove('default')
920
self.set_default(key)
921
format = self.get('default')()
923
def make_bzrdir(self, key):
924
return self.get(key)()
926
def help_topic(self, topic):
928
default_realkey = None
929
default_help = self.get_help('default')
931
for key in self._registration_order:
934
help = self.get_help(key)
935
if help == default_help:
936
default_realkey = key
938
help_pairs.append((key, help))
940
def wrapped(key, help, info):
942
help = '(native) ' + help
943
return ':%s:\n%s\n\n' % (key,
944
textwrap.fill(help, initial_indent=' ',
945
subsequent_indent=' ',
946
break_long_words=False))
947
if default_realkey is not None:
948
output += wrapped(default_realkey, '(default) %s' % default_help,
949
self.get_info('default'))
950
deprecated_pairs = []
951
experimental_pairs = []
952
for key, help in help_pairs:
953
info = self.get_info(key)
956
elif info.deprecated:
957
deprecated_pairs.append((key, help))
958
elif info.experimental:
959
experimental_pairs.append((key, help))
961
output += wrapped(key, help, info)
962
output += "\nSee :doc:`formats-help` for more about storage formats."
964
if len(experimental_pairs) > 0:
965
other_output += "Experimental formats are shown below.\n\n"
966
for key, help in experimental_pairs:
967
info = self.get_info(key)
968
other_output += wrapped(key, help, info)
971
"No experimental formats are available.\n\n"
972
if len(deprecated_pairs) > 0:
973
other_output += "\nDeprecated formats are shown below.\n\n"
974
for key, help in deprecated_pairs:
975
info = self.get_info(key)
976
other_output += wrapped(key, help, info)
979
"\nNo deprecated formats are available.\n\n"
981
"\nSee :doc:`formats-help` for more about storage formats."
983
if topic == 'other-formats':
989
# Please register new formats after old formats so that formats
990
# appear in chronological order and format descriptions can build
992
format_registry = ControlDirFormatRegistry()
994
network_format_registry = registry.FormatRegistry()
995
"""Registry of formats indexed by their network name.
997
The network name for a ControlDirFormat is an identifier that can be used when
998
referring to formats with smart server operations. See
999
ControlDirFormat.network_name() for more detail.