Rev 2252: Get rid of RepositoryFormat*_instance objects. Instead the format in file:///home/mbp/bzr/Work/repoformats/

Martin Pool mbp at sourcefrog.net
Wed Feb 7 12:41:46 GMT 2007


------------------------------------------------------------
revno: 2252
revision-id: mbp at sourcefrog.net-20070207124145-qufbufe41sm6fqrf
parent: mbp at sourcefrog.net-20070207120941-gd7ow6jzt5b4ughi
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: repoformats
timestamp: Wed 2007-02-07 23:41:45 +1100
message:
  Get rid of RepositoryFormat*_instance objects.  Instead the format
  registry can hold either format objects or factories that create them, and
  its get() method calls that if needed.
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-02-07 09:11:31 +0000
+++ b/bzrlib/bzrdir.py	2007-02-07 12:41:45 +0000
@@ -1833,7 +1833,7 @@
 
     def convert(self, to_convert, pb):
         """See Converter.convert()."""
-        from bzrlib.repofmt.weaverepo import RepositoryFormat7_instance
+        from bzrlib.repofmt.weaverepo import RepositoryFormat7
         from bzrlib.branch import BzrBranchFormat5
         self.bzrdir = to_convert
         self.pb = pb
@@ -1869,7 +1869,7 @@
         # we hard code the formats here because we are converting into
         # the meta format. The meta format upgrader can take this to a 
         # future format within each component.
-        self.put_format('repository', RepositoryFormat7_instance)
+        self.put_format('repository', RepositoryFormat7())
         for entry in repository_names:
             self.move_entry('repository', entry)
 

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2007-02-07 09:22:47 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-02-07 12:41:45 +0000
@@ -358,6 +358,7 @@
 
     This format was introduced in bzr 0.8.
     """
+
     def get_format_string(self):
         """See RepositoryFormat.get_format_string()."""
         return "Bazaar-NG Knit Repository Format 1"
@@ -427,7 +428,3 @@
                                _revision_store=_revision_store,
                                control_store=control_store,
                                text_store=text_store)
-
-
-RepositoryFormatKnit1_instance = RepositoryFormatKnit1()
-RepositoryFormatKnit2_instance = RepositoryFormatKnit2()

=== modified file 'bzrlib/repofmt/weaverepo.py'
--- a/bzrlib/repofmt/weaverepo.py	2007-02-07 12:09:41 +0000
+++ b/bzrlib/repofmt/weaverepo.py	2007-02-07 12:41:45 +0000
@@ -202,9 +202,10 @@
     has been removed.
     """
 
+    _matchingbzrdir = bzrdir.BzrDirFormat4()
+
     def __init__(self):
         super(RepositoryFormat4, self).__init__()
-        self._matchingbzrdir = bzrdir.BzrDirFormat4()
 
     def get_format_description(self):
         """See RepositoryFormat.get_format_description()."""
@@ -252,10 +253,10 @@
     """
 
     _versionedfile_class = weave.WeaveFile
+    _matchingbzrdir = bzrdir.BzrDirFormat5()
 
     def __init__(self):
         super(RepositoryFormat5, self).__init__()
-        self._matchingbzrdir = bzrdir.BzrDirFormat5()
 
     def get_format_description(self):
         """See RepositoryFormat.get_format_description()."""
@@ -284,10 +285,10 @@
     """
 
     _versionedfile_class = weave.WeaveFile
+    _matchingbzrdir = bzrdir.BzrDirFormat6()
 
     def __init__(self):
         super(RepositoryFormat6, self).__init__()
-        self._matchingbzrdir = bzrdir.BzrDirFormat6()
 
     def get_format_description(self):
         """See RepositoryFormat.get_format_description()."""
@@ -400,9 +401,6 @@
             text_store=text_store)
 
 
-RepositoryFormat7_instance = RepositoryFormat7()
-
-
 _legacy_formats = [RepositoryFormat4(),
                    RepositoryFormat5(),
                    RepositoryFormat6()]

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-02-07 12:09:41 +0000
+++ b/bzrlib/repository.py	2007-02-07 12:41:45 +0000
@@ -858,10 +858,20 @@
 class RepositoryFormatRegistry(registry.Registry):
     """Registry of RepositoryFormats.
     """
+
+    def get(self, format_string):
+        r = registry.Registry.get(self, format_string)
+        if callable(r):
+            r = r()
+        return r
     
 
 format_registry = RepositoryFormatRegistry()
-"""Registry of formats, indexed by their identifying format string."""
+"""Registry of formats, indexed by their identifying format string.
+
+This can contain either format instances themselves, or classes/factories that
+can be called to obtain one.
+"""
 
 
 class RepositoryFormat(object):
@@ -891,6 +901,10 @@
     def __str__(self):
         return "<%s>" % self.__class__.__name__
 
+    def __eq__(self, other):
+        # format objects are generally stateless
+        return isinstance(other, self.__class__)
+
     @classmethod
     def find_format(klass, a_bzrdir):
         """Return the format for the repository object in a_bzrdir.
@@ -1033,10 +1047,10 @@
     """Common base class for the new repositories using the metadir layout."""
 
     rich_root_data = False
+    _matchingbzrdir = bzrdir.BzrDirMetaFormat1()
 
     def __init__(self):
         super(MetaDirRepositoryFormat, self).__init__()
-        self._matchingbzrdir = bzrdir.BzrDirMetaFormat1()
 
     def _create_control_files(self, a_bzrdir):
         """Create the required files and the initial control_files object."""
@@ -1067,11 +1081,14 @@
 
 # formats which have no format string are not discoverable
 # and not independently creatable, so are not registered.  They're 
-# all in bzrlib.repofmt.weaverepo now.
+# all in bzrlib.repofmt.weaverepo now.  When an instance of one of these is
+# needed, it's constructed directly by the BzrDir.  Non-native formats where
+# the repository is not separately opened are similar.
+
 format_registry.register_lazy(
     'Bazaar-NG Repository format 7',
     'bzrlib.repofmt.weaverepo',
-    'RepositoryFormat7_instance'
+    'RepositoryFormat7'
     )
 # KEEP in sync with bzrdir.format_registry default, which controls the overall
 # default control directory format
@@ -1079,14 +1096,14 @@
 format_registry.register_lazy(
     'Bazaar-NG Knit Repository Format 1',
     'bzrlib.repofmt.knitrepo',
-    'RepositoryFormatKnit1_instance',
+    'RepositoryFormatKnit1',
     )
 format_registry.default_key = 'Bazaar-NG Knit Repository Format 1'
 
 format_registry.register_lazy(
     'Bazaar Knit Repository Format 2\n',
     'bzrlib.repofmt.knitrepo',
-    'RepositoryFormatKnit2_instance',
+    'RepositoryFormatKnit2',
     )
 
 

=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- a/bzrlib/tests/repository_implementations/__init__.py	2007-02-06 06:27:24 +0000
+++ b/bzrlib/tests/repository_implementations/__init__.py	2007-02-07 12:41:45 +0000
@@ -51,7 +51,8 @@
         'bzrlib.tests.repository_implementations.test_repository',
         'bzrlib.tests.repository_implementations.test_revision',
         ]
-    all_formats = [v for (k, v) in repository.format_registry.iteritems()]
+    registry = repository.format_registry
+    all_formats = [registry.get(k) for k in registry.keys()]
     all_formats.extend(weaverepo._legacy_formats)
     adapter = RepositoryTestProviderAdapter(
         default_transport,




More information about the bazaar-commits mailing list