168
170
format.get_format_description(),
171
def clone(self, url, revision_id=None, force_new_repo=False,
172
preserve_stacking=False):
173
"""Clone this bzrdir and its contents to url verbatim.
175
:param url: The url create the clone at. If url's last component does
176
not exist, it will be created.
177
:param revision_id: The tip revision-id to use for any branch or
178
working tree. If not None, then the clone operation may tune
179
itself to download less data.
180
:param force_new_repo: Do not use a shared repository for the target
181
even if one is available.
182
:param preserve_stacking: When cloning a stacked branch, stack the
183
new branch on top of the other branch's stacked-on branch.
185
return self.clone_on_transport(get_transport(url),
186
revision_id=revision_id,
187
force_new_repo=force_new_repo,
188
preserve_stacking=preserve_stacking)
190
173
def clone_on_transport(self, transport, revision_id=None,
191
174
force_new_repo=False, preserve_stacking=False, stacked_on=None,
192
create_prefix=False, use_existing_dir=True):
175
create_prefix=False, use_existing_dir=True, no_tree=False):
193
176
"""Clone this bzrdir and its contents to transport verbatim.
195
178
:param transport: The transport for the location to produce the clone
371
336
except errors.NoRepositoryPresent:
374
return False, (None, repository)
376
branch = bzrdir.open_branch()
377
except errors.NotBranchError:
378
return True, (None, None)
380
return True, (branch, None)
382
for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
339
return False, ([], repository)
340
return True, (bzrdir.list_branches(), None)
342
for branches, repo in BzrDir.find_bzrdirs(transport,
383
344
if repo is not None:
384
branches.extend(repo.find_branches())
385
if branch is not None:
386
branches.append(branch)
389
def destroy_repository(self):
390
"""Destroy the repository in this BzrDir"""
391
raise NotImplementedError(self.destroy_repository)
393
def create_branch(self):
394
"""Create a branch in this BzrDir.
396
The bzrdir's format will control what branch format is created.
397
For more control see BranchFormatXX.create(a_bzrdir).
399
raise NotImplementedError(self.create_branch)
401
def destroy_branch(self):
402
"""Destroy the branch in this BzrDir"""
403
raise NotImplementedError(self.destroy_branch)
345
ret.extend(repo.find_branches())
346
if branches is not None:
406
351
def create_branch_and_repo(base, force_new_repo=False, format=None):
556
501
format=format).bzrdir
557
502
return bzrdir.create_workingtree()
559
def create_workingtree(self, revision_id=None, from_branch=None,
560
accelerator_tree=None, hardlink=False):
561
"""Create a working tree at this BzrDir.
563
:param revision_id: create it as of this revision id.
564
:param from_branch: override bzrdir branch (for lightweight checkouts)
565
:param accelerator_tree: A tree which can be used for retrieving file
566
contents more quickly than the revision tree, i.e. a workingtree.
567
The revision tree will be used for cases where accelerator_tree's
568
content is different.
504
@deprecated_method(deprecated_in((2, 3, 0)))
505
def generate_backup_name(self, base):
506
return self._available_backup_name(base)
508
def _available_backup_name(self, base):
509
"""Find a non-existing backup file name based on base.
511
See bzrlib.osutils.available_backup_name about race conditions.
570
raise NotImplementedError(self.create_workingtree)
513
return osutils.available_backup_name(base, self.root_transport.has)
572
515
def backup_bzrdir(self):
573
516
"""Backup this bzr control directory.
575
518
:return: Tuple with old path name and new path name
577
521
pb = ui.ui_factory.nested_progress_bar()
579
# FIXME: bug 300001 -- the backup fails if the backup directory
580
# already exists, but it should instead either remove it or make
581
# a new backup directory.
583
# FIXME: bug 262450 -- the backup directory should have the same
584
# permissions as the .bzr directory (probably a bug in copy_tree)
585
523
old_path = self.root_transport.abspath('.bzr')
586
new_path = self.root_transport.abspath('backup.bzr')
587
ui.ui_factory.note('making backup of %s\n to %s' % (old_path, new_path,))
588
self.root_transport.copy_tree('.bzr', 'backup.bzr')
524
backup_dir = self._available_backup_name('backup.bzr')
525
new_path = self.root_transport.abspath(backup_dir)
526
ui.ui_factory.note('making backup of %s\n to %s'
527
% (old_path, new_path,))
528
self.root_transport.copy_tree('.bzr', backup_dir)
589
529
return (old_path, new_path)
997
845
raise errors.NotBranchError(location)
998
846
return tree, branch, branch.repository, relpath
1000
def open_repository(self, _unsupported=False):
1001
"""Open the repository object at this BzrDir if one is present.
1003
This will not follow the Branch object pointer - it's strictly a direct
1004
open facility. Most client code should use open_branch().repository to
1005
get at a repository.
1007
:param _unsupported: a private parameter, not part of the api.
1008
TODO: static convenience version of this?
1010
raise NotImplementedError(self.open_repository)
1012
def open_workingtree(self, _unsupported=False,
1013
recommend_upgrade=True, from_branch=None):
1014
"""Open the workingtree object at this BzrDir if one is present.
1016
:param recommend_upgrade: Optional keyword parameter, when True (the
1017
default), emit through the ui module a recommendation that the user
1018
upgrade the working tree when the workingtree being opened is old
1019
(but still fully supported).
1020
:param from_branch: override bzrdir branch (for lightweight checkouts)
1022
raise NotImplementedError(self.open_workingtree)
1024
def has_branch(self):
1025
"""Tell if this bzrdir contains a branch.
1027
Note: if you're going to open the branch, you should just go ahead
1028
and try, and not ask permission first. (This method just opens the
1029
branch and discards it, and that's somewhat expensive.)
1034
except errors.NotBranchError:
1037
def has_workingtree(self):
1038
"""Tell if this bzrdir contains a working tree.
1040
This will still raise an exception if the bzrdir has a workingtree that
1041
is remote & inaccessible.
1043
Note: if you're going to open the working tree, you should just go ahead
1044
and try, and not ask permission first. (This method just opens the
1045
workingtree and discards it, and that's somewhat expensive.)
1048
self.open_workingtree(recommend_upgrade=False)
1050
except errors.NoWorkingTree:
1053
848
def _cloning_metadir(self):
1054
849
"""Produce a metadir suitable for cloning with.
1113
908
format.require_stacking()
1116
def checkout_metadir(self):
1117
return self.cloning_metadir()
1119
def sprout(self, url, revision_id=None, force_new_repo=False,
1120
recurse='down', possible_transports=None,
1121
accelerator_tree=None, hardlink=False, stacked=False,
1122
source_branch=None, create_tree_if_local=True):
1123
"""Create a copy of this bzrdir prepared for use as a new line of
1126
If url's last component does not exist, it will be created.
1128
Attributes related to the identity of the source branch like
1129
branch nickname will be cleaned, a working tree is created
1130
whether one existed before or not; and a local branch is always
1133
if revision_id is not None, then the clone operation may tune
1134
itself to download less data.
1135
:param accelerator_tree: A tree which can be used for retrieving file
1136
contents more quickly than the revision tree, i.e. a workingtree.
1137
The revision tree will be used for cases where accelerator_tree's
1138
content is different.
1139
:param hardlink: If true, hard-link files from accelerator_tree,
1141
:param stacked: If true, create a stacked branch referring to the
1142
location of this control directory.
1143
:param create_tree_if_local: If true, a working-tree will be created
1144
when working locally.
912
def create(cls, base, format=None, possible_transports=None):
913
"""Create a new BzrDir at the url 'base'.
915
:param format: If supplied, the format of branch to create. If not
916
supplied, the default is used.
917
:param possible_transports: If supplied, a list of transports that
918
can be reused to share a remote connection.
1146
target_transport = get_transport(url, possible_transports)
1147
target_transport.ensure_base()
1148
cloning_format = self.cloning_metadir(stacked)
1149
# Create/update the result branch
1150
result = cloning_format.initialize_on_transport(target_transport)
1151
# if a stacked branch wasn't requested, we don't create one
1152
# even if the origin was stacked
1153
stacked_branch_url = None
1154
if source_branch is not None:
1156
stacked_branch_url = self.root_transport.base
1157
source_repository = source_branch.repository
1160
source_branch = self.open_branch()
1161
source_repository = source_branch.repository
1163
stacked_branch_url = self.root_transport.base
1164
except errors.NotBranchError:
1165
source_branch = None
1167
source_repository = self.open_repository()
1168
except errors.NoRepositoryPresent:
1169
source_repository = None
1170
repository_policy = result.determine_repository_policy(
1171
force_new_repo, stacked_branch_url, require_stacking=stacked)
1172
result_repo, is_new_repo = repository_policy.acquire_repository()
1173
if is_new_repo and revision_id is not None and not stacked:
1174
fetch_spec = graph.PendingAncestryResult(
1175
[revision_id], source_repository)
1178
if source_repository is not None:
1179
# Fetch while stacked to prevent unstacked fetch from
1181
if fetch_spec is None:
1182
result_repo.fetch(source_repository, revision_id=revision_id)
1184
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1186
if source_branch is None:
1187
# this is for sprouting a bzrdir without a branch; is that
1189
# Not especially, but it's part of the contract.
1190
result_branch = result.create_branch()
1192
result_branch = source_branch.sprout(result,
1193
revision_id=revision_id, repository_policy=repository_policy)
1194
mutter("created new branch %r" % (result_branch,))
1196
# Create/update the result working tree
1197
if (create_tree_if_local and
1198
isinstance(target_transport, local.LocalTransport) and
1199
(result_repo is None or result_repo.make_working_trees())):
1200
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1204
if wt.path2id('') is None:
1206
wt.set_root_id(self.open_workingtree.get_root_id())
1207
except errors.NoWorkingTree:
1213
if recurse == 'down':
1215
basis = wt.basis_tree()
1217
subtrees = basis.iter_references()
1218
elif result_branch is not None:
1219
basis = result_branch.basis_tree()
1221
subtrees = basis.iter_references()
1222
elif source_branch is not None:
1223
basis = source_branch.basis_tree()
1225
subtrees = basis.iter_references()
1230
for path, file_id in subtrees:
1231
target = urlutils.join(url, urlutils.escape(path))
1232
sublocation = source_branch.reference_parent(file_id, path)
1233
sublocation.bzrdir.sprout(target,
1234
basis.get_reference_revision(file_id, path),
1235
force_new_repo=force_new_repo, recurse=recurse,
1238
if basis is not None:
1242
def push_branch(self, source, revision_id=None, overwrite=False,
1243
remember=False, create_prefix=False):
1244
"""Push the source branch into this BzrDir."""
1246
# If we can open a branch, use its direct repository, otherwise see
1247
# if there is a repository without a branch.
1249
br_to = self.open_branch()
1250
except errors.NotBranchError:
1251
# Didn't find a branch, can we find a repository?
1252
repository_to = self.find_repository()
1254
# Found a branch, so we must have found a repository
1255
repository_to = br_to.repository
1257
push_result = PushResult()
1258
push_result.source_branch = source
1260
# We have a repository but no branch, copy the revisions, and then
1262
repository_to.fetch(source.repository, revision_id=revision_id)
1263
br_to = source.clone(self, revision_id=revision_id)
1264
if source.get_push_location() is None or remember:
1265
source.set_push_location(br_to.base)
1266
push_result.stacked_on = None
1267
push_result.branch_push_result = None
1268
push_result.old_revno = None
1269
push_result.old_revid = _mod_revision.NULL_REVISION
1270
push_result.target_branch = br_to
1271
push_result.master_branch = None
1272
push_result.workingtree_updated = False
1274
# We have successfully opened the branch, remember if necessary:
1275
if source.get_push_location() is None or remember:
1276
source.set_push_location(br_to.base)
1278
tree_to = self.open_workingtree()
1279
except errors.NotLocalUrl:
1280
push_result.branch_push_result = source.push(br_to,
1281
overwrite, stop_revision=revision_id)
1282
push_result.workingtree_updated = False
1283
except errors.NoWorkingTree:
1284
push_result.branch_push_result = source.push(br_to,
1285
overwrite, stop_revision=revision_id)
1286
push_result.workingtree_updated = None # Not applicable
1288
tree_to.lock_write()
1290
push_result.branch_push_result = source.push(
1291
tree_to.branch, overwrite, stop_revision=revision_id)
1295
push_result.workingtree_updated = True
1296
push_result.old_revno = push_result.branch_push_result.old_revno
1297
push_result.old_revid = push_result.branch_push_result.old_revid
1298
push_result.target_branch = \
1299
push_result.branch_push_result.target_branch
920
if cls is not BzrDir:
921
raise AssertionError("BzrDir.create always creates the"
922
"default format, not one of %r" % cls)
923
t = get_transport(base, possible_transports)
926
format = controldir.ControlDirFormat.get_default_format()
927
return format.initialize_on_transport(t)
1303
931
class BzrDirHooks(hooks.Hooks):
1309
937
self.create_hook(hooks.HookPoint('pre_open',
1310
938
"Invoked before attempting to open a BzrDir with the transport "
1311
939
"that the open will use.", (1, 14), None))
940
self.create_hook(hooks.HookPoint('post_repo_init',
941
"Invoked after a repository has been initialized. "
942
"post_repo_init is called with a "
943
"bzrlib.bzrdir.RepoInitHookParams.",
1313
946
# install the default hooks
1314
947
BzrDir.hooks = BzrDirHooks()
950
class RepoInitHookParams(object):
951
"""Object holding parameters passed to *_repo_init hooks.
953
There are 4 fields that hooks may wish to access:
955
:ivar repository: Repository created
956
:ivar format: Repository format
957
:ivar bzrdir: The bzrdir for the repository
958
:ivar shared: The repository is shared
961
def __init__(self, repository, format, a_bzrdir, shared):
962
"""Create a group of RepoInitHook parameters.
964
:param repository: Repository created
965
:param format: Repository format
966
:param bzrdir: The bzrdir for the repository
967
:param shared: The repository is shared
969
self.repository = repository
971
self.bzrdir = a_bzrdir
974
def __eq__(self, other):
975
return self.__dict__ == other.__dict__
979
return "<%s for %s>" % (self.__class__.__name__,
982
return "<%s for %s>" % (self.__class__.__name__,
1317
986
class BzrDirPreSplitOut(BzrDir):
1318
987
"""A common class for the all-in-one formats."""
1768
1447
return config.TransportConfig(self.transport, 'control.conf')
1771
class BzrDirFormat(object):
1772
"""An encapsulation of the initialization and open routines for a format.
1774
Formats provide three things:
1775
* An initialization routine,
1450
class BzrProber(controldir.Prober):
1451
"""Prober for formats that use a .bzr/ control directory."""
1454
"""The known .bzr formats."""
1457
def register_bzrdir_format(klass, format):
1458
klass._formats[format.get_format_string()] = format
1461
def unregister_bzrdir_format(klass, format):
1462
del klass._formats[format.get_format_string()]
1465
def probe_transport(klass, transport):
1466
"""Return the .bzrdir style format present in a directory."""
1468
format_string = transport.get_bytes(".bzr/branch-format")
1469
except errors.NoSuchFile:
1470
raise errors.NotBranchError(path=transport.base)
1472
return klass._formats[format_string]
1474
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1477
controldir.ControlDirFormat.register_prober(BzrProber)
1480
class RemoteBzrProber(controldir.Prober):
1481
"""Prober for remote servers that provide a Bazaar smart server."""
1484
def probe_transport(klass, transport):
1485
"""Return a RemoteBzrDirFormat object if it looks possible."""
1487
medium = transport.get_smart_medium()
1488
except (NotImplementedError, AttributeError,
1489
errors.TransportNotPossible, errors.NoSmartMedium,
1490
errors.SmartProtocolError):
1491
# no smart server, so not a branch for this format type.
1492
raise errors.NotBranchError(path=transport.base)
1494
# Decline to open it if the server doesn't support our required
1495
# version (3) so that the VFS-based transport will do it.
1496
if medium.should_probe():
1498
server_version = medium.protocol_version()
1499
except errors.SmartProtocolError:
1500
# Apparently there's no usable smart server there, even though
1501
# the medium supports the smart protocol.
1502
raise errors.NotBranchError(path=transport.base)
1503
if server_version != '2':
1504
raise errors.NotBranchError(path=transport.base)
1505
return RemoteBzrDirFormat()
1508
class BzrDirFormat(controldir.ControlDirFormat):
1509
"""ControlDirFormat base class for .bzr/ directories.
1779
1511
Formats are placed in a dict by their format string for reference
1780
1512
during bzrdir opening. These should be subclasses of BzrDirFormat
1785
1517
object will be created every system load.
1788
_default_format = None
1789
"""The default format used for new .bzr dirs."""
1792
"""The known formats."""
1794
_control_formats = []
1795
"""The registered control formats - .bzr, ....
1797
This is a list of BzrDirFormat objects.
1800
_control_server_formats = []
1801
"""The registered control server formats, e.g. RemoteBzrDirs.
1803
This is a list of BzrDirFormat objects.
1806
1520
_lock_file_name = 'branch-lock'
1808
1522
# _lock_class must be set in subclasses to the lock type, typ.
1809
1523
# TransportLock or LockDir
1812
def find_format(klass, transport, _server_formats=True):
1813
"""Return the format present at transport."""
1815
formats = klass._control_server_formats + klass._control_formats
1817
formats = klass._control_formats
1818
for format in formats:
1820
return format.probe_transport(transport)
1821
except errors.NotBranchError:
1822
# this format does not find a control dir here.
1824
raise errors.NotBranchError(path=transport.base)
1827
def probe_transport(klass, transport):
1828
"""Return the .bzrdir style format present in a directory."""
1830
format_string = transport.get_bytes(".bzr/branch-format")
1831
except errors.NoSuchFile:
1832
raise errors.NotBranchError(path=transport.base)
1835
return klass._formats[format_string]
1837
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1840
def get_default_format(klass):
1841
"""Return the current default format."""
1842
return klass._default_format
1844
1525
def get_format_string(self):
1845
1526
"""Return the ASCII format string that identifies this format."""
1846
1527
raise NotImplementedError(self.get_format_string)
1848
def get_format_description(self):
1849
"""Return the short description for this format."""
1850
raise NotImplementedError(self.get_format_description)
1852
def get_converter(self, format=None):
1853
"""Return the converter to use to convert bzrdirs needing converts.
1855
This returns a bzrlib.bzrdir.Converter object.
1857
This should return the best upgrader to step this format towards the
1858
current default format. In the case of plugins we can/should provide
1859
some means for them to extend the range of returnable converters.
1861
:param format: Optional format to override the default format of the
1864
raise NotImplementedError(self.get_converter)
1866
def initialize(self, url, possible_transports=None):
1867
"""Create a bzr control dir at this url and return an opened copy.
1869
While not deprecated, this method is very specific and its use will
1870
lead to many round trips to setup a working environment. See
1871
initialize_on_transport_ex for a [nearly] all-in-one method.
1873
Subclasses should typically override initialize_on_transport
1874
instead of this method.
1876
return self.initialize_on_transport(get_transport(url,
1877
possible_transports))
1879
1529
def initialize_on_transport(self, transport):
1880
1530
"""Initialize a new bzrdir in the base directory of a Transport."""
2029
1679
control_files.unlock()
2030
1680
return self.open(transport, _found=True)
2032
def is_supported(self):
2033
"""Is this format supported?
2035
Supported formats must be initializable and openable.
2036
Unsupported formats may not support initialization or committing or
2037
some other features depending on the reason for not being supported.
2041
def network_name(self):
2042
"""A simple byte string uniquely identifying this format for RPC calls.
2044
Bzr control formats use thir disk format string to identify the format
2045
over the wire. Its possible that other control formats have more
2046
complex detection requirements, so we permit them to use any unique and
2047
immutable string they desire.
2049
raise NotImplementedError(self.network_name)
2051
def same_model(self, target_format):
2052
return (self.repository_format.rich_root_data ==
2053
target_format.rich_root_data)
2056
def known_formats(klass):
2057
"""Return all the known formats.
2059
Concrete formats should override _known_formats.
2061
# There is double indirection here to make sure that control
2062
# formats used by more than one dir format will only be probed
2063
# once. This can otherwise be quite expensive for remote connections.
2065
for format in klass._control_formats:
2066
result.update(format._known_formats())
2070
def _known_formats(klass):
2071
"""Return the known format instances for this control format."""
2072
return set(klass._formats.values())
2074
1682
def open(self, transport, _found=False):
2075
1683
"""Return an instance of this format for the dir transport points at.
2077
1685
_found is a private parameter, do not use it.
2080
found_format = BzrDirFormat.find_format(transport)
1688
found_format = controldir.ControlDirFormat.find_format(transport)
2081
1689
if not isinstance(found_format, self.__class__):
2082
1690
raise AssertionError("%s was asked to open %s, but it seems to need "
2099
1707
def register_format(klass, format):
2100
klass._formats[format.get_format_string()] = format
1708
BzrProber.register_bzrdir_format(format)
2101
1709
# bzr native formats have a network name of their format string.
2102
network_format_registry.register(format.get_format_string(), format.__class__)
2105
def register_control_format(klass, format):
2106
"""Register a format that does not use '.bzr' for its control dir.
2108
TODO: This should be pulled up into a 'ControlDirFormat' base class
2109
which BzrDirFormat can inherit from, and renamed to register_format
2110
there. It has been done without that for now for simplicity of
2113
klass._control_formats.append(format)
2116
def register_control_server_format(klass, format):
2117
"""Register a control format for client-server environments.
2119
These formats will be tried before ones registered with
2120
register_control_format. This gives implementations that decide to the
2121
chance to grab it before anything looks at the contents of the format
2124
klass._control_server_formats.append(format)
2127
def _set_default_format(klass, format):
2128
"""Set default format (for testing behavior of defaults only)"""
2129
klass._default_format = format
2133
return self.get_format_description().rstrip()
1710
controldir.network_format_registry.register(format.get_format_string(), format.__class__)
1711
controldir.ControlDirFormat.register_format(format)
2135
1713
def _supply_sub_formats_to(self, other_format):
2136
1714
"""Give other_format the same values for sub formats as this has.
3361
2915
BzrDirMetaFormat1._set_repository_format) #.im_func)
3364
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
3367
class BzrDirFormatInfo(object):
3369
def __init__(self, native, deprecated, hidden, experimental):
3370
self.deprecated = deprecated
3371
self.native = native
3372
self.hidden = hidden
3373
self.experimental = experimental
3376
class BzrDirFormatRegistry(registry.Registry):
3377
"""Registry of user-selectable BzrDir subformats.
3379
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
3380
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
3384
"""Create a BzrDirFormatRegistry."""
3385
self._aliases = set()
3386
self._registration_order = list()
3387
super(BzrDirFormatRegistry, self).__init__()
3390
"""Return a set of the format names which are aliases."""
3391
return frozenset(self._aliases)
3393
def register_metadir(self, key,
3394
repository_format, help, native=True, deprecated=False,
3400
"""Register a metadir subformat.
3402
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3403
by the Repository/Branch/WorkingTreeformats.
3405
:param repository_format: The fully-qualified repository format class
3407
:param branch_format: Fully-qualified branch format class name as
3409
:param tree_format: Fully-qualified tree format class name as
3412
# This should be expanded to support setting WorkingTree and Branch
3413
# formats, once BzrDirMetaFormat1 supports that.
3414
def _load(full_name):
3415
mod_name, factory_name = full_name.rsplit('.', 1)
3417
mod = __import__(mod_name, globals(), locals(),
3419
except ImportError, e:
3420
raise ImportError('failed to load %s: %s' % (full_name, e))
3422
factory = getattr(mod, factory_name)
3423
except AttributeError:
3424
raise AttributeError('no factory %s in module %r'
3429
bd = BzrDirMetaFormat1()
3430
if branch_format is not None:
3431
bd.set_branch_format(_load(branch_format))
3432
if tree_format is not None:
3433
bd.workingtree_format = _load(tree_format)
3434
if repository_format is not None:
3435
bd.repository_format = _load(repository_format)
3437
self.register(key, helper, help, native, deprecated, hidden,
3438
experimental, alias)
3440
def register(self, key, factory, help, native=True, deprecated=False,
3441
hidden=False, experimental=False, alias=False):
3442
"""Register a BzrDirFormat factory.
3444
The factory must be a callable that takes one parameter: the key.
3445
It must produce an instance of the BzrDirFormat when called.
3447
This function mainly exists to prevent the info object from being
3450
registry.Registry.register(self, key, factory, help,
3451
BzrDirFormatInfo(native, deprecated, hidden, experimental))
3453
self._aliases.add(key)
3454
self._registration_order.append(key)
3456
def register_lazy(self, key, module_name, member_name, help, native=True,
3457
deprecated=False, hidden=False, experimental=False, alias=False):
3458
registry.Registry.register_lazy(self, key, module_name, member_name,
3459
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
3461
self._aliases.add(key)
3462
self._registration_order.append(key)
3464
def set_default(self, key):
3465
"""Set the 'default' key to be a clone of the supplied key.
3467
This method must be called once and only once.
3469
registry.Registry.register(self, 'default', self.get(key),
3470
self.get_help(key), info=self.get_info(key))
3471
self._aliases.add('default')
3473
def set_default_repository(self, key):
3474
"""Set the FormatRegistry default and Repository default.
3476
This is a transitional method while Repository.set_default_format
3479
if 'default' in self:
3480
self.remove('default')
3481
self.set_default(key)
3482
format = self.get('default')()
3484
def make_bzrdir(self, key):
3485
return self.get(key)()
3487
def help_topic(self, topic):
3489
default_realkey = None
3490
default_help = self.get_help('default')
3492
for key in self._registration_order:
3493
if key == 'default':
3495
help = self.get_help(key)
3496
if help == default_help:
3497
default_realkey = key
3499
help_pairs.append((key, help))
3501
def wrapped(key, help, info):
3503
help = '(native) ' + help
3504
return ':%s:\n%s\n\n' % (key,
3505
textwrap.fill(help, initial_indent=' ',
3506
subsequent_indent=' ',
3507
break_long_words=False))
3508
if default_realkey is not None:
3509
output += wrapped(default_realkey, '(default) %s' % default_help,
3510
self.get_info('default'))
3511
deprecated_pairs = []
3512
experimental_pairs = []
3513
for key, help in help_pairs:
3514
info = self.get_info(key)
3517
elif info.deprecated:
3518
deprecated_pairs.append((key, help))
3519
elif info.experimental:
3520
experimental_pairs.append((key, help))
3522
output += wrapped(key, help, info)
3523
output += "\nSee :doc:`formats-help` for more about storage formats."
3525
if len(experimental_pairs) > 0:
3526
other_output += "Experimental formats are shown below.\n\n"
3527
for key, help in experimental_pairs:
3528
info = self.get_info(key)
3529
other_output += wrapped(key, help, info)
3532
"No experimental formats are available.\n\n"
3533
if len(deprecated_pairs) > 0:
3534
other_output += "\nDeprecated formats are shown below.\n\n"
3535
for key, help in deprecated_pairs:
3536
info = self.get_info(key)
3537
other_output += wrapped(key, help, info)
3540
"\nNo deprecated formats are available.\n\n"
3542
"\nSee :doc:`formats-help` for more about storage formats."
3544
if topic == 'other-formats':
2918
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
3550
2921
class RepositoryAcquisitionPolicy(object):
3704
3075
return self._repository, False
3707
# Please register new formats after old formats so that formats
3708
# appear in chronological order and format descriptions can build
3710
format_registry = BzrDirFormatRegistry()
3078
def register_metadir(registry, key,
3079
repository_format, help, native=True, deprecated=False,
3085
"""Register a metadir subformat.
3087
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3088
by the Repository/Branch/WorkingTreeformats.
3090
:param repository_format: The fully-qualified repository format class
3092
:param branch_format: Fully-qualified branch format class name as
3094
:param tree_format: Fully-qualified tree format class name as
3097
# This should be expanded to support setting WorkingTree and Branch
3098
# formats, once BzrDirMetaFormat1 supports that.
3099
def _load(full_name):
3100
mod_name, factory_name = full_name.rsplit('.', 1)
3102
factory = pyutils.get_named_object(mod_name, factory_name)
3103
except ImportError, e:
3104
raise ImportError('failed to load %s: %s' % (full_name, e))
3105
except AttributeError:
3106
raise AttributeError('no factory %s in module %r'
3107
% (full_name, sys.modules[mod_name]))
3111
bd = BzrDirMetaFormat1()
3112
if branch_format is not None:
3113
bd.set_branch_format(_load(branch_format))
3114
if tree_format is not None:
3115
bd.workingtree_format = _load(tree_format)
3116
if repository_format is not None:
3117
bd.repository_format = _load(repository_format)
3119
registry.register(key, helper, help, native, deprecated, hidden,
3120
experimental, alias)
3711
3122
# The pre-0.8 formats have their repository format network name registered in
3712
3123
# repository.py. MetaDir formats have their repository format network name
3713
3124
# inferred from their disk format string.
3714
format_registry.register('weave', BzrDirFormat6,
3125
controldir.format_registry.register('weave', BzrDirFormat6,
3715
3126
'Pre-0.8 format. Slower than knit and does not'
3716
3127
' support checkouts or shared repositories.',
3718
3129
deprecated=True)
3719
format_registry.register_metadir('metaweave',
3130
register_metadir(controldir.format_registry, 'metaweave',
3720
3131
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3721
3132
'Transitional format in 0.8. Slower than knit.',
3722
3133
branch_format='bzrlib.branch.BzrBranchFormat5',
3723
3134
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3725
3136
deprecated=True)
3726
format_registry.register_metadir('knit',
3137
register_metadir(controldir.format_registry, 'knit',
3727
3138
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3728
3139
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3729
3140
branch_format='bzrlib.branch.BzrBranchFormat5',
3730
3141
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3732
3143
deprecated=True)
3733
format_registry.register_metadir('dirstate',
3144
register_metadir(controldir.format_registry, 'dirstate',
3734
3145
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3735
3146
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3736
3147
'above when accessed over the network.',
3873
3270
# This current non-alias status is simply because we did not introduce a
3874
3271
# chk based subtree format.
3273
register_metadir(controldir.format_registry, 'development5-subtree',
3274
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3275
help='Development format, subtree variant. Can convert data to and '
3276
'from pack-0.92-subtree (and anything compatible with '
3277
'pack-0.92-subtree) format repositories. Repositories and branches in '
3278
'this format can only be read by bzr.dev. Please read '
3279
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3281
branch_format='bzrlib.branch.BzrBranchFormat7',
3282
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3877
3288
# And the development formats above will have aliased one of the following:
3878
format_registry.register_metadir('development6-rich-root',
3879
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3880
help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3882
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3884
branch_format='bzrlib.branch.BzrBranchFormat7',
3885
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3890
format_registry.register_metadir('development7-rich-root',
3891
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK2',
3892
help='pack-1.9 with 255-way hashed CHK inv, bencode revision, group compress, '
3893
'rich roots. Please read '
3894
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3896
branch_format='bzrlib.branch.BzrBranchFormat7',
3897
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3902
format_registry.register_metadir('2a',
3290
# Finally, the current format.
3291
register_metadir(controldir.format_registry, '2a',
3903
3292
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2a',
3904
3293
help='First format for bzr 2.0 series.\n'
3905
3294
'Uses group-compress storage.\n'