Rev 3929: Fix Branch.open() so that for stacked branches we don't open multiple connections. in http://bzr.arbash-meinel.com/branches/bzr/1.11/stacking_tweaks
John Arbash Meinel
john at arbash-meinel.com
Thu Jan 8 19:15:41 GMT 2009
At http://bzr.arbash-meinel.com/branches/bzr/1.11/stacking_tweaks
------------------------------------------------------------
revno: 3929
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.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-01-08 16:12:07 +0000
+++ b/NEWS 2009-01-08 19:15:20 +0000
@@ -87,6 +87,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/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 19:15:20 +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
+old_format_errors = (
+ errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat,
+ )
+
+
class TestStacking(TestCaseWithBranch):
def check_lines_added_or_present(self, stacked_branch, revid):
@@ -47,10 +53,6 @@
# 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:
@@ -66,10 +68,6 @@
# 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:
@@ -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 old_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 old_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 old_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 old_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 old_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 old_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 old_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 old_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 old_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 old_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 old_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 old_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))
More information about the bazaar-commits
mailing list