Rev 5645: (jelmer) Allow the registration of "extra" branch formats in the branch in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Feb 4 18:07:00 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5645 [merge]
revision-id: pqm at pqm.ubuntu.com-20110204180654-fmof6mad6s3aeam1
parent: pqm at pqm.ubuntu.com-20110204173207-8dzx1ym1ney4td3i
parent: jelmer at samba.org-20110204162530-waq8yf1klv2as2hs
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-02-04 18:06:54 +0000
message:
(jelmer) Allow the registration of "extra" branch formats in the branch
format registry. (Jelmer Vernooij)
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/per_branch/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
bzrlib/tests/test_branch.py test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2011-01-14 20:52:48 +0000
+++ b/bzrlib/branch.py 2011-02-04 16:25:30 +0000
@@ -1552,6 +1552,9 @@
_formats = {}
"""The known formats."""
+ _extra_formats = []
+ """Extra formats that can not be part of a metadir."""
+
can_set_append_revisions_only = True
def __eq__(self, other):
@@ -1592,7 +1595,7 @@
if isinstance(fmt, MetaDirBranchFormatFactory):
fmt = fmt()
result.append(fmt)
- return result
+ return result + klass._extra_formats
def get_reference(self, a_bzrdir, name=None):
"""Get the target reference of the branch in a_bzrdir.
@@ -1738,6 +1741,17 @@
raise NotImplementedError(self.open)
@classmethod
+ def register_extra_format(klass, format):
+ """Register a branch format that can not be part of a metadir.
+
+ This is mainly useful to allow custom branch formats, such as
+ older Bazaar formats and foreign formats, to be tested
+ """
+ klass._extra_formats.append(format)
+ network_format_registry.register(
+ format.network_name(), format.__class__)
+
+ @classmethod
def register_format(klass, format):
"""Register a metadir format.
@@ -1769,6 +1783,10 @@
def unregister_format(klass, format):
del klass._formats[format.get_format_string()]
+ @classmethod
+ def unregister_extra_format(klass, format):
+ klass._extra_formats.remove(format)
+
def __str__(self):
return self.get_format_description().rstrip()
@@ -2379,10 +2397,7 @@
BranchFormat.register_format(__format7)
BranchFormat.register_format(__format8)
BranchFormat.set_default_format(__format7)
-_legacy_formats = [BzrBranchFormat4(),
- ]
-network_format_registry.register(
- _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
+BranchFormat.register_extra_format(BzrBranchFormat4())
class BranchWriteLockResult(LogicalLockResult):
=== modified file 'bzrlib/tests/per_branch/__init__.py'
--- a/bzrlib/tests/per_branch/__init__.py 2010-08-21 16:06:24 +0000
+++ b/bzrlib/tests/per_branch/__init__.py 2011-02-04 13:15:13 +0000
@@ -29,7 +29,6 @@
tests,
)
from bzrlib.branch import (BranchFormat,
- _legacy_formats,
)
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
from bzrlib.tests import test_server
@@ -132,7 +131,7 @@
# Generate a list of branch formats and their associated bzrdir formats to
# use.
combinations = [(format, format._matchingbzrdir) for format in
- BranchFormat.get_formats() + _legacy_formats]
+ BranchFormat.get_formats()]
scenarios = make_scenarios(
# None here will cause the default vfs transport server to be used.
None,
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2011-01-27 14:27:18 +0000
+++ b/bzrlib/tests/test_branch.py 2011-02-04 13:15:13 +0000
@@ -147,6 +147,24 @@
return "opened supported branch."
+class SampleExtraBranchFormat(_mod_branch.BranchFormat):
+ """A sample format that is not usable in a metadir."""
+
+ def get_format_string(self):
+ # This format is not usable in a metadir.
+ return None
+
+ def network_name(self):
+ # Network name always has to be provided.
+ return "extra"
+
+ def initialize(self, a_bzrdir, name=None):
+ raise NotImplementedError(self.initialize)
+
+ def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
+ raise NotImplementedError(self.open)
+
+
class TestBzrBranchFormat(tests.TestCaseWithTransport):
"""Tests for the BzrBranchFormat facility."""
@@ -163,6 +181,17 @@
self.failUnless(isinstance(found_format, format.__class__))
check_format(_mod_branch.BzrBranchFormat5(), "bar")
+ def test_extra_format(self):
+ dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
+ SampleSupportedBranchFormat().initialize(dir)
+ format = SampleExtraBranchFormat()
+ _mod_branch.BranchFormat.register_extra_format(format)
+ self.addCleanup(_mod_branch.BranchFormat.unregister_extra_format,
+ format)
+ self.assertTrue(format in _mod_branch.BranchFormat.get_formats())
+ self.assertEquals(format,
+ _mod_branch.network_format_registry.get("extra"))
+
def test_find_format_factory(self):
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
SampleSupportedBranchFormat().initialize(dir)
More information about the bazaar-commits
mailing list