Rev 2520: Fix pull multiple connections. in file:///v/home/vila/src/experimental/reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jun 5 16:52:15 BST 2007
At file:///v/home/vila/src/experimental/reuse.transports/
------------------------------------------------------------
revno: 2520
revision-id: v.ladeuil+lp at free.fr-20070605155212-k2za98dhobeikxhn
parent: v.ladeuil+lp at free.fr-20070603155219-f7dtbnwdqrhs0kpk
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Tue 2007-06-05 17:52:12 +0200
message:
Fix pull multiple connections.
* bzrlib/builtins.py:
(cmd_pull.run): If 'location' wasn't a bundle, the transport may
be reused.
* bzrlib/branch.py:
(Branch.open_from_transport): New method.
* bzrlib/bundle/__init__.py:
(read_mergeable_from_transport): New method.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/__init__.py changeset.py-20050513021216-b02ab57fb9738913
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-05-08 20:00:50 +0000
+++ b/bzrlib/branch.py 2007-06-05 15:52:12 +0000
@@ -122,7 +122,7 @@
def open_downlevel(base):
"""Open a branch which may be of an old format."""
return Branch.open(base, _unsupported=True)
-
+
@staticmethod
def open(base, _unsupported=False):
"""Open the branch rooted at base.
@@ -134,6 +134,12 @@
return control.open_branch(_unsupported)
@staticmethod
+ def open_from_transport(transport, _unsupported=False):
+ """Open the branch rooted at transport"""
+ control = bzrdir.BzrDir.open_from_transport(transport, _unsupported)
+ return control.open_branch(_unsupported)
+
+ @staticmethod
def open_containing(url):
"""Open an existing branch which contains url.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-05-31 17:54:17 +0000
+++ b/bzrlib/builtins.py 2007-06-05 15:52:12 +0000
@@ -591,12 +591,26 @@
branch_to = Branch.open_containing(directory)[0]
reader = None
+ # The user may provide a bundle or branch as 'location' We first try to
+ # identify a bundle, if it's not, we try to preserve connection used by
+ # the transport to access the branch.
if location is not None:
- try:
- mergeable = bundle.read_mergeable_from_url(
- location)
- except errors.NotABundle:
- pass # Continue on considering this url a Branch
+ url = urlutils.normalize_url(location)
+ url, filename = urlutils.split(url, exclude_trailing_slash=False)
+ location_transport = transport.get_transport(url)
+ if filename:
+ try:
+ read_bundle = bundle.read_mergeable_from_transport
+ # There may be redirections but we ignore the intermediate
+ # and final transports used
+ mergeable, t = read_bundle(location_transport, filename)
+ except errors.NotABundle:
+ # Continue on considering this url a Branch but adjust the
+ # location_transport
+ location_transport = location_transport.clone(filename)
+ else:
+ # A directory was provided, location_transport is correct
+ pass
stored_loc = branch_to.get_parent()
if location is None:
@@ -608,6 +622,7 @@
self.outf.encoding)
self.outf.write("Using saved location: %s\n" % display_url)
location = stored_loc
+ location_transport = transport.get_transport(location)
if mergeable is not None:
if revision is not None:
@@ -616,7 +631,7 @@
revision_id = mergeable.install_revisions(branch_to.repository)
branch_from = branch_to
else:
- branch_from = Branch.open(location)
+ branch_from = Branch.open_from_transport(location_transport)
if branch_to.get_parent() is None or remember:
branch_to.set_parent(branch_from.base)
=== modified file 'bzrlib/bundle/__init__.py'
--- a/bzrlib/bundle/__init__.py 2007-04-01 06:19:16 +0000
+++ b/bzrlib/bundle/__init__.py 2007-06-05 15:52:12 +0000
@@ -34,13 +34,13 @@
def read_bundle_from_url(url):
return read_mergeable_from_url(url, _do_directive=False)
+
def read_mergeable_from_url(url, _do_directive=True):
"""Read mergable object from a given URL.
:return: An object supporting get_target_revision. Raises NotABundle if
the target is not a mergeable type.
"""
- from bzrlib.merge_directive import MergeDirective
url = urlutils.normalize_url(url)
url, filename = urlutils.split(url, exclude_trailing_slash=False)
if not filename:
@@ -48,14 +48,19 @@
# definitely not a bundle
raise errors.NotABundle('A directory cannot be a bundle')
+ transport = get_transport(url)
+ mergeable, transport = read_mergeable_from_transport(transport, filename,
+ _do_directive)
+ return mergeable
+
+
+def read_mergeable_from_transport(transport, filename, _do_directive=True):
# All of this must be in the try/except
# Some transports cannot detect that we are trying to read a
# directory until we actually issue read() on the handle.
try:
- transport = get_transport(url)
-
def get_bundle(transport):
- return transport.get(filename)
+ return transport.get(filename), transport
def redirected_transport(transport, exception, redirection_notice):
note(redirection_notice)
@@ -66,16 +71,17 @@
return get_transport(url)
try:
- f = do_catching_redirections(get_bundle, transport,
- redirected_transport)
+ f, transport = do_catching_redirections(get_bundle, transport,
+ redirected_transport)
except errors.TooManyRedirections:
raise errors.NotABundle(str(url))
if _do_directive:
+ from bzrlib.merge_directive import MergeDirective
directive = MergeDirective.from_lines(f.readlines())
- return directive
+ return directive, transport
else:
- return _serializer.read_bundle(f)
+ return _serializer.read_bundle(f), transport
except (errors.TransportError, errors.PathError), e:
raise errors.NotABundle(str(e))
except (IOError,), e:
@@ -89,4 +95,4 @@
raise errors.NotABundle(str(e))
except errors.NotAMergeDirective:
f.seek(0)
- return _serializer.read_bundle(f)
+ return _serializer.read_bundle(f), transport
More information about the bazaar-commits
mailing list