transport layer and multiple connections (was Re: [PATCH] FTP transport)
Matthieu Moy
Matthieu.Moy at imag.fr
Sun Nov 20 02:29:31 GMT 2005
Daniel Silverstone <dsilvers at digital-scurf.org> writes:
>> (I don't know whether this comes from the transport layer of from
>> ftp.py itself, though)
>
> The transport layer clones several times before it ever does anything,
> which caused the connection to be created several times because it was
> lazy. Now it's lazy but memoized safely.
Actually, I believe this should be fixed in the transport layer
itself. get_transport may be called several times with the same
argument (an example in "push" :
try:
br_to = Branch.open(location) # <- calls get_transport(location)
except NotBranchError:
# create a branch.
transport = get_transport(location).clone('..')
)
A relatively simple fix would be to keep a dictionary
(location -> transport), and to reuse the existing one if it exists in
get_location.
The patch below does this, but it seems too obvious to be true. Is
there a reason not to do it this way? Well, at least, a
"push sftp://host.com/not/yet/created/directory" promps my password
once instead of three times.
=== modified file 'bzrlib/transport/__init__.py'
--- bzrlib/transport/__init__.py
+++ bzrlib/transport/__init__.py
@@ -352,13 +352,21 @@
raise NotImplementedError
+transport_pool = {};
+
def get_transport(base):
global _protocol_handlers
if base is None:
base = '.'
for proto, klass in _protocol_handlers.iteritems():
if proto is not None and base.startswith(proto):
- return klass(base)
+ # check in the pool only if "base" matches a protocol.
+ # (avoids problems with relative paths)
+ if transport_pool.has_key(base):
+ return transport_pool[base]
+ k = klass(base)
+ transport_pool[base] = k
+ return k
# The default handler is the filesystem handler
# which has a lookup of None
return _protocol_handlers[None](base)
--
Matthieu
More information about the bazaar
mailing list