Rev 115: Loom now takes advantage of lazy loading of bzr objects (though not to a in http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/
Robert Collins
robertc at robertcollins.net
Fri Jun 18 05:44:59 BST 2010
At http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/
------------------------------------------------------------
revno: 115
revision-id: robertc at robertcollins.net-20100618044452-2hnpj2opedjt8iy9
parent: robertc at robertcollins.net-20100617191129-fnk2xn3jl71gc8ek
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2010-06-18 16:44:52 +1200
message:
Loom now takes advantage of lazy loading of bzr objects (though not to a
complete degree), reducing the overhead of having it installed.
(Robert Collins)
=== modified file 'NEWS'
--- a/NEWS 2010-06-17 19:11:29 +0000
+++ b/NEWS 2010-06-18 04:44:52 +0000
@@ -27,6 +27,10 @@
IMPROVEMENTS
------------
+* Loom now takes advantage of lazy loading of bzr objects (though not to a
+ complete degree), reducing the overhead of having it installed.
+ (Robert Collins)
+
BUGFIXES
--------
=== modified file '__init__.py'
--- a/__init__.py 2010-06-16 03:37:23 +0000
+++ b/__init__.py 2010-06-18 04:44:52 +0000
@@ -59,8 +59,8 @@
import bzrlib.commands
import bzrlib.revisionspec
-import branch
import commands
+import formats
for command in [
@@ -98,6 +98,9 @@
import revspec
bzrlib.revisionspec.SPEC_TYPES.append(revspec.RevisionSpecThread)
+#register loom formats
+formats.register_formats()
+
def test_suite():
import bzrlib.plugins.loom.tests
return bzrlib.plugins.loom.tests.test_suite()
=== modified file 'branch.py'
--- a/branch.py 2010-06-17 04:37:09 +0000
+++ b/branch.py 2010-06-18 04:44:52 +0000
@@ -38,6 +38,7 @@
import bzrlib.tree
import bzrlib.urlutils
+import formats
import loom_io
import loom_state
@@ -76,20 +77,8 @@
branch.unlock()
-def require_loom_branch(branch):
- """Return None if branch is already loomified, or raise NotALoom."""
- if not branch._format.__class__ in LOOM_FORMATS:
- raise NotALoom(branch)
-
-
-class NotALoom(bzrlib.errors.BzrError):
-
- _fmt = ("The branch %(branch)s is not a loom. "
- "You can use 'bzr loomify' to make it into a loom.")
-
- def __init__(self, branch):
- bzrlib.errors.BzrError.__init__(self)
- self.branch = branch
+require_loom_branch = formats.require_loom_branch
+NotALoom = formats.NotALoom
class LoomThreadError(bzrlib.errors.BzrError):
@@ -873,10 +862,6 @@
return "bzr loom format 7 (based on bzr branch format 7)\n"
-bzrlib.branch.BranchFormat.register_format(BzrBranchLoomFormat1())
-bzrlib.branch.BranchFormat.register_format(BzrBranchLoomFormat6())
-bzrlib.branch.BranchFormat.register_format(BzrBranchLoomFormat7())
-
# Handle the smart server:
class InterLoomBranch(bzrlib.branch.GenericInterBranch):
@@ -1009,10 +994,3 @@
bzrlib.branch.InterBranch.register_optimiser(InterLoomBranch)
-
-
-LOOM_FORMATS = [
- BzrBranchLoomFormat1,
- BzrBranchLoomFormat6,
- BzrBranchLoomFormat7,
-]
=== modified file 'commands.py'
--- a/commands.py 2010-06-17 16:17:15 +0000
+++ b/commands.py 2010-06-18 04:44:52 +0000
@@ -21,14 +21,19 @@
import bzrlib.commands
import bzrlib.branch
from bzrlib import errors
+from bzrlib.lazy_import import lazy_import
import bzrlib.merge
from bzrlib.option import Option
import bzrlib.revision
import bzrlib.trace
import bzrlib.transport
+import formats
+
+lazy_import(globals(), """
import branch
from tree import LoomTreeDecorator
+""")
class cmd_loomify(bzrlib.commands.Command):
@@ -154,7 +159,7 @@
else:
path = file_list[0]
(loom, _) = bzrlib.branch.Branch.open_containing(path)
- branch.require_loom_branch(loom)
+ formats.require_loom_branch(loom)
loom.lock_read()
try:
print 'Current thread: %s' % loom.nick
@@ -166,7 +171,7 @@
self._original_command().run_argv_aliases(argv, alias_argv)
try:
super(cmd_status, self).run_argv_aliases(list(argv), alias_argv)
- except branch.NotALoom:
+ except formats.NotALoom:
pass
=== added file 'formats.py'
--- a/formats.py 1970-01-01 00:00:00 +0000
+++ b/formats.py 2010-06-18 04:44:52 +0000
@@ -0,0 +1,74 @@
+# Loom, a plugin for bzr to assist in developing focused patches.
+# Copyright (C) 2010 Canonical Limited.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Format information about formats for Loom.
+
+This is split out from the implementation of the formats to permit lazy
+loading without requiring the implementation code to be cryptic.
+"""
+
+__all__ = [
+ 'NotALoom',
+ 'register_formats',
+ 'require_loom_branch',
+ ]
+
+from bzrlib.lazy_import import lazy_import
+import bzrlib.errors
+
+lazy_import(globals(), """
+from bzrlib import branch as _mod_branch
+""")
+
+
+_LOOM_FORMATS = {
+ "Bazaar-NG Loom branch format 1\n": "BzrBranchLoomFormat1",
+ "Bazaar-NG Loom branch format 6\n": "BzrBranchLoomFormat6",
+ "Bazaar-NG Loom branch format 7\n": "BzrBranchLoomFormat7",
+ }
+
+def register_formats():
+ if getattr(_mod_branch, 'MetaDirBranchFormatFactory', None):
+ branch_formats = [_mod_branch.MetaDirBranchFormatFactory(format_string,
+ "bzrlib.plugins.loom.branch", format_class) for
+ (format_string, format_class) in _LOOM_FORMATS.iteritems()]
+ else:
+ # Compat for folk not running bleeding edge. Like me as I commit this.
+ import branch
+ branch_formats = [
+ branch.BzrBranchLoomFormat1(),
+ branch.BzrBranchLoomFormat6(),
+ branch.BzrBranchLoomFormat7(),
+ ]
+ map(_mod_branch.BranchFormat.register_format, branch_formats)
+
+
+def require_loom_branch(branch):
+ """Return None if branch is already loomified, or raise NotALoom."""
+ if branch._format.network_name() not in _LOOM_FORMATS:
+ raise NotALoom(branch)
+
+
+# TODO: define errors without importing all errors.
+class NotALoom(bzrlib.errors.BzrError):
+
+ _fmt = ("The branch %(branch)s is not a loom. "
+ "You can use 'bzr loomify' to make it into a loom.")
+
+ def __init__(self, branch):
+ bzrlib.errors.BzrError.__init__(self)
+ self.branch = branch
More information about the bazaar-commits
mailing list