Rev 4464: Do not stack on the same branch/repository anymore. This was never supported and would generally result in infinite recursion. Fixes bug 376243. in http://people.ubuntu.com/~robertc/baz2.0/pending/stacking-policy

Robert Collins robertc at robertcollins.net
Fri Jun 19 01:33:42 BST 2009


At http://people.ubuntu.com/~robertc/baz2.0/pending/stacking-policy

------------------------------------------------------------
revno: 4464
revision-id: robertc at robertcollins.net-20090619003336-7rfqk0j0zv69hdgw
parent: robertc at robertcollins.net-20090619000731-al9310600e7pk27b
committer: Robert Collins <robertc at robertcollins.net>
branch nick: stacking-policy
timestamp: Fri 2009-06-19 10:33:36 +1000
message:
  Do not stack on the same branch/repository anymore. This was never supported and would generally result in infinite recursion. Fixes bug 376243.
=== modified file 'NEWS'
--- a/NEWS	2009-06-18 19:19:49 +0000
+++ b/NEWS	2009-06-19 00:33:36 +0000
@@ -42,6 +42,13 @@
   ``BZR_PROGRESS_BAR`` is set to ``none``.
   (Martin Pool, #339385)
 
+* Stacking will no longer accept requests to stack on the same
+  branch/repository. Existing branches that incorrectly reference the same
+  repository in a stacking configuration will now raise
+  UnstackableLocationError when the branch is opened. This can be fixed by
+  removing the stacking location inside ``.bzr/branch``.
+  (Robert Collins, #376243)
+
 Internals
 *********
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-06-17 03:53:51 +0000
+++ b/bzrlib/branch.py	2009-06-19 00:33:36 +0000
@@ -105,6 +105,8 @@
     def _activate_fallback_location(self, url):
         """Activate the branch/repository from url as a fallback repository."""
         repo = self._get_fallback_repository(url)
+        if repo.has_same_location(self.repository):
+            raise errors.UnstackableLocationError(self.base, url)
         self.repository.add_fallback_repository(repo)
 
     def break_lock(self):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2009-06-17 05:05:28 +0000
+++ b/bzrlib/errors.py	2009-06-19 00:33:36 +0000
@@ -636,6 +636,16 @@
         self.url = url
 
 
+class UnstackableLocationError(BzrError):
+
+    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
+
+    def __init__(self, branch_url, target_url):
+        BzrError.__init__(self)
+        self.branch_url = branch_url
+        self.target_url = target_url
+
+
 class UnstackableRepositoryFormat(BzrError):
 
     _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "

=== modified file 'bzrlib/tests/branch_implementations/test_stacking.py'
--- a/bzrlib/tests/branch_implementations/test_stacking.py	2009-06-11 07:43:56 +0000
+++ b/bzrlib/tests/branch_implementations/test_stacking.py	2009-06-19 00:33:36 +0000
@@ -78,6 +78,34 @@
             return
         self.assertEqual('../target', branch.get_stacked_on_url())
 
+    def test_set_stacked_on_same_branch_raises(self):
+        # Stacking on the same branch silently raises and doesn't execute the
+        # change. Reported in bug 376243.
+        branch = self.make_branch('branch')
+        try:
+            self.assertRaises(errors.UnstackableLocationError,
+                branch.set_stacked_on_url, '../branch')
+        except unstackable_format_errors:
+            # if the set failed, so must the get
+            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
+            return
+        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
+
+    def test_set_stacked_on_same_branch_after_being_stacked_raises(self):
+        # Stacking on the same branch silently raises and doesn't execute the
+        # change.
+        branch = self.make_branch('branch')
+        target = self.make_branch('target')
+        try:
+            branch.set_stacked_on_url('../target')
+        except unstackable_format_errors:
+            # if the set failed, so must the get
+            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
+            return
+        self.assertRaises(errors.UnstackableLocationError,
+            branch.set_stacked_on_url, '../branch')
+        self.assertEqual('../target', branch.get_stacked_on_url())
+
     def assertRevisionInRepository(self, repo_path, revid):
         """Check that a revision is in a repository, disregarding stacking."""
         repo = bzrdir.BzrDir.open(repo_path).open_repository()

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2009-05-01 06:42:30 +0000
+++ b/bzrlib/tests/test_errors.py	2009-06-19 00:33:36 +0000
@@ -242,6 +242,11 @@
             "You will need to upgrade the branch to permit branch stacking.",
             str(error))
 
+    def test_unstackable_location(self):
+        error = errors.UnstackableLocationError('foo', 'bar')
+        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
+            str(error))
+
     def test_unstackable_repository_format(self):
         format = u'foo'
         url = "/foo"




More information about the bazaar-commits mailing list