331
363
except errors.NoRepositoryPresent:
334
return False, ([], repository)
335
return True, (bzrdir.list_branches(), None)
337
for branches, repo in BzrDir.find_bzrdirs(transport,
366
return False, (None, repository)
368
branch = bzrdir.open_branch()
369
except errors.NotBranchError:
370
return True, (None, None)
372
return True, (branch, None)
374
for branch, repo in BzrDir.find_bzrdirs(transport, evaluate=evaluate):
339
375
if repo is not None:
340
ret.extend(repo.find_branches())
341
if branches is not None:
376
branches.extend(repo.find_branches())
377
if branch is not None:
378
branches.append(branch)
381
def destroy_repository(self):
382
"""Destroy the repository in this BzrDir"""
383
raise NotImplementedError(self.destroy_repository)
385
def create_branch(self):
386
"""Create a branch in this BzrDir.
388
The bzrdir's format will control what branch format is created.
389
For more control see BranchFormatXX.create(a_bzrdir).
391
raise NotImplementedError(self.create_branch)
393
def destroy_branch(self):
394
"""Destroy the branch in this BzrDir"""
395
raise NotImplementedError(self.destroy_branch)
346
398
def create_branch_and_repo(base, force_new_repo=False, format=None):
496
548
format=format).bzrdir
497
549
return bzrdir.create_workingtree()
499
def generate_backup_name(self, base):
500
"""Generate a non-existing backup file name based on base."""
502
name = "%s.~%d~" % (base, counter)
503
while self.root_transport.has(name):
505
name = "%s.~%d~" % (base, counter)
551
def create_workingtree(self, revision_id=None, from_branch=None,
552
accelerator_tree=None, hardlink=False):
553
"""Create a working tree at this BzrDir.
555
:param revision_id: create it as of this revision id.
556
:param from_branch: override bzrdir branch (for lightweight checkouts)
557
:param accelerator_tree: A tree which can be used for retrieving file
558
contents more quickly than the revision tree, i.e. a workingtree.
559
The revision tree will be used for cases where accelerator_tree's
560
content is different.
562
raise NotImplementedError(self.create_workingtree)
508
564
def backup_bzrdir(self):
509
565
"""Backup this bzr control directory.
511
567
:return: Tuple with old path name and new path name
514
backup_dir=self.generate_backup_name('backup.bzr')
515
569
pb = ui.ui_factory.nested_progress_bar()
517
571
# FIXME: bug 300001 -- the backup fails if the backup directory
518
572
# already exists, but it should instead either remove it or make
519
573
# a new backup directory.
575
# FIXME: bug 262450 -- the backup directory should have the same
576
# permissions as the .bzr directory (probably a bug in copy_tree)
521
577
old_path = self.root_transport.abspath('.bzr')
522
new_path = self.root_transport.abspath(backup_dir)
523
ui.ui_factory.note('making backup of %s\n to %s' % (old_path, new_path,))
524
self.root_transport.copy_tree('.bzr', backup_dir)
578
new_path = self.root_transport.abspath('backup.bzr')
579
pb.note('making backup of %s' % (old_path,))
580
pb.note(' to %s' % (new_path,))
581
self.root_transport.copy_tree('.bzr', 'backup.bzr')
525
582
return (old_path, new_path)
841
990
raise errors.NotBranchError(location)
842
991
return tree, branch, branch.repository, relpath
993
def open_repository(self, _unsupported=False):
994
"""Open the repository object at this BzrDir if one is present.
996
This will not follow the Branch object pointer - it's strictly a direct
997
open facility. Most client code should use open_branch().repository to
1000
:param _unsupported: a private parameter, not part of the api.
1001
TODO: static convenience version of this?
1003
raise NotImplementedError(self.open_repository)
1005
def open_workingtree(self, _unsupported=False,
1006
recommend_upgrade=True, from_branch=None):
1007
"""Open the workingtree object at this BzrDir if one is present.
1009
:param recommend_upgrade: Optional keyword parameter, when True (the
1010
default), emit through the ui module a recommendation that the user
1011
upgrade the working tree when the workingtree being opened is old
1012
(but still fully supported).
1013
:param from_branch: override bzrdir branch (for lightweight checkouts)
1015
raise NotImplementedError(self.open_workingtree)
1017
def has_branch(self):
1018
"""Tell if this bzrdir contains a branch.
1020
Note: if you're going to open the branch, you should just go ahead
1021
and try, and not ask permission first. (This method just opens the
1022
branch and discards it, and that's somewhat expensive.)
1027
except errors.NotBranchError:
1030
def has_workingtree(self):
1031
"""Tell if this bzrdir contains a working tree.
1033
This will still raise an exception if the bzrdir has a workingtree that
1034
is remote & inaccessible.
1036
Note: if you're going to open the working tree, you should just go ahead
1037
and try, and not ask permission first. (This method just opens the
1038
workingtree and discards it, and that's somewhat expensive.)
1041
self.open_workingtree(recommend_upgrade=False)
1043
except errors.NoWorkingTree:
844
1046
def _cloning_metadir(self):
845
1047
"""Produce a metadir suitable for cloning with.
904
1106
format.require_stacking()
908
def create(cls, base, format=None, possible_transports=None):
909
"""Create a new BzrDir at the url 'base'.
911
:param format: If supplied, the format of branch to create. If not
912
supplied, the default is used.
913
:param possible_transports: If supplied, a list of transports that
914
can be reused to share a remote connection.
1109
def checkout_metadir(self):
1110
return self.cloning_metadir()
1112
def sprout(self, url, revision_id=None, force_new_repo=False,
1113
recurse='down', possible_transports=None,
1114
accelerator_tree=None, hardlink=False, stacked=False,
1115
source_branch=None, create_tree_if_local=True):
1116
"""Create a copy of this bzrdir prepared for use as a new line of
1119
If url's last component does not exist, it will be created.
1121
Attributes related to the identity of the source branch like
1122
branch nickname will be cleaned, a working tree is created
1123
whether one existed before or not; and a local branch is always
1126
if revision_id is not None, then the clone operation may tune
1127
itself to download less data.
1128
:param accelerator_tree: A tree which can be used for retrieving file
1129
contents more quickly than the revision tree, i.e. a workingtree.
1130
The revision tree will be used for cases where accelerator_tree's
1131
content is different.
1132
:param hardlink: If true, hard-link files from accelerator_tree,
1134
:param stacked: If true, create a stacked branch referring to the
1135
location of this control directory.
1136
:param create_tree_if_local: If true, a working-tree will be created
1137
when working locally.
916
if cls is not BzrDir:
917
raise AssertionError("BzrDir.create always creates the"
918
"default format, not one of %r" % cls)
919
t = get_transport(base, possible_transports)
922
format = controldir.ControlDirFormat.get_default_format()
923
return format.initialize_on_transport(t)
1139
target_transport = get_transport(url, possible_transports)
1140
target_transport.ensure_base()
1141
cloning_format = self.cloning_metadir(stacked)
1142
# Create/update the result branch
1143
result = cloning_format.initialize_on_transport(target_transport)
1144
# if a stacked branch wasn't requested, we don't create one
1145
# even if the origin was stacked
1146
stacked_branch_url = None
1147
if source_branch is not None:
1149
stacked_branch_url = self.root_transport.base
1150
source_repository = source_branch.repository
1153
source_branch = self.open_branch()
1154
source_repository = source_branch.repository
1156
stacked_branch_url = self.root_transport.base
1157
except errors.NotBranchError:
1158
source_branch = None
1160
source_repository = self.open_repository()
1161
except errors.NoRepositoryPresent:
1162
source_repository = None
1163
repository_policy = result.determine_repository_policy(
1164
force_new_repo, stacked_branch_url, require_stacking=stacked)
1165
result_repo, is_new_repo = repository_policy.acquire_repository()
1166
if is_new_repo and revision_id is not None and not stacked:
1167
fetch_spec = graph.PendingAncestryResult(
1168
[revision_id], source_repository)
1171
if source_repository is not None:
1172
# Fetch while stacked to prevent unstacked fetch from
1174
if fetch_spec is None:
1175
result_repo.fetch(source_repository, revision_id=revision_id)
1177
result_repo.fetch(source_repository, fetch_spec=fetch_spec)
1179
if source_branch is None:
1180
# this is for sprouting a bzrdir without a branch; is that
1182
# Not especially, but it's part of the contract.
1183
result_branch = result.create_branch()
1185
result_branch = source_branch.sprout(result,
1186
revision_id=revision_id, repository_policy=repository_policy)
1187
mutter("created new branch %r" % (result_branch,))
1189
# Create/update the result working tree
1190
if (create_tree_if_local and
1191
isinstance(target_transport, local.LocalTransport) and
1192
(result_repo is None or result_repo.make_working_trees())):
1193
wt = result.create_workingtree(accelerator_tree=accelerator_tree,
1197
if wt.path2id('') is None:
1199
wt.set_root_id(self.open_workingtree.get_root_id())
1200
except errors.NoWorkingTree:
1206
if recurse == 'down':
1208
basis = wt.basis_tree()
1210
subtrees = basis.iter_references()
1211
elif result_branch is not None:
1212
basis = result_branch.basis_tree()
1214
subtrees = basis.iter_references()
1215
elif source_branch is not None:
1216
basis = source_branch.basis_tree()
1218
subtrees = basis.iter_references()
1223
for path, file_id in subtrees:
1224
target = urlutils.join(url, urlutils.escape(path))
1225
sublocation = source_branch.reference_parent(file_id, path)
1226
sublocation.bzrdir.sprout(target,
1227
basis.get_reference_revision(file_id, path),
1228
force_new_repo=force_new_repo, recurse=recurse,
1231
if basis is not None:
1235
def push_branch(self, source, revision_id=None, overwrite=False,
1237
"""Push the source branch into this BzrDir."""
1239
# If we can open a branch, use its direct repository, otherwise see
1240
# if there is a repository without a branch.
1242
br_to = self.open_branch()
1243
except errors.NotBranchError:
1244
# Didn't find a branch, can we find a repository?
1245
repository_to = self.find_repository()
1247
# Found a branch, so we must have found a repository
1248
repository_to = br_to.repository
1250
push_result = PushResult()
1251
push_result.source_branch = source
1253
# We have a repository but no branch, copy the revisions, and then
1255
repository_to.fetch(source.repository, revision_id=revision_id)
1256
br_to = source.clone(self, revision_id=revision_id)
1257
if source.get_push_location() is None or remember:
1258
source.set_push_location(br_to.base)
1259
push_result.stacked_on = None
1260
push_result.branch_push_result = None
1261
push_result.old_revno = None
1262
push_result.old_revid = _mod_revision.NULL_REVISION
1263
push_result.target_branch = br_to
1264
push_result.master_branch = None
1265
push_result.workingtree_updated = False
1267
# We have successfully opened the branch, remember if necessary:
1268
if source.get_push_location() is None or remember:
1269
source.set_push_location(br_to.base)
1271
tree_to = self.open_workingtree()
1272
except errors.NotLocalUrl:
1273
push_result.branch_push_result = source.push(br_to,
1274
overwrite, stop_revision=revision_id)
1275
push_result.workingtree_updated = False
1276
except errors.NoWorkingTree:
1277
push_result.branch_push_result = source.push(br_to,
1278
overwrite, stop_revision=revision_id)
1279
push_result.workingtree_updated = None # Not applicable
1281
tree_to.lock_write()
1283
push_result.branch_push_result = source.push(
1284
tree_to.branch, overwrite, stop_revision=revision_id)
1288
push_result.workingtree_updated = True
1289
push_result.old_revno = push_result.branch_push_result.old_revno
1290
push_result.old_revid = push_result.branch_push_result.old_revid
1291
push_result.target_branch = \
1292
push_result.branch_push_result.target_branch
927
1296
class BzrDirHooks(hooks.Hooks):
933
1302
self.create_hook(hooks.HookPoint('pre_open',
934
1303
"Invoked before attempting to open a BzrDir with the transport "
935
1304
"that the open will use.", (1, 14), None))
936
self.create_hook(hooks.HookPoint('post_repo_init',
937
"Invoked after a repository has been initialized. "
938
"post_repo_init is called with a "
939
"bzrlib.bzrdir.RepoInitHookParams.",
942
1306
# install the default hooks
943
1307
BzrDir.hooks = BzrDirHooks()
946
class RepoInitHookParams(object):
947
"""Object holding parameters passed to *_repo_init hooks.
949
There are 4 fields that hooks may wish to access:
951
:ivar repository: Repository created
952
:ivar format: Repository format
953
:ivar bzrdir: The bzrdir for the repository
954
:ivar shared: The repository is shared
957
def __init__(self, repository, format, a_bzrdir, shared):
958
"""Create a group of RepoInitHook parameters.
960
:param repository: Repository created
961
:param format: Repository format
962
:param bzrdir: The bzrdir for the repository
963
:param shared: The repository is shared
965
self.repository = repository
967
self.bzrdir = a_bzrdir
970
def __eq__(self, other):
971
return self.__dict__ == other.__dict__
975
return "<%s for %s>" % (self.__class__.__name__,
978
return "<%s for %s>" % (self.__class__.__name__,
982
1310
class BzrDirPreSplitOut(BzrDir):
983
1311
"""A common class for the all-in-one formats."""
1440
1732
return config.TransportConfig(self.transport, 'control.conf')
1443
class BzrProber(controldir.Prober):
1444
"""Prober for formats that use a .bzr/ control directory."""
1447
"""The known .bzr formats."""
1450
def register_bzrdir_format(klass, format):
1451
klass._formats[format.get_format_string()] = format
1454
def unregister_bzrdir_format(klass, format):
1455
del klass._formats[format.get_format_string()]
1458
def probe_transport(klass, transport):
1459
"""Return the .bzrdir style format present in a directory."""
1461
format_string = transport.get_bytes(".bzr/branch-format")
1462
except errors.NoSuchFile:
1463
raise errors.NotBranchError(path=transport.base)
1465
return klass._formats[format_string]
1467
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1470
controldir.ControlDirFormat.register_prober(BzrProber)
1473
class RemoteBzrProber(controldir.Prober):
1474
"""Prober for remote servers that provide a Bazaar smart server."""
1477
def probe_transport(klass, transport):
1478
"""Return a RemoteBzrDirFormat object if it looks possible."""
1480
medium = transport.get_smart_medium()
1481
except (NotImplementedError, AttributeError,
1482
errors.TransportNotPossible, errors.NoSmartMedium,
1483
errors.SmartProtocolError):
1484
# no smart server, so not a branch for this format type.
1485
raise errors.NotBranchError(path=transport.base)
1487
# Decline to open it if the server doesn't support our required
1488
# version (3) so that the VFS-based transport will do it.
1489
if medium.should_probe():
1491
server_version = medium.protocol_version()
1492
except errors.SmartProtocolError:
1493
# Apparently there's no usable smart server there, even though
1494
# the medium supports the smart protocol.
1495
raise errors.NotBranchError(path=transport.base)
1496
if server_version != '2':
1497
raise errors.NotBranchError(path=transport.base)
1498
return RemoteBzrDirFormat()
1501
class BzrDirFormat(controldir.ControlDirFormat):
1502
"""ControlDirFormat base class for .bzr/ directories.
1735
class BzrDirFormat(object):
1736
"""An encapsulation of the initialization and open routines for a format.
1738
Formats provide three things:
1739
* An initialization routine,
1504
1743
Formats are placed in a dict by their format string for reference
1505
1744
during bzrdir opening. These should be subclasses of BzrDirFormat
1510
1749
object will be created every system load.
1752
_default_format = None
1753
"""The default format used for new .bzr dirs."""
1756
"""The known formats."""
1758
_control_formats = []
1759
"""The registered control formats - .bzr, ....
1761
This is a list of BzrDirFormat objects.
1764
_control_server_formats = []
1765
"""The registered control server formats, e.g. RemoteBzrDirs.
1767
This is a list of BzrDirFormat objects.
1513
1770
_lock_file_name = 'branch-lock'
1515
1772
# _lock_class must be set in subclasses to the lock type, typ.
1516
1773
# TransportLock or LockDir
1776
def find_format(klass, transport, _server_formats=True):
1777
"""Return the format present at transport."""
1779
formats = klass._control_server_formats + klass._control_formats
1781
formats = klass._control_formats
1782
for format in formats:
1784
return format.probe_transport(transport)
1785
except errors.NotBranchError:
1786
# this format does not find a control dir here.
1788
raise errors.NotBranchError(path=transport.base)
1791
def probe_transport(klass, transport):
1792
"""Return the .bzrdir style format present in a directory."""
1794
format_string = transport.get(".bzr/branch-format").read()
1795
except errors.NoSuchFile:
1796
raise errors.NotBranchError(path=transport.base)
1799
return klass._formats[format_string]
1801
raise errors.UnknownFormatError(format=format_string, kind='bzrdir')
1804
def get_default_format(klass):
1805
"""Return the current default format."""
1806
return klass._default_format
1518
1808
def get_format_string(self):
1519
1809
"""Return the ASCII format string that identifies this format."""
1520
1810
raise NotImplementedError(self.get_format_string)
1812
def get_format_description(self):
1813
"""Return the short description for this format."""
1814
raise NotImplementedError(self.get_format_description)
1816
def get_converter(self, format=None):
1817
"""Return the converter to use to convert bzrdirs needing converts.
1819
This returns a bzrlib.bzrdir.Converter object.
1821
This should return the best upgrader to step this format towards the
1822
current default format. In the case of plugins we can/should provide
1823
some means for them to extend the range of returnable converters.
1825
:param format: Optional format to override the default format of the
1828
raise NotImplementedError(self.get_converter)
1830
def initialize(self, url, possible_transports=None):
1831
"""Create a bzr control dir at this url and return an opened copy.
1833
While not deprecated, this method is very specific and its use will
1834
lead to many round trips to setup a working environment. See
1835
initialize_on_transport_ex for a [nearly] all-in-one method.
1837
Subclasses should typically override initialize_on_transport
1838
instead of this method.
1840
return self.initialize_on_transport(get_transport(url,
1841
possible_transports))
1522
1843
def initialize_on_transport(self, transport):
1523
1844
"""Initialize a new bzrdir in the base directory of a Transport."""
1672
1993
control_files.unlock()
1673
1994
return self.open(transport, _found=True)
1996
def is_supported(self):
1997
"""Is this format supported?
1999
Supported formats must be initializable and openable.
2000
Unsupported formats may not support initialization or committing or
2001
some other features depending on the reason for not being supported.
2005
def network_name(self):
2006
"""A simple byte string uniquely identifying this format for RPC calls.
2008
Bzr control formats use thir disk format string to identify the format
2009
over the wire. Its possible that other control formats have more
2010
complex detection requirements, so we permit them to use any unique and
2011
immutable string they desire.
2013
raise NotImplementedError(self.network_name)
2015
def same_model(self, target_format):
2016
return (self.repository_format.rich_root_data ==
2017
target_format.rich_root_data)
2020
def known_formats(klass):
2021
"""Return all the known formats.
2023
Concrete formats should override _known_formats.
2025
# There is double indirection here to make sure that control
2026
# formats used by more than one dir format will only be probed
2027
# once. This can otherwise be quite expensive for remote connections.
2029
for format in klass._control_formats:
2030
result.update(format._known_formats())
2034
def _known_formats(klass):
2035
"""Return the known format instances for this control format."""
2036
return set(klass._formats.values())
1675
2038
def open(self, transport, _found=False):
1676
2039
"""Return an instance of this format for the dir transport points at.
1678
2041
_found is a private parameter, do not use it.
1681
found_format = controldir.ControlDirFormat.find_format(transport)
2044
found_format = BzrDirFormat.find_format(transport)
1682
2045
if not isinstance(found_format, self.__class__):
1683
2046
raise AssertionError("%s was asked to open %s, but it seems to need "
1700
2063
def register_format(klass, format):
1701
BzrProber.register_bzrdir_format(format)
2064
klass._formats[format.get_format_string()] = format
1702
2065
# bzr native formats have a network name of their format string.
1703
controldir.network_format_registry.register(format.get_format_string(), format.__class__)
1704
controldir.ControlDirFormat.register_format(format)
2066
network_format_registry.register(format.get_format_string(), format.__class__)
2069
def register_control_format(klass, format):
2070
"""Register a format that does not use '.bzr' for its control dir.
2072
TODO: This should be pulled up into a 'ControlDirFormat' base class
2073
which BzrDirFormat can inherit from, and renamed to register_format
2074
there. It has been done without that for now for simplicity of
2077
klass._control_formats.append(format)
2080
def register_control_server_format(klass, format):
2081
"""Register a control format for client-server environments.
2083
These formats will be tried before ones registered with
2084
register_control_format. This gives implementations that decide to the
2085
chance to grab it before anything looks at the contents of the format
2088
klass._control_server_formats.append(format)
2091
def _set_default_format(klass, format):
2092
"""Set default format (for testing behavior of defaults only)"""
2093
klass._default_format = format
2097
return self.get_format_description().rstrip()
1706
2099
def _supply_sub_formats_to(self, other_format):
1707
2100
"""Give other_format the same values for sub formats as this has.
2908
3313
BzrDirMetaFormat1._set_repository_format) #.im_func)
2911
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
3316
BzrDirFormat.register_control_server_format(RemoteBzrDirFormat)
3319
class BzrDirFormatInfo(object):
3321
def __init__(self, native, deprecated, hidden, experimental):
3322
self.deprecated = deprecated
3323
self.native = native
3324
self.hidden = hidden
3325
self.experimental = experimental
3328
class BzrDirFormatRegistry(registry.Registry):
3329
"""Registry of user-selectable BzrDir subformats.
3331
Differs from BzrDirFormat._control_formats in that it provides sub-formats,
3332
e.g. BzrDirMeta1 with weave repository. Also, it's more user-oriented.
3336
"""Create a BzrDirFormatRegistry."""
3337
self._aliases = set()
3338
self._registration_order = list()
3339
super(BzrDirFormatRegistry, self).__init__()
3342
"""Return a set of the format names which are aliases."""
3343
return frozenset(self._aliases)
3345
def register_metadir(self, key,
3346
repository_format, help, native=True, deprecated=False,
3352
"""Register a metadir subformat.
3354
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3355
by the Repository/Branch/WorkingTreeformats.
3357
:param repository_format: The fully-qualified repository format class
3359
:param branch_format: Fully-qualified branch format class name as
3361
:param tree_format: Fully-qualified tree format class name as
3364
# This should be expanded to support setting WorkingTree and Branch
3365
# formats, once BzrDirMetaFormat1 supports that.
3366
def _load(full_name):
3367
mod_name, factory_name = full_name.rsplit('.', 1)
3369
mod = __import__(mod_name, globals(), locals(),
3371
except ImportError, e:
3372
raise ImportError('failed to load %s: %s' % (full_name, e))
3374
factory = getattr(mod, factory_name)
3375
except AttributeError:
3376
raise AttributeError('no factory %s in module %r'
3381
bd = BzrDirMetaFormat1()
3382
if branch_format is not None:
3383
bd.set_branch_format(_load(branch_format))
3384
if tree_format is not None:
3385
bd.workingtree_format = _load(tree_format)
3386
if repository_format is not None:
3387
bd.repository_format = _load(repository_format)
3389
self.register(key, helper, help, native, deprecated, hidden,
3390
experimental, alias)
3392
def register(self, key, factory, help, native=True, deprecated=False,
3393
hidden=False, experimental=False, alias=False):
3394
"""Register a BzrDirFormat factory.
3396
The factory must be a callable that takes one parameter: the key.
3397
It must produce an instance of the BzrDirFormat when called.
3399
This function mainly exists to prevent the info object from being
3402
registry.Registry.register(self, key, factory, help,
3403
BzrDirFormatInfo(native, deprecated, hidden, experimental))
3405
self._aliases.add(key)
3406
self._registration_order.append(key)
3408
def register_lazy(self, key, module_name, member_name, help, native=True,
3409
deprecated=False, hidden=False, experimental=False, alias=False):
3410
registry.Registry.register_lazy(self, key, module_name, member_name,
3411
help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
3413
self._aliases.add(key)
3414
self._registration_order.append(key)
3416
def set_default(self, key):
3417
"""Set the 'default' key to be a clone of the supplied key.
3419
This method must be called once and only once.
3421
registry.Registry.register(self, 'default', self.get(key),
3422
self.get_help(key), info=self.get_info(key))
3423
self._aliases.add('default')
3425
def set_default_repository(self, key):
3426
"""Set the FormatRegistry default and Repository default.
3428
This is a transitional method while Repository.set_default_format
3431
if 'default' in self:
3432
self.remove('default')
3433
self.set_default(key)
3434
format = self.get('default')()
3436
def make_bzrdir(self, key):
3437
return self.get(key)()
3439
def help_topic(self, topic):
3441
default_realkey = None
3442
default_help = self.get_help('default')
3444
for key in self._registration_order:
3445
if key == 'default':
3447
help = self.get_help(key)
3448
if help == default_help:
3449
default_realkey = key
3451
help_pairs.append((key, help))
3453
def wrapped(key, help, info):
3455
help = '(native) ' + help
3456
return ':%s:\n%s\n\n' % (key,
3457
textwrap.fill(help, initial_indent=' ',
3458
subsequent_indent=' ',
3459
break_long_words=False))
3460
if default_realkey is not None:
3461
output += wrapped(default_realkey, '(default) %s' % default_help,
3462
self.get_info('default'))
3463
deprecated_pairs = []
3464
experimental_pairs = []
3465
for key, help in help_pairs:
3466
info = self.get_info(key)
3469
elif info.deprecated:
3470
deprecated_pairs.append((key, help))
3471
elif info.experimental:
3472
experimental_pairs.append((key, help))
3474
output += wrapped(key, help, info)
3475
output += "\nSee ``bzr help formats`` for more about storage formats."
3477
if len(experimental_pairs) > 0:
3478
other_output += "Experimental formats are shown below.\n\n"
3479
for key, help in experimental_pairs:
3480
info = self.get_info(key)
3481
other_output += wrapped(key, help, info)
3484
"No experimental formats are available.\n\n"
3485
if len(deprecated_pairs) > 0:
3486
other_output += "\nDeprecated formats are shown below.\n\n"
3487
for key, help in deprecated_pairs:
3488
info = self.get_info(key)
3489
other_output += wrapped(key, help, info)
3492
"\nNo deprecated formats are available.\n\n"
3494
"\nSee ``bzr help formats`` for more about storage formats."
3496
if topic == 'other-formats':
2914
3502
class RepositoryAcquisitionPolicy(object):
3068
3652
return self._repository, False
3071
def register_metadir(registry, key,
3072
repository_format, help, native=True, deprecated=False,
3078
"""Register a metadir subformat.
3080
These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
3081
by the Repository/Branch/WorkingTreeformats.
3083
:param repository_format: The fully-qualified repository format class
3085
:param branch_format: Fully-qualified branch format class name as
3087
:param tree_format: Fully-qualified tree format class name as
3090
# This should be expanded to support setting WorkingTree and Branch
3091
# formats, once BzrDirMetaFormat1 supports that.
3092
def _load(full_name):
3093
mod_name, factory_name = full_name.rsplit('.', 1)
3095
mod = __import__(mod_name, globals(), locals(),
3097
except ImportError, e:
3098
raise ImportError('failed to load %s: %s' % (full_name, e))
3100
factory = getattr(mod, factory_name)
3101
except AttributeError:
3102
raise AttributeError('no factory %s in module %r'
3107
bd = BzrDirMetaFormat1()
3108
if branch_format is not None:
3109
bd.set_branch_format(_load(branch_format))
3110
if tree_format is not None:
3111
bd.workingtree_format = _load(tree_format)
3112
if repository_format is not None:
3113
bd.repository_format = _load(repository_format)
3115
registry.register(key, helper, help, native, deprecated, hidden,
3116
experimental, alias)
3655
# Please register new formats after old formats so that formats
3656
# appear in chronological order and format descriptions can build
3658
format_registry = BzrDirFormatRegistry()
3118
3659
# The pre-0.8 formats have their repository format network name registered in
3119
3660
# repository.py. MetaDir formats have their repository format network name
3120
3661
# inferred from their disk format string.
3121
controldir.format_registry.register('weave', BzrDirFormat6,
3662
format_registry.register('weave', BzrDirFormat6,
3122
3663
'Pre-0.8 format. Slower than knit and does not'
3123
3664
' support checkouts or shared repositories.',
3125
3665
deprecated=True)
3126
register_metadir(controldir.format_registry, 'metaweave',
3666
format_registry.register_metadir('metaweave',
3127
3667
'bzrlib.repofmt.weaverepo.RepositoryFormat7',
3128
3668
'Transitional format in 0.8. Slower than knit.',
3129
3669
branch_format='bzrlib.branch.BzrBranchFormat5',
3130
3670
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3132
3671
deprecated=True)
3133
register_metadir(controldir.format_registry, 'knit',
3672
format_registry.register_metadir('knit',
3134
3673
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3135
3674
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
3136
3675
branch_format='bzrlib.branch.BzrBranchFormat5',
3137
3676
tree_format='bzrlib.workingtree.WorkingTreeFormat3',
3139
3677
deprecated=True)
3140
register_metadir(controldir.format_registry, 'dirstate',
3678
format_registry.register_metadir('dirstate',
3141
3679
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3142
3680
help='New in 0.15: Fast local operations. Compatible with bzr 0.8 and '
3143
3681
'above when accessed over the network.',
3145
3683
# this uses bzrlib.workingtree.WorkingTreeFormat4 because importing
3146
3684
# directly from workingtree_4 triggers a circular import.
3147
3685
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3149
3686
deprecated=True)
3150
register_metadir(controldir.format_registry, 'dirstate-tags',
3687
format_registry.register_metadir('dirstate-tags',
3151
3688
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
3152
3689
help='New in 0.15: Fast local operations and improved scaling for '
3153
3690
'network operations. Additionally adds support for tags.'
3154
3691
' Incompatible with bzr < 0.15.',
3155
3692
branch_format='bzrlib.branch.BzrBranchFormat6',
3156
3693
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3158
3694
deprecated=True)
3159
register_metadir(controldir.format_registry, 'rich-root',
3695
format_registry.register_metadir('rich-root',
3160
3696
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit4',
3161
3697
help='New in 1.0. Better handling of tree roots. Incompatible with'
3163
3699
branch_format='bzrlib.branch.BzrBranchFormat6',
3164
3700
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3166
3701
deprecated=True)
3167
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
3702
format_registry.register_metadir('dirstate-with-subtree',
3168
3703
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
3169
3704
help='New in 0.15: Fast local operations and improved scaling for '
3170
3705
'network operations. Additionally adds support for versioning nested '
3174
3709
experimental=True,
3177
register_metadir(controldir.format_registry, 'pack-0.92',
3712
format_registry.register_metadir('pack-0.92',
3178
3713
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack1',
3179
3714
help='New in 0.92: Pack-based format with data compatible with '
3180
3715
'dirstate-tags format repositories. Interoperates with '
3181
3716
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3717
'Previously called knitpack-experimental. '
3718
'For more information, see '
3719
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3183
3720
branch_format='bzrlib.branch.BzrBranchFormat6',
3184
3721
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3186
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
3723
format_registry.register_metadir('pack-0.92-subtree',
3187
3724
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack3',
3188
3725
help='New in 0.92: Pack-based format with data compatible with '
3189
3726
'dirstate-with-subtree format repositories. Interoperates with '
3190
3727
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
3728
'Previously called knitpack-experimental. '
3729
'For more information, see '
3730
'http://doc.bazaar-vcs.org/latest/developers/packrepo.html.',
3192
3731
branch_format='bzrlib.branch.BzrBranchFormat6',
3193
3732
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3195
3734
experimental=True,
3197
register_metadir(controldir.format_registry, 'rich-root-pack',
3736
format_registry.register_metadir('rich-root-pack',
3198
3737
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack4',
3199
3738
help='New in 1.0: A variant of pack-0.92 that supports rich-root data '
3200
3739
'(needed for bzr-svn and bzr-git).',
3201
3740
branch_format='bzrlib.branch.BzrBranchFormat6',
3202
3741
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3205
register_metadir(controldir.format_registry, '1.6',
3743
format_registry.register_metadir('1.6',
3206
3744
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5',
3207
3745
help='A format that allows a branch to indicate that there is another '
3208
3746
'(stacked) repository that should be used to access data that is '
3209
3747
'not present locally.',
3210
3748
branch_format='bzrlib.branch.BzrBranchFormat7',
3211
3749
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3214
register_metadir(controldir.format_registry, '1.6.1-rich-root',
3751
format_registry.register_metadir('1.6.1-rich-root',
3215
3752
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack5RichRoot',
3216
3753
help='A variant of 1.6 that supports rich-root data '
3217
3754
'(needed for bzr-svn and bzr-git).',
3218
3755
branch_format='bzrlib.branch.BzrBranchFormat7',
3219
3756
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3222
register_metadir(controldir.format_registry, '1.9',
3758
format_registry.register_metadir('1.9',
3223
3759
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3224
3760
help='A repository format using B+tree indexes. These indexes '
3225
3761
'are smaller in size, have smarter caching and provide faster '
3226
3762
'performance for most operations.',
3227
3763
branch_format='bzrlib.branch.BzrBranchFormat7',
3228
3764
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3231
register_metadir(controldir.format_registry, '1.9-rich-root',
3766
format_registry.register_metadir('1.9-rich-root',
3232
3767
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3233
3768
help='A variant of 1.9 that supports rich-root data '
3234
3769
'(needed for bzr-svn and bzr-git).',
3235
3770
branch_format='bzrlib.branch.BzrBranchFormat7',
3236
3771
tree_format='bzrlib.workingtree.WorkingTreeFormat4',
3239
register_metadir(controldir.format_registry, '1.14',
3773
format_registry.register_metadir('1.14',
3240
3774
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6',
3241
3775
help='A working-tree format that supports content filtering.',
3242
3776
branch_format='bzrlib.branch.BzrBranchFormat7',
3243
3777
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3245
register_metadir(controldir.format_registry, '1.14-rich-root',
3779
format_registry.register_metadir('1.14-rich-root',
3246
3780
'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
3247
3781
help='A variant of 1.14 that supports rich-root data '
3248
3782
'(needed for bzr-svn and bzr-git).',
3250
3784
tree_format='bzrlib.workingtree.WorkingTreeFormat5',
3252
3786
# The following un-numbered 'development' formats should always just be aliases.
3253
register_metadir(controldir.format_registry, 'development-rich-root',
3787
format_registry.register_metadir('development-rich-root',
3254
3788
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3255
3789
help='Current development format. Supports rich roots. Can convert data '
3256
3790
'to and from rich-root-pack (and anything compatible with '
3257
3791
'rich-root-pack) format repositories. Repositories and branches in '
3258
3792
'this format can only be read by bzr.dev. Please read '
3259
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3793
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3261
3795
branch_format='bzrlib.branch.BzrBranchFormat7',
3262
3796
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3263
3797
experimental=True,
3267
register_metadir(controldir.format_registry, 'development5-subtree',
3800
format_registry.register_metadir('development-subtree',
3268
3801
'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment2Subtree',
3269
help='Development format, subtree variant. Can convert data to and '
3270
'from pack-0.92-subtree (and anything compatible with '
3271
'pack-0.92-subtree) format repositories. Repositories and branches in '
3272
'this format can only be read by bzr.dev. Please read '
3273
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3275
branch_format='bzrlib.branch.BzrBranchFormat7',
3276
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3283
register_metadir(controldir.format_registry, 'development-subtree',
3284
'bzrlib.repofmt.groupcompress_repo.RepositoryFormat2aSubtree',
3285
3802
help='Current development format, subtree variant. Can convert data to and '
3286
3803
'from pack-0.92-subtree (and anything compatible with '
3287
3804
'pack-0.92-subtree) format repositories. Repositories and branches in '
3288
3805
'this format can only be read by bzr.dev. Please read '
3289
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3806
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3291
3808
branch_format='bzrlib.branch.BzrBranchFormat7',
3292
3809
tree_format='bzrlib.workingtree.WorkingTreeFormat6',
3293
3810
experimental=True,
3295
3811
alias=False, # Restore to being an alias when an actual development subtree format is added
3296
3812
# This current non-alias status is simply because we did not introduce a
3297
3813
# chk based subtree format.
3300
3816
# And the development formats above will have aliased one of the following:
3301
register_metadir(controldir.format_registry, 'development6-rich-root',
3817
format_registry.register_metadir('development6-rich-root',
3302
3818
'bzrlib.repofmt.groupcompress_repo.RepositoryFormatCHK1',
3303
3819
help='pack-1.9 with 255-way hashed CHK inv, group compress, rich roots '
3305
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
3821
'http://doc.bazaar-vcs.org/latest/developers/development-repo.html '
3307
3823
branch_format='bzrlib.branch.BzrBranchFormat7',
3308
3824
tree_format='bzrlib.workingtree.WorkingTreeFormat6',