Rev 2813: (vila) avoid repeated connections from bzr update in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Sep 11 03:55:02 BST 2007


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

------------------------------------------------------------
revno: 2813
revision-id: pqm at pqm.ubuntu.com-20070911025457-xd28g5hqu9jco1sm
parent: pqm at pqm.ubuntu.com-20070911020027-bmt9h0jgy3zdlge3
parent: mbp at sourcefrog.net-20070911012409-c2ln3x5v53weqf9c
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-09-11 03:54:57 +0100
message:
  (vila) avoid repeated connections from bzr update
added:
  bzrlib/tests/commands/test_update.py test_update.py-20070910091045-8uyp8v73j926l1g2-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/tests/commands/__init__.py __init__.py-20070520095518-ecfl8531fxgjeycj-1
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 2810.2.2
    merged: mbp at sourcefrog.net-20070911012409-c2ln3x5v53weqf9c
    parent: mbp at sourcefrog.net-20070911002726-xqvjood96a36ue2m
    parent: pqm at pqm.ubuntu.com-20070911010353-6lu7ek40rbjhj86o
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Tue 2007-09-11 11:24:09 +1000
    message:
      merge news
    ------------------------------------------------------------
    revno: 2810.2.1
    merged: mbp at sourcefrog.net-20070911002726-xqvjood96a36ue2m
    parent: pqm at pqm.ubuntu.com-20070910121243-ccy1gej0kqy4feen
    parent: v.ladeuil+lp at free.fr-20070910121247-sxf4l4pq1e27380p
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: integration
    timestamp: Tue 2007-09-11 10:27:26 +1000
    message:
      merge vincent and cleanup
    ------------------------------------------------------------
    revno: 2806.2.2
    merged: v.ladeuil+lp at free.fr-20070910121247-sxf4l4pq1e27380p
    parent: v.ladeuil+lp at free.fr-20070910091350-mnrhuokhmj2vxim0
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 128076
    timestamp: Mon 2007-09-10 14:12:47 +0200
    message:
      Fix #128076 and #131396 by reusing bound branch transport.
      
      * bzrlib/bzrdir.py:
      (BzrDir.open): Add possible_transports as the last parameter.
      
      * bzrlib/builtins.py:
      (cmd_update.run): Use possible_transports parameter to obtain the
      master branch transport and reuse it.
      
      * bzrlib/branch.py:
      (Branch.open, Branch.get_master_branch,
      BzrBranch5.get_master_branch, BzrBranch5.update): Add
      possible_transports as the last parameter.
      
      * bzrlib/workingtree.py:
      (WorkingTree.update): Add possible_transports as the last parameter.
      
      * bzrlib/tests/commands/test_update.py:
      (TestUpdate.test_update): Ignore connections from bind.
    ------------------------------------------------------------
    revno: 2806.2.1
    merged: v.ladeuil+lp at free.fr-20070910091350-mnrhuokhmj2vxim0
    parent: pqm at pqm.ubuntu.com-20070910054843-evbkt0bivtk6tpqu
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 128076
    timestamp: Mon 2007-09-10 11:13:50 +0200
    message:
      Reproduce #131396 and #128076 in the test suite.
=== added file 'bzrlib/tests/commands/test_update.py'
--- a/bzrlib/tests/commands/test_update.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/commands/test_update.py	2007-09-10 12:12:47 +0000
@@ -0,0 +1,40 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+from bzrlib import builtins
+from bzrlib.tests.transport_util import TestCaseWithConnectionHookedTransport
+
+
+class TestUpdate(TestCaseWithConnectionHookedTransport):
+
+    def test_update(self):
+        wt1 = self.make_branch_and_tree('branch1')
+        wt2 = self.make_branch_and_tree('branch2')
+        wt2.pull(wt1.branch)
+
+        wt1.commit('empty commit')
+        wt2.commit('empty commit too')
+
+        bind = builtins.cmd_bind()
+        bind.run(location=self.get_url('branch1'))
+
+        self.install_hooks()
+
+        update = builtins.cmd_update()
+        update.run()
+        self.assertEquals(1, len(self.connections))
+

=== modified file 'NEWS'
--- a/NEWS	2007-09-11 02:00:27 +0000
+++ b/NEWS	2007-09-11 02:54:57 +0000
@@ -126,6 +126,10 @@
    * Prompt for an ftp password if none is provided.
      (Vincent Ladeuil, #137044)
 
+   * Reuse bound branch associated transport to avoid multiple
+     connections.
+     (Vincent Ladeuil, #128076, #131396)
+
    * Overwrite conflicting tags by ``push`` and ``pull`` if the
      ``--overwrite`` option is specified.  (Lukáš Lalinský, #93947)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-09-07 11:37:13 +0000
+++ b/bzrlib/branch.py	2007-09-11 01:24:09 +0000
@@ -117,13 +117,14 @@
             master.break_lock()
 
     @staticmethod
-    def open(base, _unsupported=False):
+    def open(base, _unsupported=False, possible_transports=None):
         """Open the branch rooted at base.
 
         For instance, if the branch is at URL/.bzr/branch,
         Branch.open(URL) -> a Branch instance.
         """
-        control = bzrdir.BzrDir.open(base, _unsupported)
+        control = bzrdir.BzrDir.open(base, _unsupported,
+                                     possible_transports=possible_transports)
         return control.open_branch(_unsupported)
 
     @staticmethod
@@ -320,7 +321,7 @@
         return self.repository.get_commit_builder(self, parents, config,
             timestamp, timezone, committer, revprops, revision_id)
 
-    def get_master_branch(self):
+    def get_master_branch(self, possible_transports=None):
         """Return the branch we are bound to.
         
         :return: Either a Branch, or None
@@ -1648,7 +1649,7 @@
 
 
 class BzrBranch5(BzrBranch):
-    """A format 5 branch. This supports new features over plan branches.
+    """A format 5 branch. This supports new features over plain branches.
 
     It has support for a master_branch which is the data for bound branches.
     """
@@ -1697,7 +1698,7 @@
             return None
 
     @needs_read_lock
-    def get_master_branch(self):
+    def get_master_branch(self, possible_transports=None):
         """Return the branch we are bound to.
         
         :return: Either a Branch, or None
@@ -1711,7 +1712,8 @@
         if not bound_loc:
             return None
         try:
-            return Branch.open(bound_loc)
+            return Branch.open(bound_loc,
+                               possible_transports=possible_transports)
         except (errors.NotBranchError, errors.ConnectionError), e:
             raise errors.BoundBranchConnectionFailure(
                     self, bound_loc, e)
@@ -1779,13 +1781,13 @@
         return self.set_bound_location(None)
 
     @needs_write_lock
-    def update(self):
+    def update(self, possible_transports=None):
         """Synchronise this branch with the master branch if any. 
 
         :return: None or the last_revision that was pivoted out during the
                  update.
         """
-        master = self.get_master_branch()
+        master = self.get_master_branch(possible_transports)
         if master is not None:
             old_tip = _mod_revision.ensure_null(self.last_revision())
             self.pull(master, overwrite=True)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-09-10 10:05:51 +0000
+++ b/bzrlib/builtins.py	2007-09-11 00:27:26 +0000
@@ -1016,7 +1016,9 @@
 
     def run(self, dir='.'):
         tree = WorkingTree.open_containing(dir)[0]
-        master = tree.branch.get_master_branch()
+        possible_transports = []
+        master = tree.branch.get_master_branch(
+            possible_transports=possible_transports)
         if master is not None:
             tree.lock_write()
         else:
@@ -1032,8 +1034,9 @@
                     revno = tree.branch.revision_id_to_revno(last_rev)
                     note("Tree is up to date at revision %d." % (revno,))
                     return 0
-            conflicts = tree.update(delta._ChangeReporter(
-                                        unversioned_filter=tree.is_ignored))
+            conflicts = tree.update(
+                delta._ChangeReporter(unversioned_filter=tree.is_ignored),
+                possible_transports=possible_transports)
             revno = tree.branch.revision_id_to_revno(
                 _mod_revision.ensure_null(tree.last_revision()))
             note('Updated to revision %d.' % (revno,))

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-09-05 03:20:26 +0000
+++ b/bzrlib/bzrdir.py	2007-09-10 12:12:47 +0000
@@ -533,12 +533,12 @@
         return BzrDir.open(base, _unsupported=True)
         
     @staticmethod
-    def open(base, _unsupported=False):
+    def open(base, _unsupported=False, possible_transports=None):
         """Open an existing bzrdir, rooted at 'base' (url)
         
         _unsupported is a private parameter to the BzrDir class.
         """
-        t = get_transport(base)
+        t = get_transport(base, possible_transports=possible_transports)
         return BzrDir.open_from_transport(t, _unsupported=_unsupported)
 
     @staticmethod

=== modified file 'bzrlib/tests/commands/__init__.py'
--- a/bzrlib/tests/commands/__init__.py	2007-07-15 11:17:19 +0000
+++ b/bzrlib/tests/commands/__init__.py	2007-09-10 09:13:50 +0000
@@ -35,6 +35,7 @@
         'bzrlib.tests.commands.test_missing',
         'bzrlib.tests.commands.test_pull',
         'bzrlib.tests.commands.test_push',
+        'bzrlib.tests.commands.test_update',
         ]
     loader = TestLoader()
     suite = loader.loadTestsFromModuleNames(testmod_names)

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-09-05 03:20:26 +0000
+++ b/bzrlib/workingtree.py	2007-09-10 12:12:47 +0000
@@ -2022,7 +2022,7 @@
         """
         raise NotImplementedError(self.unlock)
 
-    def update(self, change_reporter=None):
+    def update(self, change_reporter=None, possible_transports=None):
         """Update a working tree along its branch.
 
         This will update the branch if its bound too, which means we have
@@ -2047,7 +2047,7 @@
           basis.
         - Do a 'normal' merge of the old branch basis if it is relevant.
         """
-        if self.branch.get_master_branch() is not None:
+        if self.branch.get_master_branch(possible_transports) is not None:
             self.lock_write()
             update_branch = True
         else:
@@ -2055,7 +2055,7 @@
             update_branch = False
         try:
             if update_branch:
-                old_tip = self.branch.update()
+                old_tip = self.branch.update(possible_transports)
             else:
                 old_tip = None
             return self._update_tree(old_tip, change_reporter)




More information about the bazaar-commits mailing list