Rev 3933: (jam) Some fixes to stacked branches to avoid opening multiple in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jan 9 05:29:14 GMT 2009


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

------------------------------------------------------------
revno: 3933
revision-id: pqm at pqm.ubuntu.com-20090109052909-3jh4taiu906vin4p
parent: pqm at pqm.ubuntu.com-20090108225256-26dj4mre937k2u6q
parent: john at arbash-meinel.com-20090109031355-rg3grll5bbshstf2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-01-09 05:29:09 +0000
message:
  (jam) Some fixes to stacked branches to avoid opening multiple
  	connections.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
  bzrlib/tests/commands/test_push.py test_push.py-20070525122003-gc1ob0ea0nueoqgj-1
  bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
    ------------------------------------------------------------
    revno: 3928.3.4
    revision-id: john at arbash-meinel.com-20090109031355-rg3grll5bbshstf2
    parent: john at arbash-meinel.com-20090108210718-n70cw41ujrwdxifx
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: stacking_tweaks
    timestamp: Thu 2009-01-08 21:13:55 -0600
    message:
      SampleBzrDir now needs to return a real repo from open_repository
    modified:
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
    ------------------------------------------------------------
    revno: 3928.3.3
    revision-id: john at arbash-meinel.com-20090108210718-n70cw41ujrwdxifx
    parent: john at arbash-meinel.com-20090108194848-93vcyrrg1snzqqjd
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: stacking_tweaks
    timestamp: Thu 2009-01-08 15:07:18 -0600
    message:
      Change the name of 'old_format_errors' to 'unstackable_format_errors'
    modified:
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
    ------------------------------------------------------------
    revno: 3928.3.2
    revision-id: john at arbash-meinel.com-20090108194848-93vcyrrg1snzqqjd
    parent: john at arbash-meinel.com-20090108191520-ymp6abkgwvkz297o
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: stacking_tweaks
    timestamp: Thu 2009-01-08 13:48:48 -0600
    message:
      Track down the other cause of us connecting multiple times.
      
      The repository acquisition policy objects weren't re-using the connections that
      they knew about. This has been fixed.
      
      Now 'bzr push' connects a single time, rather than connecting 4 times when
      creating a new stacked-on branch, or 2 times for an existing stacked-on
      branch.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/tests/commands/test_push.py test_push.py-20070525122003-gc1ob0ea0nueoqgj-1
    ------------------------------------------------------------
    revno: 3928.3.1
    revision-id: john at arbash-meinel.com-20090108191520-ymp6abkgwvkz297o
    parent: pqm at pqm.ubuntu.com-20090108161207-d95v7ouel5ibahh0
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: stacking_tweaks
    timestamp: Thu 2009-01-08 13:15:20 -0600
    message:
      Fix Branch.open() so that for stacked branches we don't open multiple connections.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
=== modified file 'NEWS'
--- a/NEWS	2009-01-08 20:51:58 +0000
+++ b/NEWS	2009-01-09 05:29:09 +0000
@@ -48,13 +48,12 @@
 
   BUG FIXES:
   
-    * Fix a problem with CIFS client/server lag on windows colliding with
-      an invariant-per-process algorithm for generating AtomicFile names
-      (Adrian Wilkins, #304023)
-
     * Allow BzrDir implementation to implement backing up of 
       control directory. (#139691)
 
+    * ``bzr push`` creating a new stacked branch will now only open a
+      single connection to the target machine. (John Arbash Meinel)
+
     * Don't call iteritems on transport_list_registry, because it may
       change during iteration.  (Martin Pool, #277048)
 
@@ -65,6 +64,10 @@
     * Don't require embedding user in HTTP(S) URLs do use authentication.conf.
       (Ben Jansen, Vincent Ladeuil, #300347)
 
+    * Fix a problem with CIFS client/server lag on windows colliding with
+      an invariant-per-process algorithm for generating AtomicFile names
+      (Adrian Wilkins, #304023)
+
     * Fix bogus setUp signature in UnavailableFTPServer.
       (Gary van der Merwe, #313498)
 
@@ -87,6 +90,10 @@
       in the appropriate sections.
       (Vincent Ladeuil, #103029)
 
+    * Opening a stacked branch now properly shares the connection, rather
+      than opening a new connection for the stacked-on branch.
+      (John Arbash meinel)
+
     * Preserve transport decorators while following redirections.
       (Vincent Ladeuil, #245964, #270863)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-12-16 02:58:31 +0000
+++ b/bzrlib/branch.py	2009-01-08 19:15:20 +0000
@@ -2063,7 +2063,9 @@
     def _get_fallback_repository(self, url):
         """Get the repository we fallback to at url."""
         url = urlutils.join(self.base, url)
-        return bzrdir.BzrDir.open(url).open_branch().repository
+        a_bzrdir = bzrdir.BzrDir.open(url,
+                                      possible_transports=[self._transport])
+        return a_bzrdir.open_branch().repository
 
     def _activate_fallback_location(self, url):
         """Activate the branch/repository from url as a fallback repository."""

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2008-12-23 03:44:45 +0000
+++ b/bzrlib/bzrdir.py	2009-01-08 19:48:48 +0000
@@ -2902,12 +2902,13 @@
         else:
             return urlutils.join(self._stack_on_pwd, self._stack_on)
 
-    def _add_fallback(self, repository):
+    def _add_fallback(self, repository, possible_transports=None):
         """Add a fallback to the supplied repository, if stacking is set."""
         stack_on = self._get_full_stack_on()
         if stack_on is None:
             return
-        stacked_dir = BzrDir.open(stack_on)
+        stacked_dir = BzrDir.open(stack_on,
+                                  possible_transports=possible_transports)
         try:
             stacked_repo = stacked_dir.open_branch().repository
         except errors.NotBranchError:
@@ -2955,7 +2956,8 @@
         Creates the desired repository in the bzrdir we already have.
         """
         repository = self._bzrdir.create_repository(shared=shared)
-        self._add_fallback(repository)
+        self._add_fallback(repository,
+                           possible_transports=[self._bzrdir.transport])
         if make_working_trees is not None:
             repository.set_make_working_trees(make_working_trees)
         return repository
@@ -2982,7 +2984,8 @@
 
         Returns an existing repository to use
         """
-        self._add_fallback(self._repository)
+        self._add_fallback(self._repository,
+                       possible_transports=[self._repository.bzrdir.transport])
         return self._repository
 
 

=== modified file 'bzrlib/tests/branch_implementations/test_stacking.py'
--- a/bzrlib/tests/branch_implementations/test_stacking.py	2008-12-01 23:50:52 +0000
+++ b/bzrlib/tests/branch_implementations/test_stacking.py	2009-01-08 21:07:18 +0000
@@ -23,11 +23,17 @@
     )
 from bzrlib.revision import NULL_REVISION
 from bzrlib.smart import server
-from bzrlib.tests import TestNotApplicable, KnownFailure
+from bzrlib.tests import TestNotApplicable, KnownFailure, transport_util
 from bzrlib.tests.branch_implementations import TestCaseWithBranch
 from bzrlib.transport import get_transport
 
 
+unstackable_format_errors = (
+    errors.UnstackableBranchFormat,
+    errors.UnstackableRepositoryFormat,
+    )
+
+
 class TestStacking(TestCaseWithBranch):
 
     def check_lines_added_or_present(self, stacked_branch, revid):
@@ -47,15 +53,11 @@
         # permit stacking to be done and then return the stacked location.
         branch = self.make_branch('branch')
         target = self.make_branch('target')
-        old_format_errors = (
-            errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat,
-            )
         try:
             branch.set_stacked_on_url(target.base)
-        except old_format_errors:
+        except unstackable_format_errors:
             # if the set failed, so must the get
-            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
+            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
             return
         # now we have a stacked branch:
         self.assertEqual(target.base, branch.get_stacked_on_url())
@@ -66,15 +68,11 @@
         # Branches can be stacked on other branches using relative paths.
         branch = self.make_branch('branch')
         target = self.make_branch('target')
-        old_format_errors = (
-            errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat,
-            )
         try:
             branch.set_stacked_on_url('../target')
-        except old_format_errors:
+        except unstackable_format_errors:
             # if the set failed, so must the get
-            self.assertRaises(old_format_errors, branch.get_stacked_on_url)
+            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
             return
         self.assertEqual('../target', branch.get_stacked_on_url())
 
@@ -98,8 +96,7 @@
         new_branch = self.make_branch('new_branch')
         try:
             new_branch.set_stacked_on_url(trunk_tree.branch.base)
-        except (errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat), e:
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         # reading the graph from the stacked branch's repository should see
         # data from the stacked-on branch
@@ -118,8 +115,7 @@
         # and make branch from it which is stacked
         try:
             new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
-        except (errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat), e:
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         # stacked repository
         self.assertRevisionNotInRepository('newbranch', trunk_revid)
@@ -145,8 +141,7 @@
         # Make sure that we can make a stacked branch from it
         try:
             trunk_tree.bzrdir.sprout('testbranch', stacked=True)
-        except (errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat), e:
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         # Now serve the original mainline from a smart server
         remote_transport = self.make_smart_server('mainline')
@@ -168,8 +163,7 @@
         # and make branch from it which is stacked
         try:
             new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
-        except (errors.UnstackableBranchFormat,
-            errors.UnstackableRepositoryFormat), e:
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         # stacked repository
         self.assertRevisionNotInRepository('newbranch', trunk_revid)
@@ -208,17 +202,14 @@
         # same branch as the original.
         try:
             stacked_bzrdir = self.make_stacked_bzrdir()
-        except (errors.UnstackableBranchFormat,
-                errors.UnstackableRepositoryFormat), e:
-            # not a testable combination.
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
         try:
             self.assertEqual(
                 stacked_bzrdir.open_branch().get_stacked_on_url(),
                 cloned_bzrdir.open_branch().get_stacked_on_url())
-        except (errors.UnstackableBranchFormat,
-                errors.UnstackableRepositoryFormat):
+        except unstackable_format_errors, e:
             pass
 
     def test_clone_from_branch_stacked_on_relative_url_preserve_stacking(self):
@@ -227,9 +218,7 @@
         # on an appropriately adjusted relative url.
         try:
             stacked_bzrdir = self.make_stacked_bzrdir(in_directory='dir')
-        except (errors.UnstackableBranchFormat,
-                errors.UnstackableRepositoryFormat), e:
-            # not a testable combination.
+        except unstackable_format_errors, e:
             raise TestNotApplicable(e)
         stacked_bzrdir.open_branch().set_stacked_on_url('../stacked-on')
         cloned_bzrdir = stacked_bzrdir.clone('cloned', preserve_stacking=True)
@@ -240,8 +229,7 @@
     def test_clone_from_stacked_branch_no_preserve_stacking(self):
         try:
             stacked_bzrdir = self.make_stacked_bzrdir()
-        except (errors.UnstackableBranchFormat,
-                errors.UnstackableRepositoryFormat), e:
+        except unstackable_format_errors, e:
             # not a testable combination.
             raise TestNotApplicable(e)
         cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
@@ -286,8 +274,7 @@
         stack_on.commit('first commit', rev_id='rev1')
         try:
             stacked_dir = stack_on.bzrdir.sprout('stacked', stacked=True)
-        except (errors.UnstackableRepositoryFormat,
-                errors.UnstackableBranchFormat):
+        except unstackable_format_errors, e:
             raise TestNotApplicable('Format does not support stacking.')
         unstacked = self.make_repository('unstacked')
         return stacked_dir.open_workingtree(), unstacked
@@ -370,8 +357,7 @@
         target = self.make_branch('target')
         try:
             target.set_stacked_on_url('../stacked-on')
-        except (errors.UnstackableRepositoryFormat,
-                errors.UnstackableBranchFormat):
+        except unstackable_format_errors, e:
             raise TestNotApplicable('Format does not support stacking.')
 
         # Change the source branch.
@@ -393,8 +379,7 @@
         stacked = self.make_branch('stacked')
         try:
             stacked.set_stacked_on_url('../stack-on')
-        except (errors.UnstackableRepositoryFormat,
-                errors.UnstackableBranchFormat):
+        except unstackable_format_errors, e:
             raise TestNotApplicable('Format does not support stacking.')
         self.get_transport().rename('stack-on', 'new-stack-on')
         hook_calls = []
@@ -423,3 +408,37 @@
         b.bzrdir.clone_on_transport(transport, stacked_on=b.base)
         # Ensure that opening the branch doesn't raise.
         branch.Branch.open(transport.base)
+
+
+class TestStackingConnections(
+    transport_util.TestCaseWithConnectionHookedTransport):
+
+    def setUp(self):
+        super(TestStackingConnections, self).setUp()
+        try:
+            base_tree = self.make_branch_and_tree('base',
+                                                  format=self.bzrdir_format)
+        except errors.UninitializableFormat, e:
+            raise TestNotApplicable(e)
+        stacked = self.make_branch('stacked', format=self.bzrdir_format)
+        try:
+            stacked.set_stacked_on_url(base_tree.branch.base)
+        except unstackable_format_errors, e:
+            raise TestNotApplicable(e)
+        base_tree.commit('first', rev_id='rev-base')
+        stacked.set_last_revision_info(1, 'rev-base')
+        stacked_relative = self.make_branch('stacked_relative',
+                                            format=self.bzrdir_format)
+        stacked_relative.set_stacked_on_url('../base')
+        stacked.set_last_revision_info(1, 'rev-base')
+        self.start_logging_connections()
+
+    def test_open_stacked(self):
+        b = branch.Branch.open(self.get_url('stacked'))
+        rev = b.repository.get_revision('rev-base')
+        self.assertEqual(1, len(self.connections))
+
+    def test_open_stacked_relative(self):
+        b = branch.Branch.open(self.get_url('stacked_relative'))
+        rev = b.repository.get_revision('rev-base')
+        self.assertEqual(1, len(self.connections))

=== modified file 'bzrlib/tests/commands/test_push.py'
--- a/bzrlib/tests/commands/test_push.py	2008-06-06 02:20:29 +0000
+++ b/bzrlib/tests/commands/test_push.py	2009-01-08 19:48:48 +0000
@@ -32,3 +32,15 @@
         cmd.outf = tests.StringIOWrapper()
         cmd.run(self.get_url('remote'), directory='branch')
         self.assertEquals(1, len(self.connections))
+
+    def test_push_onto_stacked(self):
+        self.make_branch_and_tree('base', format='1.9')
+        self.make_branch_and_tree('source', format='1.9')
+
+        self.start_logging_connections()
+
+        cmd = cmd_push()
+        cmd.outf = tests.StringIOWrapper()
+        cmd.run(self.get_url('remote'), directory='source',
+                stacked_on=self.get_url('base'))
+        self.assertEqual(1, len(self.connections))

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py	2009-01-08 16:57:10 +0000
+++ b/bzrlib/tests/test_bzrdir.py	2009-01-09 05:29:09 +0000
@@ -180,7 +180,7 @@
             'Pre-0.8 format.  Slower and does not support checkouts or shared'
             ' repositories', deprecated=True, alias=True)
         self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
-    
+
 
 class SampleBranch(bzrlib.branch.Branch):
     """A dummy branch for guess what, dummy use."""
@@ -189,6 +189,13 @@
         self.bzrdir = dir
 
 
+class SampleRepository(bzrlib.repository.Repository):
+    """A dummy repo."""
+
+    def __init__(self, dir):
+        self.bzrdir = dir
+
+
 class SampleBzrDir(bzrdir.BzrDir):
     """A sample BzrDir implementation to allow testing static methods."""
 
@@ -198,7 +205,7 @@
 
     def open_repository(self):
         """See BzrDir.open_repository."""
-        return "A repository"
+        return SampleRepository(self)
 
     def create_branch(self):
         """See BzrDir.create_branch."""




More information about the bazaar-commits mailing list