1159
1160
parameterisation.
1162
_default_format = None
1163
"""The default format used for new repositories."""
1166
"""The known formats."""
1163
_registry = registry.Registry()
1164
"""Registry of formats, indexed by their identifying format string."""
1168
1166
def __str__(self):
1169
1167
return "<%s>" % self.__class__.__name__
1172
1170
def find_format(klass, a_bzrdir):
1173
"""Return the format for the repository object in a_bzrdir."""
1171
"""Return the format for the repository object in a_bzrdir.
1173
This is used by bzr native formats that have a "format" file in
1174
the repository. Other methods may be used by different types of
1175
1178
transport = a_bzrdir.get_repository_transport(None)
1176
1179
format_string = transport.get("format").read()
1177
return klass._formats[format_string]
1180
return klass._registry.get(format_string)
1178
1181
except errors.NoSuchFile:
1179
1182
raise errors.NoRepositoryPresent(a_bzrdir)
1180
1183
except KeyError:
1181
1184
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)
1187
def register_format(klass, format):
1188
klass._registry.register(format.get_format_string(), format)
1191
@deprecated_method(symbol_versioning.zero_fourteen)
1192
def set_default_format(klass, format):
1193
klass._set_default_format(format)
1196
def _set_default_format(klass, format):
1197
"""Set the default format for new Repository creation.
1199
The format must already be registered.
1201
klass._registry.default_key = format.get_format_string()
1204
def unregister_format(klass, format):
1205
klass._registry.remove(format.get_format_string())
1188
1208
def get_default_format(klass):
1189
1209
"""Return the current default format."""
1190
return klass._default_format
1210
return klass._registry.get(klass._registry.default_key)
1212
def _get_control_store(self, repo_transport, control_files):
1213
"""Return the control store for this repository."""
1214
raise NotImplementedError(self._get_control_store)
1192
1216
def get_format_string(self):
1193
1217
"""Return the ASCII format string that identifies this format.
1276
1300
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
1303
class PreSplitOutRepositoryFormat(RepositoryFormat):
1298
1304
"""Base class for the pre split out repository formats."""
1807
1813
# formats which have no format string are not discoverable
1808
1814
# and not independently creatable, so are not registered.
1809
1815
RepositoryFormat.register_format(RepositoryFormat7())
1810
# KEEP in sync with bzrdir.format_registry default
1816
# KEEP in sync with bzrdir.format_registry default, which controls the overall
1817
# default control directory format
1811
1818
_default_format = RepositoryFormatKnit1()
1812
1819
RepositoryFormat.register_format(_default_format)
1813
1820
RepositoryFormat.register_format(RepositoryFormatKnit2())