Rev 4054: (robertc) Fix race condition with branch hooks during cloning when in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Feb 26 03:16:03 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4054
revision-id: pqm at pqm.ubuntu.com-20090226031558-1ubr618vdn4r5f07
parent: pqm at pqm.ubuntu.com-20090225235242-3h3yxyd8smf6b0g2
parent: robertc at robertcollins.net-20090226010618-tr1mdkrhu6i8c234
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-02-26 03:15:58 +0000
message:
  (robertc) Fix race condition with branch hooks during cloning when
  	the new branch is stacked. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
  bzrlib/tests/branch_implementations/test_create_clone.py test_create_clone.py-20090225031440-8ybpkzojo7cvourv-1
    ------------------------------------------------------------
    revno: 4050.1.3
    revision-id: robertc at robertcollins.net-20090226010618-tr1mdkrhu6i8c234
    parent: robertc at robertcollins.net-20090226001302-ltc7k8ekbmcr2ofq
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: integration
    timestamp: Thu 2009-02-26 12:06:18 +1100
    message:
      Add missed new parameter for branch reference cloning.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 4050.1.2
    revision-id: robertc at robertcollins.net-20090226001302-ltc7k8ekbmcr2ofq
    parent: robertc at robertcollins.net-20090225221725-0795sbskjouaxbm5
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: integration
    timestamp: Thu 2009-02-26 11:13:02 +1100
    message:
      Bump stacked first push up by two calls (because the branch is stacked earlier).
    modified:
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
    ------------------------------------------------------------
    revno: 4050.1.1
    revision-id: robertc at robertcollins.net-20090225221725-0795sbskjouaxbm5
    parent: pqm at pqm.ubuntu.com-20090225171156-l63eiz2bz51ialsg
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: clone.branch-takes-strategy
    timestamp: Thu 2009-02-26 09:17:25 +1100
    message:
      Fix race condition with branch hooks during cloning when the new branch is stacked.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/tests/branch_implementations/test_create_clone.py test_create_clone.py-20090225031440-8ybpkzojo7cvourv-1
=== modified file 'NEWS'
--- a/NEWS	2009-02-25 22:00:24 +0000
+++ b/NEWS	2009-02-26 03:15:58 +0000
@@ -93,6 +93,13 @@
       via RPC calls rather than VFS calls, reducing round trips for
       pushing new branches substantially. (Robert Collins)
 
+    * ``Branch.clone`` now takes the ``repository_policy`` formerly used
+      inside ``BzrDir.clone_on_transport``, allowing stacking to be
+      configured before the branch tags and revision tip are set. This
+      fixes a race condition cloning stacked branches that would cause
+      plugins to have hooks called on non-stacked instances.
+      (Robert Collins, #334187)
+
     * ``BzrDirFormat.__str__`` now uses the human readable description
       rather than the sometimes-absent disk label. (Robert Collins)
 

=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py	2009-02-13 21:21:25 +0000
+++ b/bzrlib/__init__.py	2009-02-25 22:17:25 +0000
@@ -53,8 +53,8 @@
 version_info = (1, 13, 0, 'dev', 0)
 
 
-# API compatibility version: bzrlib is currently API compatible with 1.11.
-api_minimum_version = (1, 11, 0)
+# API compatibility version: bzrlib is currently API compatible with 1.13.
+api_minimum_version = (1, 13, 0)
 
 
 def _format_version_tuple(version_info):

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-02-25 23:52:42 +0000
+++ b/bzrlib/branch.py	2009-02-26 03:15:58 +0000
@@ -878,7 +878,7 @@
             raise errors.InvalidRevisionNumber(revno)
 
     @needs_read_lock
-    def clone(self, to_bzrdir, revision_id=None):
+    def clone(self, to_bzrdir, revision_id=None, repository_policy=None):
         """Clone this branch into to_bzrdir preserving all semantic values.
 
         Most API users will want 'create_clone_on_transport', which creates a
@@ -888,6 +888,8 @@
                      be truncated to end with revision_id.
         """
         result = to_bzrdir.create_branch()
+        if repository_policy is not None:
+            repository_policy.configure_branch(result)
         self.copy_content_into(result, revision_id=revision_id)
         return  result
 
@@ -1668,7 +1670,8 @@
 
     def _make_reference_clone_function(format, a_branch):
         """Create a clone() routine for a branch dynamically."""
-        def clone(to_bzrdir, revision_id=None):
+        def clone(to_bzrdir, revision_id=None,
+            repository_policy=None):
             """See Branch.clone()."""
             return format.initialize(to_bzrdir, a_branch)
             # cannot obey revision_id limits when cloning a reference ...

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2009-02-25 05:36:18 +0000
+++ b/bzrlib/bzrdir.py	2009-02-25 22:17:25 +0000
@@ -229,9 +229,8 @@
         #   make sure its content is available in the target repository
         #   clone it.
         if local_branch is not None:
-            result_branch = local_branch.clone(result, revision_id=revision_id)
-            if repository_policy is not None:
-                repository_policy.configure_branch(result_branch)
+            result_branch = local_branch.clone(result, revision_id=revision_id,
+                repository_policy=repository_policy)
         try:
             # Cheaper to check if the target is not local, than to try making
             # the tree and fail.

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-02-25 16:27:41 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-02-26 00:13:02 +0000
@@ -219,7 +219,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertEqual(54, rpc_count)
+        self.assertEqual(56, rpc_count)
         remote = Branch.open('public')
         self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 

=== modified file 'bzrlib/tests/branch_implementations/test_create_clone.py'
--- a/bzrlib/tests/branch_implementations/test_create_clone.py	2009-02-25 03:22:12 +0000
+++ b/bzrlib/tests/branch_implementations/test_create_clone.py	2009-02-25 22:17:25 +0000
@@ -16,7 +16,9 @@
 
 """Tests for branch.create_clone behaviour."""
 
+from bzrlib.branch import Branch
 from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
+from bzrlib import remote
 
 
 class TestCreateClone(TestCaseWithBranch):
@@ -54,3 +56,30 @@
             stacked_on=trunk.base)
         self.assertEqual(revid, result.last_revision())
         self.assertEqual(trunk.base, result.get_stacked_on_url())
+
+    def assertBranchHookBranchIsStacked(self, pre_change_params):
+        # Just calling will either succeed or fail.
+        pre_change_params.branch.get_stacked_on_url()
+        self.hook_calls.append(pre_change_params)
+
+    def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self):
+        tree = self.make_branch_and_tree('source')
+        tree.commit('a commit')
+        trunk = tree.branch.create_clone_on_transport(
+            self.get_transport('trunk'))
+        revid = tree.commit('a second commit')
+        source = tree.branch
+        target_transport = self.get_transport('target')
+        self.hook_calls = []
+        Branch.hooks.install_named_hook("pre_change_branch_tip",
+            self.assertBranchHookBranchIsStacked, None)
+        result = tree.branch.create_clone_on_transport(target_transport,
+            stacked_on=trunk.base)
+        self.assertEqual(revid, result.last_revision())
+        self.assertEqual(trunk.base, result.get_stacked_on_url())
+        # Smart servers invoke hooks on both sides
+        if isinstance(result, remote.RemoteBranch):
+            expected_calls = 2
+        else:
+            expected_calls = 1
+        self.assertEqual(expected_calls, len(self.hook_calls))




More information about the bazaar-commits mailing list