Rev 2482: Fix the 'init connects multiple times' in a different way. in file:///v/home/vila/src/bugs/111702/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu May 3 12:38:34 BST 2007
At file:///v/home/vila/src/bugs/111702/
------------------------------------------------------------
revno: 2482
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.
modified:
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/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-05-02 20:18:37 +0000
+++ b/bzrlib/builtins.py 2007-05-03 11:38:27 +0000
@@ -1285,7 +1285,8 @@
except errors.NotBranchError:
# really a NotBzrDir error...
create_branch= bzrdir.BzrDir.create_branch_convenience
- branch = create_branch(transport=to_transport, format=format)
+ branch = create_branch(to_transport.base, format=format,
+ 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 20:31:01 +0000
+++ b/bzrlib/bzrdir.py 2007-05-03 11:38:27 +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, transports=None):
"""Create a new BzrDir at the url 'base'.
This will call the current default formats initialize with base
@@ -227,11 +226,11 @@
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, 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), transports)
def create_branch(self):
"""Create a branch in this BzrDir.
@@ -267,11 +266,11 @@
return self.find_repository()
except errors.NoRepositoryPresent:
return self.create_repository()
-
+
@staticmethod
- def create_branch_convenience(base=None, transport=None,
- force_new_repo=False, force_new_tree=None,
- format=None):
+ def create_branch_convenience(base, force_new_repo=False,
+ force_new_tree=None, format=None,
+ transports=None,):
"""Create a new BzrDir, Branch and Repository at the url 'base'.
This is a convenience function - it will use an existing repository
@@ -290,28 +289,18 @@
data is created on disk and NotLocalUrl is raised.
:param base: The URL to create the branch at.
- :param transport: An alternate way to specify the URL.
- 'format' must also be specified.
: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 transports: An optional reusable transports list.
"""
- if base is None and transport is None:
- raise AssertionError('You should specify one of '
- 'base or transport parameter')
if force_new_tree:
- if base:
- transport = get_transport(base)
# check for non local urls
- if not isinstance(transport, LocalTransport):
- raise errors.NotLocalUrl(transport.base)
- if format is None:
- format = BzrDirFormat.get_default_format()
- if base:
- bzrdir = BzrDir.create(base, format)
- else:
- bzrdir = format.initialize_on_transport(transport)
+ t = get_transport(safe_unicode(base), transports)
+ if not isinstance(t, LocalTransport):
+ raise errors.NotLocalUrl(base)
+ bzrdir = BzrDir.create(base, format, transports)
repo = bzrdir._find_or_create_repository(force_new_repo)
result = bzrdir.create_branch()
if force_new_tree or (repo.make_working_trees() and
@@ -1303,13 +1292,13 @@
"""
raise NotImplementedError(self.get_converter)
- def initialize(self, url):
+ def initialize(self, url, 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, 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-05-02 20:31:01 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2007-05-03 11:38:27 +0000
@@ -336,11 +336,6 @@
format=format)
tree.bzrdir.open_repository()
- def test_create_branch_convenience_mising_parameter(self):
- # at least one of base or transport should be provided
- self.assertRaises(AssertionError,
- bzrdir.BzrDir.create_branch_convenience)
-
def test_create_branch_convenience(self):
# outside a repo the default convenience output is a repo+branch_tree
format = bzrdir.format_registry.make_bzrdir('knit')
@@ -348,15 +343,6 @@
branch.bzrdir.open_workingtree()
branch.bzrdir.open_repository()
- def test_create_branch_convenience_with_transport(self):
- t = get_transport(self.get_url())
- # outside a repo the default convenience output is a repo+branch_tree
- format = bzrdir.format_registry.make_bzrdir('knit')
- branch = bzrdir.BzrDir.create_branch_convenience(transport=t,
- format=format)
- 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/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-05-03 09:59:47 +0000
+++ b/bzrlib/transport/__init__.py 2007-05-03 11:38:27 +0000
@@ -1038,11 +1038,11 @@
urlunescape = urlutils.unescape
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<path>.*)$')
-def get_transport(base, transports=[]):
+def get_transport(base, transports=None):
"""Open a transport to access a URL or directory.
:param base: either a URL or a directory name.
- :param transports: optional reusable transport list.
+ :param transports: optional reusable transports list.
"""
if base is None:
base = '.'
@@ -1068,11 +1068,11 @@
'URLs must be properly escaped (protocol: %s)')
transport = None
- for t in transports:
- if t.base == base:
- transport = t
- break
-
+ if transports:
+ for t in 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):
@@ -1080,7 +1080,6 @@
factory_list)
if transport:
break
-
if transport is None:
# We tried all the different protocols, now try one last
# time as a local protocol
@@ -1090,7 +1089,6 @@
# as protocol None
factory_list = transport_list_registry.get(None)
transport, last_err = _try_transport_factories(base, factory_list)
-
return transport
More information about the bazaar-commits
mailing list