Rev 5651: (jelmer) Allow registering "extra" working tree formats that can not be used in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Feb 7 18:33:48 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5651 [merge]
revision-id: pqm at pqm.ubuntu.com-20110207183342-sid8o7k8d1c5ph7c
parent: pqm at pqm.ubuntu.com-20110207094313-kms5t2agjk410hqt
parent: jelmer at samba.org-20110207140050-2551pkugrm1p1yqs
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-02-07 18:33:42 +0000
message:
(jelmer) Allow registering "extra" working tree formats that can not be used
in meta dirs. (Jelmer Vernooij)
modified:
bzrlib/tests/per_tree/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
bzrlib/tests/per_workingtree/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
bzrlib/tests/test_inv.py testinv.py-20050722220913-1dc326138d1a5892
bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
=== modified file 'bzrlib/tests/per_tree/__init__.py'
--- a/bzrlib/tests/per_tree/__init__.py 2010-12-02 10:41:05 +0000
+++ b/bzrlib/tests/per_tree/__init__.py 2011-02-04 18:12:44 +0000
@@ -39,7 +39,6 @@
from bzrlib.transform import TransformPreview
from bzrlib.workingtree import (
WorkingTreeFormat,
- _legacy_formats,
)
from bzrlib.workingtree_4 import (
DirStateRevisionTree,
@@ -398,6 +397,6 @@
# None here will cause a readonly decorator to be created
# by the TestCaseWithTransport.get_readonly_transport method.
None,
- WorkingTreeFormat._formats.values() + _legacy_formats)
+ WorkingTreeFormat.get_formats())
# add the tests for the sub modules
return tests.multiply_tests(submod_tests, scenarios, standard_tests)
=== modified file 'bzrlib/tests/per_workingtree/__init__.py'
--- a/bzrlib/tests/per_workingtree/__init__.py 2011-01-24 21:49:59 +0000
+++ b/bzrlib/tests/per_workingtree/__init__.py 2011-02-04 18:12:44 +0000
@@ -67,12 +67,6 @@
return builder
-def workingtree_formats():
- """The known working tree formats."""
- return (workingtree.WorkingTreeFormat._formats.values() +
- workingtree._legacy_formats)
-
-
def load_tests(standard_tests, module, loader):
test_names = [
'add_reference',
@@ -126,7 +120,7 @@
# None here will cause a readonly decorator to be created
# by the TestCaseWithTransport.get_readonly_transport method.
None,
- workingtree_formats()
+ workingtree.WorkingTreeFormat.get_formats()
)
# add the tests for the sub modules
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_inv.py 2011-02-04 18:12:44 +0000
@@ -38,8 +38,8 @@
TestCase,
TestCaseWithTransport,
)
-from bzrlib.tests.per_workingtree import workingtree_formats
from bzrlib.tests.scenarios import load_tests_apply_scenarios
+from bzrlib.workingtree import WorkingTreeFormat
load_tests = load_tests_apply_scenarios
@@ -59,7 +59,7 @@
scenarios.append((str(format.__name__), {
'apply_delta':apply_inventory_Repository_add_inventory_by_delta,
'format':format}))
- for format in workingtree_formats():
+ for format in WorkingTreeFormat.get_formats():
scenarios.append(
(str(format.__class__.__name__) + ".update_basis_by_delta", {
'apply_delta':apply_inventory_WT_basis,
=== modified file 'bzrlib/tests/test_workingtree.py'
--- a/bzrlib/tests/test_workingtree.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_workingtree.py 2011-02-04 18:18:19 +0000
@@ -123,6 +123,26 @@
return "opened tree."
+class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
+ """A sample format that does not support use in a metadir.
+
+ """
+
+ def get_format_string(self):
+ # Not usable in a metadir, so no format string
+ return None
+
+ def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
+ accelerator_tree=None, hardlink=False):
+ raise NotImplementedError(self.initialize)
+
+ def is_supported(self):
+ return False
+
+ def open(self, transport, _found=False):
+ raise NotImplementedError(self.open)
+
+
class TestWorkingTreeFormat(TestCaseWithTransport):
"""Tests for the WorkingTreeFormat facility."""
@@ -165,12 +185,21 @@
format.initialize(dir)
# register a format for it.
workingtree.WorkingTreeFormat.register_format(format)
+ self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
# which branch.Open will refuse (not supported)
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
# but open_downlevel will work
self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
# unregister the format
workingtree.WorkingTreeFormat.unregister_format(format)
+ self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
+
+ def test_register_unregister_extra_format(self):
+ format = SampleExtraTreeFormat()
+ workingtree.WorkingTreeFormat.register_extra_format(format)
+ self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
+ workingtree.WorkingTreeFormat.unregister_extra_format(format)
+ self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
class TestWorkingTreeFormat3(TestCaseWithTransport):
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-01-27 17:45:24 +0000
+++ b/bzrlib/workingtree.py 2011-02-07 14:00:50 +0000
@@ -2882,6 +2882,9 @@
_formats = {}
"""The known formats."""
+ _extra_formats = []
+ """Extra formats that can not be used in a metadir."""
+
requires_rich_root = False
upgrade_recommended = False
@@ -2944,6 +2947,18 @@
klass._formats[format.get_format_string()] = format
@classmethod
+ def register_extra_format(klass, format):
+ klass._extra_formats.append(format)
+
+ @classmethod
+ def unregister_extra_format(klass, format):
+ klass._extra_formats.remove(format)
+
+ @classmethod
+ def get_formats(klass):
+ return klass._formats.values() + klass._extra_formats
+
+ @classmethod
def set_default_format(klass, format):
klass._default_format = format
@@ -3177,7 +3192,7 @@
WorkingTreeFormat.register_format(WorkingTreeFormat4())
WorkingTreeFormat.register_format(WorkingTreeFormat3())
WorkingTreeFormat.set_default_format(__default_format)
-# formats which have no format string are not discoverable
-# and not independently creatable, so are not registered.
-_legacy_formats = [WorkingTreeFormat2(),
- ]
+# Register extra formats which have no format string are not discoverable
+# and not independently creatable. They are implicitly created as part of
+# e.g. older Bazaar formats or foreign formats.
+WorkingTreeFormat.register_extra_format(WorkingTreeFormat2())
More information about the bazaar-commits
mailing list