Rev 3231: Adjust stackable branches to work with an external reference supporting repository. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Fri Feb 15 03:30:20 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

------------------------------------------------------------
revno: 3231
revision-id:robertc at robertcollins.net-20080215033013-lej7ll35xy59m4x5
parent: robertc at robertcollins.net-20080215023052-fhpnuessxzniifd5
parent: robertc at robertcollins.net-20080215032610-5u2bbflfg1zi4dk0
committer: Robert Collins <robertc at robertcollins.net>
branch nick: StackablePacks
timestamp: Fri 2008-02-15 14:30:13 +1100
message:
  Adjust stackable branches to work with an external reference supporting repository.
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
    ------------------------------------------------------------
    revno: 3229.1.1
    revision-id:robertc at robertcollins.net-20080215032610-5u2bbflfg1zi4dk0
    parent: robertc at robertcollins.net-20080215022546-g3i4tmuoln761k8r
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: StackableBranch
    timestamp: Fri 2008-02-15 14:26:10 +1100
    message:
      Stackable branch fixes.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-02-15 02:25:46 +0000
+++ b/bzrlib/branch.py	2008-02-15 03:30:13 +0000
@@ -40,6 +40,7 @@
         )
 from bzrlib.config import BranchConfig, TreeConfig
 from bzrlib.lockable_files import LockableFiles, TransportLock
+from bzrlib.repofmt.pack_repo import RepositoryFormatPackDevelopment1Subtree
 from bzrlib.tag import (
     BasicTags,
     DisabledTags,
@@ -1236,6 +1237,11 @@
                       ]
         return self._initialize_helper(a_bzrdir, utf8_files)
 
+    def __init__(self):
+        super(BzrBranchFormat7, self).__init__()
+        self._matchingbzrdir.repository_format = \
+            RepositoryFormatPackDevelopment1Subtree()
+
 
 class BranchReferenceFormat(BranchFormat):
     """Bzr branch reference format.
@@ -1994,6 +2000,10 @@
 
     def get_stacked_on(self):
         self._check_stackable_repo()
+        stacked_url = self.control_files.get_utf8('stacked-on').read()[:-1]
+        if not stacked_url:
+            raise errors.NotStacked(self)
+        return stacked_url
 
     def set_append_revisions_only(self, enabled):
         if enabled:
@@ -2005,6 +2015,9 @@
 
     def set_stacked_on(self, url):
         self._check_stackable_repo()
+        if not url:
+            url = ''
+        self.control_files.put_utf8('stacked-on', url + '\n')
 
     def _get_append_revisions_only(self):
         value = self.get_config().get_user_option('append_revisions_only')

=== modified file 'bzrlib/tests/branch_implementations/test_stacking.py'
--- a/bzrlib/tests/branch_implementations/test_stacking.py	2008-02-14 02:08:03 +0000
+++ b/bzrlib/tests/branch_implementations/test_stacking.py	2008-02-15 03:26:10 +0000
@@ -41,6 +41,6 @@
             self.assertRaises(old_format_errors, branch.get_stacked_on)
             return
         # now we have a stacked branch:
-        self.assertEqual(target.base, branch.get_stacked_on)
+        self.assertEqual(target.base, branch.get_stacked_on())
         branch.set_stacked_on(None)
-        self.assertRaises(NotStacked, branch.get_stacked_on)
+        self.assertRaises(errors.NotStacked, branch.get_stacked_on)

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2008-02-14 00:40:32 +0000
+++ b/bzrlib/tests/test_branch.py	2008-02-15 03:30:13 +0000
@@ -339,7 +339,9 @@
         return "development-subtree"
 
     def test_set_stacked_on_unstackable_repo(self):
-        branch = self.make_branch('a', format=self.get_format_name())
+        repo = self.make_repository('a', format='dirstate-tags')
+        control = repo.bzrdir
+        branch = _mod_branch.BzrBranchFormat7().initialize(control)
         target = self.make_branch('b')
         self.assertRaises(errors.UnstackableRepositoryFormat,
             branch.set_stacked_on, target.base)
@@ -352,6 +354,14 @@
         branch = self.make_branch('a', format=self.get_format_name())
         self.assertFileEqual('\n', 'a/.bzr/branch/stacked-on')
 
+    def test_stack_and_unstack(self):
+        branch = self.make_branch('a', format=self.get_format_name())
+        target = self.make_branch('b')
+        branch.set_stacked_on(target.base)
+        self.assertEqual(target.base, branch.get_stacked_on())
+        branch.set_stacked_on(None)
+        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
+
 
 class TestBranchReference(TestCaseWithTransport):
     """Tests for the branch reference facility."""



More information about the bazaar-commits mailing list