Rev 5307: More clarity about how to use the lazy registration feature. in http://bazaar.launchpad.net/~lifeless/bzr/loomsupport
Robert Collins
robertc at robertcollins.net
Sun Jun 20 22:14:50 BST 2010
At http://bazaar.launchpad.net/~lifeless/bzr/loomsupport
------------------------------------------------------------
revno: 5307
revision-id: robertc at robertcollins.net-20100620211449-9ns38l9zvdxd1n96
parent: robertc at robertcollins.net-20100618043750-ij6cdr2fudc71jjs
committer: Robert Collins <robertc at robertcollins.net>
branch nick: loomsupport
timestamp: Mon 2010-06-21 09:14:49 +1200
message:
More clarity about how to use the lazy registration feature.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2010-06-18 04:37:50 +0000
+++ b/bzrlib/branch.py 2010-06-20 21:14:49 +0000
@@ -1727,7 +1727,13 @@
class MetaDirBranchFormatFactory(registry._LazyObjectGetter):
- """A factory for a BranchFormat object, permitting simple lazy registration."""
+ """A factory for a BranchFormat object, permitting simple lazy registration.
+
+ While none of the built in BranchFormats are lazy registered yet,
+ bzrlib.tests.test_branch.TestMetaDirBranchFormatFactory demonstrates how to
+ use it, and the bzr-loom plugin uses it as well (see
+ bzrlib.plugins.loom.formats).
+ """
def __init__(self, format_string, module_name, member_name):
"""Create a MetaDirBranchFormatFactory.
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2010-06-18 04:37:50 +0000
+++ b/bzrlib/tests/test_branch.py 2010-06-20 21:14:49 +0000
@@ -136,12 +136,17 @@
return "opened branch."
+# Demonstrating how lazy loading is often implemented:
+# A constant string is created.
+SampleSupportedBranchFormatString = "Sample supported branch format."
+
+# And the format class can then reference the constant to avoid skew.
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
"""A sample supported format."""
def get_format_string(self):
"""See BzrBranchFormat.get_format_string()."""
- return "Sample supported branch format."
+ return SampleSupportedBranchFormatString
def initialize(self, a_bzrdir, name=None):
t = a_bzrdir.get_branch_transport(self, name=name)
@@ -172,7 +177,7 @@
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
SampleSupportedBranchFormat().initialize(dir)
factory = _mod_branch.MetaDirBranchFormatFactory(
- SampleSupportedBranchFormat().get_format_string(),
+ SampleSupportedBranchFormatString,
"bzrlib.tests.test_branch", "SampleSupportedBranchFormat")
_mod_branch.BranchFormat.register_format(factory)
self.addCleanup(_mod_branch.BranchFormat.unregister_format, factory)
More information about the bazaar-commits
mailing list