Rev 4628: Merge per_branch fixes for 2a as default. in http://bazaar.launchpad.net/~lifeless/bzr/bug-398668

Robert Collins robertc at robertcollins.net
Mon Aug 17 07:22:24 BST 2009


At http://bazaar.launchpad.net/~lifeless/bzr/bug-398668

------------------------------------------------------------
revno: 4628 [merge]
revision-id: robertc at robertcollins.net-20090817062218-bm4gpy36qbno7nur
parent: robertc at robertcollins.net-20090817041933-cocito5y3x8v8nk3
parent: robertc at robertcollins.net-20090817061721-ztcjftsbqx370uq6
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bug-398668
timestamp: Mon 2009-08-17 16:22:18 +1000
message:
  Merge per_branch fixes for 2a as default.
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/per_branch/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
  bzrlib/tests/per_branch/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-08-17 03:47:03 +0000
+++ b/bzrlib/branch.py	2009-08-17 06:22:18 +0000
@@ -1147,6 +1147,9 @@
         revision_id: if not None, the revision history in the new branch will
                      be truncated to end with revision_id.
         """
+        if (repository_policy is not None and
+            repository_policy.requires_stacking()):
+            to_bzrdir._format.require_stacking(_skip_repo=True)
         result = to_bzrdir.create_branch()
         result.lock_write()
         try:

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2009-08-17 03:51:44 +0000
+++ b/bzrlib/bzrdir.py	2009-08-17 06:22:18 +0000
@@ -3548,6 +3548,10 @@
             if self._require_stacking:
                 raise
 
+    def requires_stacking(self):
+        """Return True if this policy requires stacking."""
+        return self._stack_on is not None and self._require_stacking
+
     def _get_full_stack_on(self):
         """Get a fully-qualified URL for the stack_on location."""
         if self._stack_on is None:

=== modified file 'bzrlib/tests/per_branch/__init__.py'
--- a/bzrlib/tests/per_branch/__init__.py	2009-07-10 10:46:00 +0000
+++ b/bzrlib/tests/per_branch/__init__.py	2009-08-17 06:17:21 +0000
@@ -78,7 +78,9 @@
         return self.branch
 
     def make_branch(self, relpath, format=None):
-        repo = self.make_repository(relpath, format=format)
+        if format is not None:
+            return TestCaseWithBzrDir.make_branch(self, relpath, format)
+        repo = self.make_repository(relpath)
         # fixme RBC 20060210 this isnt necessarily a fixable thing,
         # Skipped is the wrong exception to raise.
         try:

=== modified file 'bzrlib/tests/per_branch/test_stacking.py'
--- a/bzrlib/tests/per_branch/test_stacking.py	2009-08-14 13:55:30 +0000
+++ b/bzrlib/tests/per_branch/test_stacking.py	2009-08-17 06:17:21 +0000
@@ -278,14 +278,28 @@
         self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
                           cloned_bzrdir.open_branch().get_stacked_on_url)
 
+    def make_stacked_on_matching(self, source):
+        if source.repository.supports_rich_root():
+            if source.repository._format.supports_chks:
+                format = "2a"
+            else:
+                format = "1.9-rich-root"
+        else:
+            format = "1.9"
+        return self.make_branch('stack-on', format)
+
     def test_sprout_stacking_policy_handling(self):
         """Obey policy where possible, ignore otherwise."""
-        stack_on = self.make_branch('stack-on')
+        if isinstance(self.branch_format, branch.BzrBranchFormat4):
+            raise TestNotApplicable('Branch format 4 does not autoupgrade.')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         target = source.bzrdir.sprout('target').open_branch()
-        if self.branch_format.supports_stacking():
+        # When we sprout we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -293,13 +307,17 @@
 
     def test_clone_stacking_policy_handling(self):
         """Obey policy where possible, ignore otherwise."""
+        if isinstance(self.branch_format, branch.BzrBranchFormat4):
+            raise TestNotApplicable('Branch format 4 does not autoupgrade.')
         self.thisFailsStrictLockCheck()
-        stack_on = self.make_branch('stack-on')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         target = source.bzrdir.clone('target').open_branch()
-        if self.branch_format.supports_stacking():
+        # When we clone we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -309,13 +327,15 @@
         """Obey policy where possible, ignore otherwise."""
         if isinstance(self.branch_format, branch.BzrBranchFormat4):
             raise TestNotApplicable('Branch format 4 is not usable via HPSS.')
-        stack_on = self.make_branch('stack-on')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         url = self.make_smart_server('target').base
         target = source.bzrdir.sprout(url).open_branch()
-        if self.branch_format.supports_stacking():
+        # When we sprout we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -352,10 +372,10 @@
         # repository boundaries.  however, i didn't actually get this test to
         # fail on that code. -- mbp
         # see https://bugs.launchpad.net/bzr/+bug/252821
-        if not self.branch_format.supports_stacking():
+        stack_on = self.make_branch_and_tree('stack-on')
+        if not stack_on.branch._format.supports_stacking():
             raise TestNotApplicable("%r does not support stacking"
                 % self.branch_format)
-        stack_on = self.make_branch_and_tree('stack-on')
         text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
         self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
         stack_on.add('a')




More information about the bazaar-commits mailing list