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
28
class BzrProber(controldir.Prober):
29
"""Prober for formats that use a .bzr/ control directory."""
31
formats = registry.FormatRegistry(controldir.network_format_registry)
32
"""The known .bzr formats."""
35
def probe_transport(klass, transport):
36
"""Return the .bzrdir style format present in a directory."""
38
format_string = transport.get_bytes(".bzr/branch-format")
39
except errors.NoSuchFile:
40
raise errors.NotBranchError(path=transport.base)
42
first_line = format_string[:format_string.index(b"\n") + 1]
44
first_line = format_string
46
cls = klass.formats.get(first_line)
48
if first_line.endswith(b"\r\n"):
49
raise errors.LineEndingError(file=".bzr/branch-format")
51
raise errors.UnknownFormatError(
52
format=first_line, kind='bzrdir')
53
return cls.from_string(format_string)
56
def known_formats(cls):
58
for name, format in cls.formats.items():
65
controldir.ControlDirFormat.register_prober(BzrProber)
68
class RemoteBzrProber(controldir.Prober):
69
"""Prober for remote servers that provide a Bazaar smart server."""
72
def probe_transport(klass, transport):
73
"""Return a RemoteBzrDirFormat object if it looks possible."""
75
medium = transport.get_smart_medium()
76
except (NotImplementedError, AttributeError,
77
errors.TransportNotPossible, errors.NoSmartMedium,
78
errors.SmartProtocolError):
79
# no smart server, so not a branch for this format type.
80
raise errors.NotBranchError(path=transport.base)
82
# Decline to open it if the server doesn't support our required
83
# version (3) so that the VFS-based transport will do it.
84
if medium.should_probe():
86
server_version = medium.protocol_version()
87
except errors.SmartProtocolError:
88
# Apparently there's no usable smart server there, even though
89
# the medium supports the smart protocol.
90
raise errors.NotBranchError(path=transport.base)
91
if server_version != '2':
92
raise errors.NotBranchError(path=transport.base)
93
from .remote import RemoteBzrDirFormat
94
return RemoteBzrDirFormat()
97
def known_formats(cls):
98
from .remote import RemoteBzrDirFormat
99
return [RemoteBzrDirFormat()]
102
controldir.ControlDirFormat.register_server_prober(RemoteBzrProber)
104
# Register bzr formats
105
BzrProber.formats.register_lazy(
106
b"Bazaar-NG meta directory, format 1\n",
107
__name__ + '.bzrdir', 'BzrDirMetaFormat1')
108
BzrProber.formats.register_lazy(
109
b"Bazaar meta directory, format 1 (with colocated branches)\n",
110
__name__ + '.bzrdir', 'BzrDirMetaFormat1Colo')
113
def register_metadir(registry, key,
114
repository_format, help, native=True, deprecated=False,
120
"""Register a metadir subformat.
122
These all use a meta bzrdir, but can be parameterized by the
123
Repository/Branch/WorkingTreeformats.
125
:param repository_format: The fully-qualified repository format class
127
:param branch_format: Fully-qualified branch format class name as
129
:param tree_format: Fully-qualified tree format class name as
132
if bzrdir_format is None:
133
bzrdir_format = 'breezy.bzr.bzrdir.BzrDirMetaFormat1'
134
# This should be expanded to support setting WorkingTree and Branch
135
# formats, once the API supports that.
137
def _load(full_name):
138
mod_name, factory_name = full_name.rsplit('.', 1)
140
factory = pyutils.get_named_object(mod_name, factory_name)
141
except ImportError as e:
142
raise ImportError('failed to load %s: %s' % (full_name, e))
143
except AttributeError:
144
raise AttributeError('no factory %s in module %r'
145
% (full_name, sys.modules[mod_name]))
149
bd = _load(bzrdir_format)
150
if branch_format is not None:
151
bd.set_branch_format(_load(branch_format))
152
if tree_format is not None:
153
bd.workingtree_format = _load(tree_format)
154
if repository_format is not None:
155
bd.repository_format = _load(repository_format)
157
registry.register(key, helper, help, native, deprecated, hidden,
162
controldir.format_registry, 'knit',
163
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
164
'Format using knits. Recommended for interoperation with bzr <= 0.14.',
165
branch_format='breezy.bzr.fullhistory.BzrBranchFormat5',
166
tree_format='breezy.bzr.workingtree_3.WorkingTreeFormat3',
170
controldir.format_registry, 'dirstate',
171
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
172
help='Format using dirstate for working trees. '
173
'Compatible with bzr 0.8 and '
174
'above when accessed over the network. Introduced in bzr 0.15.',
175
branch_format='breezy.bzr.fullhistory.BzrBranchFormat5',
176
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
180
controldir.format_registry, 'dirstate-tags',
181
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
182
help='Variant of dirstate with support for tags. '
183
'Introduced in bzr 0.15.',
184
branch_format='breezy.bzr.branch.BzrBranchFormat6',
185
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
189
controldir.format_registry, 'rich-root',
190
'breezy.bzr.knitrepo.RepositoryFormatKnit4',
191
help='Variant of dirstate with better handling of tree roots. '
192
'Introduced in bzr 1.0',
193
branch_format='breezy.bzr.branch.BzrBranchFormat6',
194
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
198
controldir.format_registry, 'dirstate-with-subtree',
199
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
200
help='Variant of dirstate with support for nested trees. '
201
'Introduced in 0.15.',
202
branch_format='breezy.bzr.branch.BzrBranchFormat6',
203
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
208
controldir.format_registry, 'pack-0.92',
209
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack1',
210
help='Pack-based format used in 1.x series. Introduced in 0.92. '
211
'Interoperates with bzr repositories before 0.92 but cannot be '
212
'read by bzr < 0.92. ',
213
branch_format='breezy.bzr.branch.BzrBranchFormat6',
214
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
219
controldir.format_registry, 'pack-0.92-subtree',
220
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack3',
221
help='Pack-based format used in 1.x series, with subtree support. '
222
'Introduced in 0.92. Interoperates with '
223
'bzr repositories before 0.92 but cannot be read by bzr < 0.92. ',
224
branch_format='breezy.bzr.branch.BzrBranchFormat6',
225
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
231
controldir.format_registry, 'rich-root-pack',
232
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack4',
233
help='A variant of pack-0.92 that supports rich-root data '
234
'(needed for bzr-svn and bzr-git). Introduced in 1.0.',
235
branch_format='breezy.bzr.branch.BzrBranchFormat6',
236
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
241
controldir.format_registry, '1.6',
242
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack5',
243
help='A format that allows a branch to indicate that there is another '
244
'(stacked) repository that should be used to access data that is '
245
'not present locally.',
246
branch_format='breezy.bzr.branch.BzrBranchFormat7',
247
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
252
controldir.format_registry, '1.6.1-rich-root',
253
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack5RichRoot',
254
help='A variant of 1.6 that supports rich-root data '
255
'(needed for bzr-svn and bzr-git).',
256
branch_format='breezy.bzr.branch.BzrBranchFormat7',
257
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
262
controldir.format_registry, '1.9',
263
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6',
264
help='A repository format using B+tree indexes. These indexes '
265
'are smaller in size, have smarter caching and provide faster '
266
'performance for most operations.',
267
branch_format='breezy.bzr.branch.BzrBranchFormat7',
268
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat4',
273
controldir.format_registry, '1.9-rich-root',
274
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
275
help='A variant of 1.9 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.WorkingTreeFormat4',
283
controldir.format_registry, '1.14',
284
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6',
285
help='A working-tree format that supports content filtering.',
286
branch_format='breezy.bzr.branch.BzrBranchFormat7',
287
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat5',
292
controldir.format_registry, '1.14-rich-root',
293
'breezy.bzr.knitpack_repo.RepositoryFormatKnitPack6RichRoot',
294
help='A variant of 1.14 that supports rich-root data '
295
'(needed for bzr-svn and bzr-git).',
296
branch_format='breezy.bzr.branch.BzrBranchFormat7',
297
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat5',
301
# The following un-numbered 'development' formats should always just be aliases.
303
controldir.format_registry, 'development-subtree',
304
'breezy.bzr.groupcompress_repo.RepositoryFormat2aSubtree',
305
help='Current development format, subtree variant. Can convert data to and '
306
'from pack-0.92-subtree (and anything compatible with '
307
'pack-0.92-subtree) format repositories. Repositories and branches in '
308
'this format can only be read by bzr.dev. Please read '
309
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
311
branch_format='breezy.bzr.branch.BzrBranchFormat8',
312
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
317
controldir.format_registry, 'development5-subtree',
318
'breezy.bzr.knitpack_repo.RepositoryFormatPackDevelopment2Subtree',
319
help='Development format, subtree variant. Can convert data to and '
320
'from pack-0.92-subtree (and anything compatible with '
321
'pack-0.92-subtree) format repositories. Repositories and branches in '
322
'this format can only be read by bzr.dev. Please read '
323
'http://doc.bazaar.canonical.com/latest/developers/development-repo.html '
325
branch_format='breezy.bzr.branch.BzrBranchFormat7',
326
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
332
controldir.format_registry, 'development-colo',
333
'breezy.bzr.groupcompress_repo.RepositoryFormat2a',
334
help='The 2a format with experimental support for colocated branches.\n',
335
branch_format='breezy.bzr.branch.BzrBranchFormat7',
336
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
338
bzrdir_format='breezy.bzr.bzrdir.BzrDirMetaFormat1Colo',
343
# And the development formats above will have aliased one of the following:
345
# Finally, the current format.
346
register_metadir(controldir.format_registry, '2a',
347
'breezy.bzr.groupcompress_repo.RepositoryFormat2a',
348
help='Format for the bzr 2.0 series.\n',
349
branch_format='breezy.bzr.branch.BzrBranchFormat7',
350
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
354
# The following format should be an alias for the rich root equivalent
355
# of the default format
357
controldir.format_registry.register_alias(
358
'default-rich-root', '2a', hidden=True)
360
# The following format should is just an alias for the default bzr format.
361
controldir.format_registry.register_alias('bzr', '2a')
363
# The current format that is made on 'bzr init'.
364
format_name = config.GlobalStack().get('default_format')
365
controldir.format_registry.set_default(format_name)