~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-01-25 05:18:17 UTC
  • mfrom: (2241.1.3 repoformats)
  • Revision ID: pqm@pqm.ubuntu.com-20070125051817-53a80525dbdf87b4
(mbp) Change RepositoryFormat to use a registry (r=john)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
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
37
37
    lockable_files,
38
38
    lockdir,
39
39
    osutils,
 
40
    registry,
40
41
    revision as _mod_revision,
41
42
    symbol_versioning,
42
43
    transactions,
1135
1136
                                 committer, revprops, revision_id)
1136
1137
 
1137
1138
 
 
1139
class RepositoryFormatRegistry(registry.Registry):
 
1140
    """Registry of RepositoryFormats.
 
1141
    """
 
1142
    
 
1143
 
 
1144
format_registry = RepositoryFormatRegistry()
 
1145
"""Registry of formats, indexed by their identifying format string."""
 
1146
 
 
1147
 
1138
1148
class RepositoryFormat(object):
1139
1149
    """A repository format.
1140
1150
 
1159
1169
    parameterisation.
1160
1170
    """
1161
1171
 
1162
 
    _default_format = None
1163
 
    """The default format used for new repositories."""
1164
 
 
1165
 
    _formats = {}
1166
 
    """The known formats."""
1167
 
 
1168
1172
    def __str__(self):
1169
1173
        return "<%s>" % self.__class__.__name__
1170
1174
 
1171
1175
    @classmethod
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.
 
1178
        
 
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 
 
1181
        control directory.
 
1182
        """
1174
1183
        try:
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)
1182
1191
 
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)
 
1192
    @classmethod
 
1193
    @deprecated_method(symbol_versioning.zero_fourteen)
 
1194
    def set_default_format(klass, format):
 
1195
        klass._set_default_format(format)
 
1196
 
 
1197
    @classmethod
 
1198
    def _set_default_format(klass, format):
 
1199
        """Set the default format for new Repository creation.
 
1200
 
 
1201
        The format must already be registered.
 
1202
        """
 
1203
        format_registry.default_key = format.get_format_string()
 
1204
 
 
1205
    @classmethod
 
1206
    def register_format(klass, format):
 
1207
        format_registry.register(format.get_format_string(), format)
 
1208
 
 
1209
    @classmethod
 
1210
    def unregister_format(klass, format):
 
1211
        format_registry.remove(format.get_format_string())
1186
1212
    
1187
1213
    @classmethod
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)
 
1217
 
 
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)
1191
1221
 
1192
1222
    def get_format_string(self):
1193
1223
        """Return the ASCII format string that identifies this format.
1275
1305
        """
1276
1306
        raise NotImplementedError(self.open)
1277
1307
 
1278
 
    @classmethod
1279
 
    def register_format(klass, format):
1280
 
        klass._formats[format.get_format_string()] = format
1281
 
 
1282
 
    @classmethod
1283
 
    @deprecated_method(symbol_versioning.zero_fourteen)
1284
 
    def set_default_format(klass, format):
1285
 
        klass._set_default_format(format)
1286
 
 
1287
 
    @classmethod
1288
 
    def _set_default_format(klass, format):
1289
 
        klass._default_format = format
1290
 
 
1291
 
    @classmethod
1292
 
    def unregister_format(klass, format):
1293
 
        assert klass._formats[format.get_format_string()] is format
1294
 
        del klass._formats[format.get_format_string()]
1295
 
 
1296
1308
 
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())