Rev 2499: merge fix for bug 111702 in file:///v/home/vila/src/experimental/reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue May 29 14:35:19 BST 2007
At file:///v/home/vila/src/experimental/reuse.transports/
------------------------------------------------------------
revno: 2499
revision-id: v.ladeuil+lp at free.fr-20070529133516-z5bc236n3qk5b6ex
parent: v.ladeuil+lp at free.fr-20070529132124-zszi9sihkjcro6ko
parent: v.ladeuil+lp at free.fr-20070529131741-df4zd9ko5y1w1g6d
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Tue 2007-05-29 15:35:16 +0200
message:
merge fix for bug 111702
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/test_bzrdir.py test_bzrdir.py-20060131065654-deba40eef51cf220
bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
bzrlib/transport/sftp.py sftp.py-20051019050329-ab48ce71b7e32dfe
------------------------------------------------------------
revno: 2476.3.13
revision-id: v.ladeuil+lp at free.fr-20070529131741-df4zd9ko5y1w1g6d
parent: v.ladeuil+lp at free.fr-20070504103507-cm0woizea22taavd
parent: pqm at pqm.ubuntu.com-20070525050023-ip6kst9coq8a32z5
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Tue 2007-05-29 15:17:41 +0200
message:
merge bzr.dev at 2495
------------------------------------------------------------
revno: 2476.3.12
revision-id: v.ladeuil+lp at free.fr-20070504103507-cm0woizea22taavd
parent: v.ladeuil+lp at free.fr-20070504103356-c371vuio9ldhnaw8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Fri 2007-05-04 12:35:07 +0200
message:
Fix bug #111702 with a first attempt to refactor Transport.get_transport()
------------------------------------------------------------
revno: 2476.3.11
revision-id: v.ladeuil+lp at free.fr-20070504103356-c371vuio9ldhnaw8
parent: v.ladeuil+lp at free.fr-20070504102643-3qbwrvmvzjildjez
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Fri 2007-05-04 12:33:56 +0200
message:
Cosmetic changes.
------------------------------------------------------------
revno: 2476.3.10
revision-id: v.ladeuil+lp at free.fr-20070504102643-3qbwrvmvzjildjez
parent: v.ladeuil+lp at free.fr-20070503212944-naxq1qsq297uxauz
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Fri 2007-05-04 12:26:43 +0200
message:
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
------------------------------------------------------------
revno: 2476.3.9
revision-id: v.ladeuil+lp at free.fr-20070503212944-naxq1qsq297uxauz
parent: v.ladeuil+lp at free.fr-20070503212714-3sbdmehsv8kemomw
parent: pqm at pqm.ubuntu.com-20070503194912-pzlcms91kk2uqfdo
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Thu 2007-05-03 23:29:44 +0200
message:
merge bzr.dev at 2480
------------------------------------------------------------
revno: 2476.3.8
revision-id: v.ladeuil+lp at free.fr-20070503212714-3sbdmehsv8kemomw
parent: v.ladeuil+lp at free.fr-20070503124529-3na89ialmyl9bogy
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Thu 2007-05-03 23:27:14 +0200
message:
Mark transports that need to be instrumented or refactored to check
multiple connections. Various cosmetic changes.
------------------------------------------------------------
revno: 2476.3.7
revision-id: v.ladeuil+lp at free.fr-20070503124529-3na89ialmyl9bogy
parent: v.ladeuil+lp at free.fr-20070503113827-25fhckdmd2oslags
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Thu 2007-05-03 14:45:29 +0200
message:
Fix failing tests.
* tests/test_bzrdir.py:
(SampleBzrDirFormat.initialize): Add a transports parameter for reuse.
------------------------------------------------------------
revno: 2476.3.6
revision-id: v.ladeuil+lp at free.fr-20070503113827-25fhckdmd2oslags
parent: v.ladeuil+lp at free.fr-20070503095947-k2o8rnp5ug6uriu1
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Thu 2007-05-03 13:38:27 +0200
message:
Fix the 'init connects multiple times' in a different way.
* transport/__init__.py:
(get_transport): Make transports default to None instead of [],
it's easier and less confusing in its other uses.
* tests/test_bzrdir.py:
(TestBzrDirFormat): Remove the test, the new fix is harder to test
for. What we really want to test is that *connections* are reused,
LocalTransport.clone create new objects anyway, so there is no way
to verify that a LocalTransport is really reused. So we must
instrument transports that use connection to be able to catch
multiple connections.
* bzrdir.py:
(BzrDir.create): Add a transports parameter for reuse.
(BzrDir.create_branch_convenience): Add a transports parameter for
reuse.
(BzrDirFormat.initialize): Add a transports parameter for reuse.
* builtins.py:
(cmd_init.run): Pass the known transport to
create_branch_convenience in its own list.
------------------------------------------------------------
revno: 2476.3.5
revision-id: v.ladeuil+lp at free.fr-20070503095947-k2o8rnp5ug6uriu1
parent: v.ladeuil+lp at free.fr-20070502203101-prcuwowzkz5qh0gn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Thu 2007-05-03 11:59:47 +0200
message:
Naive implementation of transport reuse by Transport.get_transport().
* transport/__init__.py:
(get_transport): Accept a list of reusable transports as a
parameter.
* tests/test_transport.py:
(TestReusedTransports): Some basic tests.
------------------------------------------------------------
revno: 2476.3.4
revision-id: v.ladeuil+lp at free.fr-20070502203101-prcuwowzkz5qh0gn
parent: v.ladeuil+lp at free.fr-20070502201837-od1q12zbvr90kyni
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Wed 2007-05-02 22:31:01 +0200
message:
Add tests.
* tests/test_bzrdir.py:
(TestBzrDirFormat): Add tests for the new parameters.
------------------------------------------------------------
revno: 2476.3.3
revision-id: v.ladeuil+lp at free.fr-20070502201837-od1q12zbvr90kyni
parent: v.ladeuil+lp at free.fr-20070502162141-zwqhrx0ydx7hzwv0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Wed 2007-05-02 22:18:37 +0200
message:
Fix bug #111702.
* bzrdir.py:
(BzrDir.create_branch_convenience): Add 'transport' as an
alternate way to specify the URL to create the branch at.
* builtins.py:
(cmd_init.run): We have a transport, use it.
------------------------------------------------------------
revno: 2476.3.2
revision-id: v.ladeuil+lp at free.fr-20070502162141-zwqhrx0ydx7hzwv0
parent: v.ladeuil+lp at free.fr-20070502144224-xgusmp6ra32m055m
parent: john at arbash-meinel.com-20070502145420-k2vebnl0rd45q8kk
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Wed 2007-05-02 18:21:41 +0200
message:
merge jam's second fix for bug 75721
------------------------------------------------------------
revno: 2476.3.1
revision-id: v.ladeuil+lp at free.fr-20070502144224-xgusmp6ra32m055m
parent: pqm at pqm.ubuntu.com-20070502125159-zpnij2o99tlddedp
parent: john at arbash-meinel.com-20070502143655-id25373m3lgue8ke
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 111702
timestamp: Wed 2007-05-02 16:42:24 +0200
message:
merge jam's fix for bug 75721
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2007-05-25 04:00:47 +0000
+++ b/NEWS 2007-05-29 13:17:41 +0000
@@ -52,6 +52,13 @@
the root of the source tree and allows HACKING to be split into multiple
files. (Robert Collins, Alexander Belchenko)
+ * ``bzr init`` should only connect to the remote location one time.
+ We have been connecting several times because we forget to pass
+ around the Transport object. This modifies
+ ``BzrDir.create_branch_convenience``, so that we can pass in the
+ Transport that we already have.
+ (John Arbash Meinel, Vincent Ladeuil, #111702)
+
bzr 0.16rc2 2007-04-30
BUGFIXES:
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-05-29 13:21:24 +0000
+++ b/bzrlib/builtins.py 2007-05-29 13:35:16 +0000
@@ -1278,23 +1278,16 @@
to_transport = transport.get_transport(location)
- # The path has to exist to initialize a
- # branch inside of it.
- # Just using os.mkdir, since I don't
- # believe that we want to create a bunch of
- # locations if the user supplies an extended path
# TODO: create-prefix
to_transport.ensure_base()
try:
- # FIXME: Reuse to_transport instead of location
- existing_bzrdir = bzrdir.BzrDir.open(location)
+ existing_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
except errors.NotBranchError:
# really a NotBzrDir error...
- # FIXME: Reuse to_transport instead of
- # to_transport.base (nastier than above)
- branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
- format=format)
+ create_branch = bzrdir.BzrDir.create_branch_convenience
+ branch = create_branch(to_transport.base, format=format,
+ possible_transports=[to_transport])
else:
from bzrlib.transport.local import LocalTransport
if existing_bzrdir.has_branch():
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2007-05-02 14:54:20 +0000
+++ b/bzrlib/bzrdir.py 2007-05-04 10:33:56 +0000
@@ -213,9 +213,8 @@
t = get_transport(url)
t.ensure_base()
- # TODO: Should take a Transport
@classmethod
- def create(cls, base, format=None):
+ def create(cls, base, format=None, possible_transports=None):
"""Create a new BzrDir at the url 'base'.
This will call the current default formats initialize with base
@@ -223,15 +222,17 @@
:param format: If supplied, the format of branch to create. If not
supplied, the default is used.
+ :param possible_transports: If supplied, a list of transports that
+ can be reused to share a remote connection.
"""
if cls is not BzrDir:
raise AssertionError("BzrDir.create always creates the default"
" format, not one of %r" % cls)
- t = get_transport(base)
+ t = get_transport(base, possible_transports)
t.ensure_base()
if format is None:
format = BzrDirFormat.get_default_format()
- return format.initialize(safe_unicode(base))
+ return format.initialize(safe_unicode(base), possible_transports)
def create_branch(self):
"""Create a branch in this BzrDir.
@@ -270,7 +271,8 @@
@staticmethod
def create_branch_convenience(base, force_new_repo=False,
- force_new_tree=None, format=None):
+ force_new_tree=None, format=None,
+ possible_transports=None):
"""Create a new BzrDir, Branch and Repository at the url 'base'.
This is a convenience function - it will use an existing repository
@@ -292,24 +294,25 @@
:param force_new_repo: If True a new repository is always created.
:param force_new_tree: If True or False force creation of a tree or
prevent such creation respectively.
- :param format: Override for the for the bzrdir format to create
+ :param format: Override for the for the bzrdir format to create.
+ :param possible_transports: An optional reusable transports list.
"""
if force_new_tree:
# check for non local urls
- t = get_transport(safe_unicode(base))
+ t = get_transport(safe_unicode(base), possible_transports)
if not isinstance(t, LocalTransport):
raise errors.NotLocalUrl(base)
- bzrdir = BzrDir.create(base, format)
+ bzrdir = BzrDir.create(base, format, possible_transports)
repo = bzrdir._find_or_create_repository(force_new_repo)
result = bzrdir.create_branch()
- if force_new_tree or (repo.make_working_trees() and
+ if force_new_tree or (repo.make_working_trees() and
force_new_tree is None):
try:
bzrdir.create_workingtree()
except errors.NotLocalUrl:
pass
return result
-
+
@staticmethod
def create_repository(base, shared=False, format=None):
"""Create a new BzrDir and Repository at the url 'base'.
@@ -1291,13 +1294,14 @@
"""
raise NotImplementedError(self.get_converter)
- def initialize(self, url):
+ def initialize(self, url, possible_transports=None):
"""Create a bzr control dir at this url and return an opened copy.
Subclasses should typically override initialize_on_transport
instead of this method.
"""
- return self.initialize_on_transport(get_transport(url))
+ return self.initialize_on_transport(get_transport(url,
+ possible_transports))
def initialize_on_transport(self, transport):
"""Initialize a new bzrdir in the base directory of a Transport."""
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py 2007-04-05 09:35:26 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2007-05-04 10:26:43 +0000
@@ -198,9 +198,9 @@
"""See BzrDirFormat.get_format_string()."""
return "Sample .bzr dir format."
- def initialize(self, url):
+ def initialize(self, url, possible_transports=None):
"""Create a bzr dir."""
- t = get_transport(url)
+ t = get_transport(url, possible_transports)
t.mkdir('.bzr')
t.put_bytes('.bzr/branch-format', self.get_format_string())
return SampleBzrDir(t, self)
@@ -288,7 +288,7 @@
def test_create_branch_and_repo_uses_default(self):
format = SampleBzrDirFormat()
- branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
+ branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
format=format)
self.assertTrue(isinstance(branch, SampleBranch))
@@ -343,6 +343,15 @@
branch.bzrdir.open_workingtree()
branch.bzrdir.open_repository()
+ def test_create_branch_convenience_possible_transports(self):
+ """Check that the optional 'possible_transports' is recognized"""
+ format = bzrdir.format_registry.make_bzrdir('knit')
+ t = self.get_transport()
+ branch = bzrdir.BzrDir.create_branch_convenience(
+ '.', format=format, possible_transports=[t])
+ branch.bzrdir.open_workingtree()
+ branch.bzrdir.open_repository()
+
def test_create_branch_convenience_root(self):
"""Creating a branch at the root of a fs should work."""
self.vfs_transport_factory = MemoryServer
=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py 2007-05-04 10:41:31 +0000
+++ b/bzrlib/tests/test_transport.py 2007-05-29 13:17:41 +0000
@@ -594,6 +594,19 @@
self.assertEquals(t.base, 'file://HOST/')
+class TestReusedTransports(TestCase):
+
+ def test_reuse_same_transport(self):
+ t = get_transport('http://foo/')
+ t2 = get_transport('http://foo/', possible_transports=[t])
+ self.assertIs(t, t2)
+
+ def test_don_t_reuse_different_transport(self):
+ t = get_transport('http://foo/')
+ t2 = get_transport('http://bar/', possible_transports=[t])
+ self.assertIsNot(t, t2)
+
+
def get_test_permutations():
"""Return transport permutations to be used in testing.
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-05-08 20:00:50 +0000
+++ b/bzrlib/transport/__init__.py 2007-05-29 13:17:41 +0000
@@ -1038,13 +1038,12 @@
urlunescape = urlutils.unescape
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<path>.*)$')
-
-def get_transport(base):
+def get_transport(base, possible_transports=None):
"""Open a transport to access a URL or directory.
- base is either a URL or a directory name.
+ :param base: either a URL or a directory name.
+ :param transports: optional reusable transports list.
"""
-
if base is None:
base = '.'
last_err = None
@@ -1067,21 +1066,32 @@
# Only local paths can be Unicode
base = convert_path_to_url(base,
'URLs must be properly escaped (protocol: %s)')
-
- for proto, factory_list in transport_list_registry.iteritems():
- if proto is not None and base.startswith(proto):
- t, last_err = _try_transport_factories(base, factory_list)
- if t:
- return t
-
- # We tried all the different protocols, now try one last time
- # as a local protocol
- base = convert_path_to_url(base, 'Unsupported protocol: %s')
-
- # The default handler is the filesystem handler, stored as protocol None
- return _try_transport_factories(base,
- transport_list_registry.get(None))[0]
-
+
+ transport = None
+ if possible_transports:
+ for t in possible_transports:
+ if t.base == base:
+ transport = t
+ break
+ if transport is None:
+ for proto, factory_list in transport_list_registry.iteritems():
+ if proto is not None and base.startswith(proto):
+ transport, last_err = _try_transport_factories(base,
+ factory_list)
+ if transport:
+ break
+ if transport is None:
+ # We tried all the different protocols, now try one last
+ # time as a local protocol
+ base = convert_path_to_url(base, 'Unsupported protocol: %s')
+
+ # The default handler is the filesystem handler, stored
+ # as protocol None
+ factory_list = transport_list_registry.get(None)
+ transport, last_err = _try_transport_factories(base, factory_list)
+ return transport
+
+
def do_catching_redirections(action, transport, redirected):
"""Execute an action with given transport catching redirections.
=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py 2007-05-29 13:14:04 +0000
+++ b/bzrlib/transport/ftp.py 2007-05-29 13:35:16 +0000
@@ -69,6 +69,7 @@
mutter("Constructing FTP instance against %r" % (alt_key,))
conn = ftplib.FTP()
+ # FIXME: instrument or refactor to allow testing for mutiple connections
conn.connect(host=hostname, port=port)
if username and username != 'anonymous' and not password:
password = bzrlib.ui.ui_factory.get_password(
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-04-22 16:32:04 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-05-04 10:26:43 +0000
@@ -235,6 +235,7 @@
handler_order = 1000 # after all pre-processings
+ # FIXME: instrument or refactor to allow testing for mutiple connections
def create_connection(self, request, http_connection_class):
host = request.get_host()
if not host:
=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py 2007-04-16 04:24:11 +0000
+++ b/bzrlib/transport/sftp.py 2007-05-04 10:26:43 +0000
@@ -824,6 +824,7 @@
# that we have taken the lock.
return SFTPLock(relpath, self)
+ # FIXME: instrument or refactor to allow testing for mutiple connections
def _sftp_connect(self):
"""Connect to the remote sftp server.
After this, self._sftp should have a valid connection (or
More information about the bazaar-commits
mailing list