1
# Copyright (C) 2017 Breezy Developers
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
from __future__ import absolute_import
27
class BzrProber(controldir.Prober):
28
"""Prober for formats that use a .bzr/ control directory."""
30
formats = registry.FormatRegistry(controldir.network_format_registry)
31
"""The known .bzr formats."""
34
def probe_transport(klass, transport):
35
"""Return the .bzrdir style format present in a directory."""
37
format_string = transport.get_bytes(".bzr/branch-format")
38
except errors.NoSuchFile:
39
raise errors.NotBranchError(path=transport.base)
41
first_line = format_string[:format_string.index(b"\n")+1]
43
first_line = format_string
45
cls = klass.formats.get(first_line)
47
raise errors.UnknownFormatError(format=first_line, kind='bzrdir')
48
return cls.from_string(format_string)
51
def known_formats(cls):
53
for name, format in cls.formats.items():
60
controldir.ControlDirFormat.register_prober(BzrProber)
63
class RemoteBzrProber(controldir.Prober):
64
"""Prober for remote servers that provide a Bazaar smart server."""
67
def probe_transport(klass, transport):
68
"""Return a RemoteBzrDirFormat object if it looks possible."""
70
medium = transport.get_smart_medium()
71
except (NotImplementedError, AttributeError,
72
errors.TransportNotPossible, errors.NoSmartMedium,
73
errors.SmartProtocolError):
74
# no smart server, so not a branch for this format type.
75
raise errors.NotBranchError(path=transport.base)
77
# Decline to open it if the server doesn't support our required
78
# version (3) so that the VFS-based transport will do it.
79
if medium.should_probe():
81
server_version = medium.protocol_version()
82
except errors.SmartProtocolError:
83
# Apparently there's no usable smart server there, even though
84
# the medium supports the smart protocol.
85
raise errors.NotBranchError(path=transport.base)
86
if server_version != '2':
87
raise errors.NotBranchError(path=transport.base)
88
from .remote import RemoteBzrDirFormat
89
return RemoteBzrDirFormat()
92
def known_formats(cls):
93
from .remote import RemoteBzrDirFormat
94
return [RemoteBzrDirFormat()]
97
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
99
# Register bzr formats
100
BzrProber.formats.register_lazy(
101
b"Bazaar-NG meta directory, format 1\n",
102
__name__ + '.bzrdir', 'BzrDirMetaFormat1')
103
BzrProber.formats.register_lazy(
104
b"Bazaar meta directory, format 1 (with colocated branches)\n",
105
__name__ + '.bzrdir', 'BzrDirMetaFormat1Colo')
108
def register_metadir(registry, key,
109
repository_format, help, native=True, deprecated=False,
115
"""Register a metadir subformat.
117
These all use a meta bzrdir, but can be parameterized by the
118
Repository/Branch/WorkingTreeformats.
120
:param repository_format: The fully-qualified repository format class
122
:param branch_format: Fully-qualified branch format class name as
124
:param tree_format: Fully-qualified tree format class name as
127
if bzrdir_format is None:
128
bzrdir_format = 'breezy.bzr.bzrdir.BzrDirMetaFormat1'
129
# This should be expanded to support setting WorkingTree and Branch
130
# formats, once the API supports that.
131
def _load(full_name):
132
mod_name, factory_name = full_name.rsplit('.', 1)
134
factory = pyutils.get_named_object(mod_name, factory_name)
135
except ImportError as e:
136
raise ImportError('failed to load %s: %s' % (full_name, e))
137
except AttributeError:
138
raise AttributeError('no factory %s in module %r'
139
% (full_name, sys.modules[mod_name]))
143
bd = _load(bzrdir_format)
144
if branch_format is not None:
145
bd.set_branch_format(_load(branch_format))
146
if tree_format is not None:
147
bd.workingtree_format = _load(tree_format)
148
if repository_format is not None:
149
bd.repository_format = _load(repository_format)
151
registry.register(key, helper, help, native, deprecated, hidden,
154
register_metadir(controldir.format_registry, 'knit',
155
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
156
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
157
branch_format='breezy.bzr.fullhistory.BzrBranchFormat5',
158
tree_format='breezy.bzr.workingtree_3.WorkingTreeFormat3',
161
register_metadir(controldir.format_registry, 'dirstate',
162
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
163
help='Format using dirstate for working trees. '
164
'Compatible with bzr 0.8 and '
165
'above when accessed over the network. Introduced in bzr 0.15.',
166
branch_format='breezy.bzr.fullhistory.BzrBranchFormat5',
167
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
170
register_metadir(controldir.format_registry, 'dirstate-tags',
171
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
172
help='Variant of dirstate with support for tags. '
173
'Introduced in bzr 0.15.',
174
branch_format='breezy.bzr.branch.BzrBranchFormat6',
175
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
178
register_metadir(controldir.format_registry, 'rich-root',
179
'breezy.bzr.knitrepo.RepositoryFormatKnit4',
180
help='Variant of dirstate with better handling of tree roots. '
181
'Introduced in bzr 1.0',
182
branch_format='breezy.bzr.branch.BzrBranchFormat6',
183
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
186
register_metadir(controldir.format_registry, 'dirstate-with-subtree',
187
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
188
help='Variant of dirstate with support for nested trees. '
189
'Introduced in 0.15.',
190
branch_format='breezy.bzr.branch.BzrBranchFormat6',
191
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
195
register_metadir(controldir.format_registry, 'pack-0.92',
196
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack1',
197
help='Pack-based format used in 1.x series. Introduced in 0.92. '
198
'Interoperates with bzr repositories before 0.92 but cannot be '
199
'read by bzr < 0.92. '
201
branch_format='breezy.bzr.branch.BzrBranchFormat6',
202
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
206
register_metadir(controldir.format_registry, 'pack-0.92-subtree',
207
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack3',
208
help='Pack-based format used in 1.x series, with subtree support. '
209
'Introduced in 0.92. Interoperates with '
210
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. '
212
branch_format='breezy.bzr.branch.BzrBranchFormat6',
213
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
218
register_metadir(controldir.format_registry, 'rich-root-pack',
219
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack4',
220
help='A variant of pack-0.92 that supports rich-root data '
221
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
222
branch_format='breezy.bzr.branch.BzrBranchFormat6',
223
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
227
register_metadir(controldir.format_registry, '1.6',
228
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack5',
229
help='A format that allows a branch to indicate that there is another '
230
'(stacked) repository that should be used to access data that is '
231
'not present locally.',
232
branch_format='breezy.bzr.branch.BzrBranchFormat7',
233
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
237
register_metadir(controldir.format_registry, '1.6.1-rich-root',
238
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
239
help='A variant of 1.6 that supports rich-root data '
240
'(needed for bzr-svn and bzr-git).',
241
branch_format='breezy.bzr.branch.BzrBranchFormat7',
242
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
246
register_metadir(controldir.format_registry, '1.9',
247
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6',
248
help='A repository format using B+tree indexes. These indexes '
249
'are smaller in size, have smarter caching and provide faster '
250
'performance for most operations.',
251
branch_format='breezy.bzr.branch.BzrBranchFormat7',
252
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
256
register_metadir(controldir.format_registry, '1.9-rich-root',
257
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
258
help='A variant of 1.9 that supports rich-root data '
259
'(needed for bzr-svn and bzr-git).',
260
branch_format='breezy.bzr.branch.BzrBranchFormat7',
261
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
265
register_metadir(controldir.format_registry, '1.14',
266
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6',
267
help='A working-tree format that supports content filtering.',
268
branch_format='breezy.bzr.branch.BzrBranchFormat7',
269
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat5',
273
register_metadir(controldir.format_registry, '1.14-rich-root',
274
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
275
help='A variant of 1.14 that supports rich-root data '
276
'(needed for bzr-svn and bzr-git).',
277
branch_format='breezy.bzr.branch.BzrBranchFormat7',
278
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat5',
282
# The following un-numbered 'development' formats should always just be aliases.
283
register_metadir(controldir.format_registry, 'development-subtree',
284
'breezy.bzr.groupcompress_repo.RepositoryFormat2aSubtree',
285
help='Current development format, subtree variant. Can convert data to and '
286
'from pack-0.92-subtree (and anything compatible with '
287
'pack-0.92-subtree) format repositories. Repositories and branches in '
288
'this format can only be read by bzr.dev. Please read '
289
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
291
branch_format='breezy.bzr.branch.BzrBranchFormat7',
292
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
296
register_metadir(controldir.format_registry, 'development5-subtree',
297
'breezy.bzr.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
298
help='Development format, subtree variant. Can convert data to and '
299
'from pack-0.92-subtree (and anything compatible with '
300
'pack-0.92-subtree) format repositories. Repositories and branches in '
301
'this format can only be read by bzr.dev. Please read '
302
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
304
branch_format='breezy.bzr.branch.BzrBranchFormat7',
305
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
310
register_metadir(controldir.format_registry, 'development-colo',
311
'breezy.bzr.groupcompress_repo.RepositoryFormat2a',
312
help='The 2a format with experimental support for colocated branches.\n',
313
branch_format='breezy.bzr.branch.BzrBranchFormat7',
314
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
316
bzrdir_format='breezy.bzr.bzrdir.BzrDirMetaFormat1Colo',
321
# And the development formats above will have aliased one of the following:
323
# Finally, the current format.
324
register_metadir(controldir.format_registry, '2a',
325
'breezy.bzr.groupcompress_repo.RepositoryFormat2a',
326
help='Format for the bzr 2.0 series.\n',
327
branch_format='breezy.bzr.branch.BzrBranchFormat7',
328
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
332
# The following format should be an alias for the rich root equivalent
333
# of the default format
335
controldir.format_registry.register_alias('default-rich-root', '2a', hidden=True)
337
# The following format should is just an alias for the default bzr format.
338
controldir.format_registry.register_alias('bzr', '2a')
340
# The current format that is made on 'bzr init'.
341
format_name = config.GlobalStack().get('default_format')
342
controldir.format_registry.set_default(format_name)