34
34
def read_bundle_from_url(url):
35
35
return read_mergeable_from_url(url, _do_directive=False)
37
def read_mergeable_from_url(url, _do_directive=True):
38
def read_mergeable_from_url(url, _do_directive=True, possible_transports=None):
38
39
"""Read mergable object from a given URL.
40
41
:return: An object supporting get_target_revision. Raises NotABundle if
41
42
the target is not a mergeable type.
43
from bzrlib.merge_directive import MergeDirective
44
url = urlutils.normalize_url(url)
45
url, filename = urlutils.split(url, exclude_trailing_slash=False)
44
child_transport = get_transport(url,
45
possible_transports=possible_transports)
46
transport = child_transport.clone('..')
47
filename = transport.relpath(child_transport.base)
48
if filename.endswith('/'):
47
49
# A path to a directory was passed in
48
50
# definitely not a bundle
49
51
raise errors.NotABundle('A directory cannot be a bundle')
52
mergeable, transport = read_mergeable_from_transport(transport, filename,
57
def read_mergeable_from_transport(transport, filename, _do_directive=True):
51
58
# All of this must be in the try/except
52
59
# Some transports cannot detect that we are trying to read a
53
60
# directory until we actually issue read() on the handle.
55
transport = get_transport(url)
57
62
def get_bundle(transport):
58
return transport.get(filename)
63
return transport.get(filename), transport
60
65
def redirected_transport(transport, exception, redirection_notice):
61
66
note(redirection_notice)
66
71
return get_transport(url)
69
f = do_catching_redirections(get_bundle, transport,
74
f, transport = do_catching_redirections(get_bundle, transport,
71
76
except errors.TooManyRedirections:
72
77
raise errors.NotABundle(str(url))
80
from bzrlib.merge_directive import MergeDirective
75
81
directive = MergeDirective.from_lines(f.readlines())
82
return directive, transport
78
return _serializer.read_bundle(f)
84
return _serializer.read_bundle(f), transport
79
85
except (errors.TransportError, errors.PathError), e:
80
86
raise errors.NotABundle(str(e))
81
87
except (IOError,), e:
89
95
raise errors.NotABundle(str(e))
90
96
except errors.NotAMergeDirective:
92
return _serializer.read_bundle(f)
98
return _serializer.read_bundle(f), transport