Rev 123: ``bzr loomify`` explicitly checks that branches being converted are not Looms in http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/

Robert Collins robertc at robertcollins.net
Fri Jul 2 06:24:36 BST 2010


At http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/

------------------------------------------------------------
revno: 123
revision-id: robertc at robertcollins.net-20100702052430-n4rvwn6i7rqd39qe
parent: robertc at robertcollins.net-20100702044855-8de5fffpvm03txvy
fixes bug(s): https://launchpad.net/bugs/600452
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2010-07-02 15:24:30 +1000
message:
  ``bzr loomify`` explicitly checks that branches being converted are not Looms
  already. This should not have been needed, but apparently it was.
  (Robert Collins, #600452)
=== modified file 'NEWS'
--- a/NEWS	2010-07-02 04:48:55 +0000
+++ b/NEWS	2010-07-02 05:24:30 +0000
@@ -42,6 +42,10 @@
   when the thread being removed has work not merged into either the thread
   above or below. (Robert Collins, #506235)
 
+* ``bzr loomify`` explicitly checks that branches being converted are not Looms
+  already. This should not have been needed, but apparently it was.
+  (Robert Collins, #600452)
+
 * ``bzr nick`` will now rename a thread rather than setting the current thread
   pointer to an invalid value. (Robert Collins, #203203, #260947, #304608)
 

=== modified file 'branch.py'
--- a/branch.py	2010-07-02 04:48:55 +0000
+++ b/branch.py	2010-07-02 05:24:30 +0000
@@ -57,6 +57,15 @@
         loom.unlock()
 
 
+class AlreadyLoom(bzrlib.errors.BzrError):
+
+    _fmt = """Loom %(loom)s is already a loom."""
+
+    def __init__(self, loom):
+        bzrlib.errors.BzrError.__init__(self)
+        self.loom = loom
+
+
 def loomify(branch):
     """Convert branch to a loom.
 
@@ -65,6 +74,12 @@
     try:
         branch.lock_write()
         try:
+            require_loom_branch(branch)
+        except NotALoom:
+            pass
+        else:
+            raise AlreadyLoom(branch)
+        try:
             format = {
                 bzrlib.branch.BzrBranchFormat5: BzrBranchLoomFormat1,
                 bzrlib.branch.BzrBranchFormat6: BzrBranchLoomFormat6,
@@ -82,8 +97,7 @@
 
 
 class LoomThreadError(bzrlib.errors.BzrError):
-
-    _fmt = """Base class for Loom-Thread errors."""
+    """Base class for Loom-Thread errors."""
 
     def __init__(self, branch, thread):
         bzrlib.errors.BzrError.__init__(self)

=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py	2010-07-02 04:48:55 +0000
+++ b/tests/test_branch.py	2010-07-02 05:24:30 +0000
@@ -23,6 +23,7 @@
 from bzrlib.branch import Branch
 import bzrlib.errors as errors
 from bzrlib.plugins.loom.branch import (
+    AlreadyLoom,
     EMPTY_REVISION,
     loomify,
     require_loom_branch,
@@ -70,8 +71,7 @@
         branch = self.make_branch('.')
         self.assertRaises(NotALoom, require_loom_branch, branch)
 
-
-    def works_on_loom(self, format):
+    def works_on_format(self, format):
         branch = self.make_branch('.', format)
         loomify(branch)
         # reopen it
@@ -79,13 +79,19 @@
         self.assertEqual(None, require_loom_branch(branch))
 
     def test_works_on_loom1(self):
-        self.works_on_loom('knit')
+        self.works_on_format('knit')
 
     def test_works_on_loom6(self):
-        self.works_on_loom('pack-0.92')
+        self.works_on_format('pack-0.92')
 
     def test_works_on_loom7(self):
-        self.works_on_loom('1.6')
+        self.works_on_format('1.6')
+
+    def test_no_harm_to_looms(self):
+        branch = self.make_branch('.')
+        loomify(branch)
+        branch = branch.bzrdir.open_branch()
+        self.assertRaises(AlreadyLoom, loomify, branch)
 
 
 class TestLoomify(TestCaseWithTransport):




More information about the bazaar-commits mailing list