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
99
100
returns the sha1 of the serialized inventory.
102
_mod_revision.check_not_reserved_id(revid)
101
103
assert inv.revision_id is None or inv.revision_id == revid, \
102
104
"Mismatch between inventory revision" \
103
105
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
1143
1146
self._serializer = xml7.serializer_v7
1149
class RepositoryFormatRegistry(registry.Registry):
1150
"""Registry of RepositoryFormats.
1154
format_registry = RepositoryFormatRegistry()
1155
"""Registry of formats, indexed by their identifying format string."""
1146
1158
class RepositoryFormat(object):
1147
1159
"""A repository format.
1167
1179
parameterisation.
1170
_default_format = None
1171
"""The default format used for new repositories."""
1174
"""The known formats."""
1176
1182
def __str__(self):
1177
1183
return "<%s>" % self.__class__.__name__
1180
1186
def find_format(klass, a_bzrdir):
1181
"""Return the format for the repository object in a_bzrdir."""
1187
"""Return the format for the repository object in a_bzrdir.
1189
This is used by bzr native formats that have a "format" file in
1190
the repository. Other methods may be used by different types of
1183
1194
transport = a_bzrdir.get_repository_transport(None)
1184
1195
format_string = transport.get("format").read()
1185
return klass._formats[format_string]
1196
return format_registry.get(format_string)
1186
1197
except errors.NoSuchFile:
1187
1198
raise errors.NoRepositoryPresent(a_bzrdir)
1188
1199
except KeyError:
1189
1200
raise errors.UnknownFormatError(format=format_string)
1191
def _get_control_store(self, repo_transport, control_files):
1192
"""Return the control store for this repository."""
1193
raise NotImplementedError(self._get_control_store)
1203
@deprecated_method(symbol_versioning.zero_fourteen)
1204
def set_default_format(klass, format):
1205
klass._set_default_format(format)
1208
def _set_default_format(klass, format):
1209
"""Set the default format for new Repository creation.
1211
The format must already be registered.
1213
format_registry.default_key = format.get_format_string()
1216
def register_format(klass, format):
1217
format_registry.register(format.get_format_string(), format)
1220
def unregister_format(klass, format):
1221
format_registry.remove(format.get_format_string())
1196
1224
def get_default_format(klass):
1197
1225
"""Return the current default format."""
1198
return klass._default_format
1226
return format_registry.get(format_registry.default_key)
1228
def _get_control_store(self, repo_transport, control_files):
1229
"""Return the control store for this repository."""
1230
raise NotImplementedError(self._get_control_store)
1200
1232
def get_format_string(self):
1201
1233
"""Return the ASCII format string that identifies this format.
1284
1316
raise NotImplementedError(self.open)
1287
def register_format(klass, format):
1288
klass._formats[format.get_format_string()] = format
1291
@deprecated_method(symbol_versioning.zero_fourteen)
1292
def set_default_format(klass, format):
1293
klass._set_default_format(format)
1296
def _set_default_format(klass, format):
1297
klass._default_format = format
1300
def unregister_format(klass, format):
1301
assert klass._formats[format.get_format_string()] is format
1302
del klass._formats[format.get_format_string()]
1305
1319
class PreSplitOutRepositoryFormat(RepositoryFormat):
1306
1320
"""Base class for the pre split out repository formats."""
1858
1871
# formats which have no format string are not discoverable
1859
1872
# and not independently creatable, so are not registered.
1860
1873
RepositoryFormat.register_format(RepositoryFormat7())
1861
# KEEP in sync with bzrdir.format_registry default
1874
# KEEP in sync with bzrdir.format_registry default, which controls the overall
1875
# default control directory format
1862
1876
_default_format = RepositoryFormatKnit1()
1863
1877
RepositoryFormat.register_format(_default_format)
1864
1878
RepositoryFormat.register_format(RepositoryFormatKnit2())