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
98
99
returns the sha1 of the serialized inventory.
101
_mod_revision.check_not_reserved_id(revid)
100
102
assert inv.revision_id is None or inv.revision_id == revid, \
101
103
"Mismatch between inventory revision" \
102
104
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
1133
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."""
1136
1148
class RepositoryFormat(object):
1137
1149
"""A repository format.
1157
1169
parameterisation.
1160
_default_format = None
1161
"""The default format used for new repositories."""
1164
"""The known formats."""
1166
1172
def __str__(self):
1167
1173
return "<%s>" % self.__class__.__name__
1170
1176
def find_format(klass, a_bzrdir):
1171
"""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
1173
1184
transport = a_bzrdir.get_repository_transport(None)
1174
1185
format_string = transport.get("format").read()
1175
return klass._formats[format_string]
1186
return format_registry.get(format_string)
1176
1187
except errors.NoSuchFile:
1177
1188
raise errors.NoRepositoryPresent(a_bzrdir)
1178
1189
except KeyError:
1179
1190
raise errors.UnknownFormatError(format=format_string)
1181
def _get_control_store(self, repo_transport, control_files):
1182
"""Return the control store for this repository."""
1183
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())
1186
1214
def get_default_format(klass):
1187
1215
"""Return the current default format."""
1188
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)
1190
1222
def get_format_string(self):
1191
1223
"""Return the ASCII format string that identifies this format.
1274
1306
raise NotImplementedError(self.open)
1277
def register_format(klass, format):
1278
klass._formats[format.get_format_string()] = format
1281
def set_default_format(klass, format):
1282
klass._default_format = format
1285
def unregister_format(klass, format):
1286
assert klass._formats[format.get_format_string()] is format
1287
del klass._formats[format.get_format_string()]
1290
1309
class PreSplitOutRepositoryFormat(RepositoryFormat):
1291
1310
"""Base class for the pre split out repository formats."""
1800
1819
# formats which have no format string are not discoverable
1801
1820
# and not independently creatable, so are not registered.
1802
1821
RepositoryFormat.register_format(RepositoryFormat7())
1803
# 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
1804
1824
_default_format = RepositoryFormatKnit1()
1805
1825
RepositoryFormat.register_format(_default_format)
1806
1826
RepositoryFormat.register_format(RepositoryFormatKnit2())
1807
RepositoryFormat.set_default_format(_default_format)
1827
RepositoryFormat._set_default_format(_default_format)
1808
1828
_legacy_formats = [RepositoryFormat4(),
1809
1829
RepositoryFormat5(),
1810
1830
RepositoryFormat6()]