1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1135
1136
committer, revprops, revision_id)
1139
class RepositoryFormatRegistry(registry.Registry):
1140
"""Registry of RepositoryFormats.
1144
format_registry = RepositoryFormatRegistry()
1145
"""Registry of formats, indexed by their identifying format string."""
1138
1148
class RepositoryFormat(object):
1139
1149
"""A repository format.
1159
1169
parameterisation.
1162
_default_format = None
1163
"""The default format used for new repositories."""
1166
"""The known formats."""
1168
1172
def __str__(self):
1169
1173
return "<%s>" % self.__class__.__name__
1172
1176
def find_format(klass, a_bzrdir):
1173
"""Return the format for the repository object in a_bzrdir."""
1177
"""Return the format for the repository object in a_bzrdir.
1179
This is used by bzr native formats that have a "format" file in
1180
the repository. Other methods may be used by different types of
1175
1184
transport = a_bzrdir.get_repository_transport(None)
1176
1185
format_string = transport.get("format").read()
1177
return klass._formats[format_string]
1186
return format_registry.get(format_string)
1178
1187
except errors.NoSuchFile:
1179
1188
raise errors.NoRepositoryPresent(a_bzrdir)
1180
1189
except KeyError:
1181
1190
raise errors.UnknownFormatError(format=format_string)
1183
def _get_control_store(self, repo_transport, control_files):
1184
"""Return the control store for this repository."""
1185
raise NotImplementedError(self._get_control_store)
1193
@deprecated_method(symbol_versioning.zero_fourteen)
1194
def set_default_format(klass, format):
1195
klass._set_default_format(format)
1198
def _set_default_format(klass, format):
1199
"""Set the default format for new Repository creation.
1201
The format must already be registered.
1203
format_registry.default_key = format.get_format_string()
1206
def register_format(klass, format):
1207
format_registry.register(format.get_format_string(), format)
1210
def unregister_format(klass, format):
1211
format_registry.remove(format.get_format_string())
1188
1214
def get_default_format(klass):
1189
1215
"""Return the current default format."""
1190
return klass._default_format
1216
return format_registry.get(format_registry.default_key)
1218
def _get_control_store(self, repo_transport, control_files):
1219
"""Return the control store for this repository."""
1220
raise NotImplementedError(self._get_control_store)
1192
1222
def get_format_string(self):
1193
1223
"""Return the ASCII format string that identifies this format.
1276
1306
raise NotImplementedError(self.open)
1279
def register_format(klass, format):
1280
klass._formats[format.get_format_string()] = format
1283
@deprecated_method(symbol_versioning.zero_fourteen)
1284
def set_default_format(klass, format):
1285
klass._set_default_format(format)
1288
def _set_default_format(klass, format):
1289
klass._default_format = format
1292
def unregister_format(klass, format):
1293
assert klass._formats[format.get_format_string()] is format
1294
del klass._formats[format.get_format_string()]
1297
1309
class PreSplitOutRepositoryFormat(RepositoryFormat):
1298
1310
"""Base class for the pre split out repository formats."""
1807
1819
# formats which have no format string are not discoverable
1808
1820
# and not independently creatable, so are not registered.
1809
1821
RepositoryFormat.register_format(RepositoryFormat7())
1810
# KEEP in sync with bzrdir.format_registry default
1822
# KEEP in sync with bzrdir.format_registry default, which controls the overall
1823
# default control directory format
1811
1824
_default_format = RepositoryFormatKnit1()
1812
1825
RepositoryFormat.register_format(_default_format)
1813
1826
RepositoryFormat.register_format(RepositoryFormatKnit2())