/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 01:31:43 UTC
  • mfrom: (7058.6.5 memorytree-symlinks)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304013143-7euyjbmanwo3tpmn
More improvements, add tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from cStringIO import StringIO
18
 
 
19
 
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
20
 
from bzrlib.lazy_import import lazy_import
 
17
from __future__ import absolute_import
 
18
 
 
19
 
 
20
from ..lazy_import import lazy_import
21
21
lazy_import(globals(), """
22
 
from bzrlib import (
 
22
from breezy import (
23
23
    errors,
 
24
    transport as _mod_transport,
24
25
    urlutils,
25
26
    )
26
 
from bzrlib.bundle import serializer as _serializer
27
 
from bzrlib.merge_directive import MergeDirective
28
 
from bzrlib.transport import (
29
 
    do_catching_redirections,
30
 
    get_transport,
31
 
    )
 
27
from breezy.bundle import serializer as _serializer
 
28
from breezy.merge_directive import MergeDirective
 
29
from breezy.i18n import gettext
32
30
""")
33
 
from bzrlib.trace import note
34
 
 
35
 
 
36
 
@deprecated_function(deprecated_in((1, 12, 0)))
37
 
def read_bundle_from_url(url):
38
 
    return read_mergeable_from_url(url, _do_directive=False)
 
31
from ..sixish import (
 
32
    BytesIO,
 
33
    )
 
34
from ..trace import note
39
35
 
40
36
 
41
37
def read_mergeable_from_url(url, _do_directive=True, possible_transports=None):
44
40
    :return: An object supporting get_target_revision.  Raises NotABundle if
45
41
        the target is not a mergeable type.
46
42
    """
47
 
    child_transport = get_transport(url,
48
 
        possible_transports=possible_transports)
 
43
    child_transport = _mod_transport.get_transport(url,
 
44
                                                   possible_transports=possible_transports)
49
45
    transport = child_transport.clone('..')
50
46
    filename = transport.relpath(child_transport.base)
51
47
    mergeable, transport = read_mergeable_from_transport(transport, filename,
55
51
 
56
52
def read_mergeable_from_transport(transport, filename, _do_directive=True):
57
53
    def get_bundle(transport):
58
 
        return StringIO(transport.get_bytes(filename)), transport
 
54
        return BytesIO(transport.get_bytes(filename)), transport
59
55
 
60
56
    def redirected_transport(transport, exception, redirection_notice):
61
57
        note(redirection_notice)
62
58
        url, filename = urlutils.split(exception.target,
63
59
                                       exclude_trailing_slash=False)
64
60
        if not filename:
65
 
            raise errors.NotABundle('A directory cannot be a bundle')
66
 
        return get_transport(url)
 
61
            raise errors.NotABundle(gettext('A directory cannot be a bundle'))
 
62
        return _mod_transport.get_transport_from_url(url)
67
63
 
68
64
    try:
69
 
        bytef, transport = do_catching_redirections(get_bundle, transport,
70
 
                                                    redirected_transport)
 
65
        bytef, transport = _mod_transport.do_catching_redirections(
 
66
            get_bundle, transport, redirected_transport)
71
67
    except errors.TooManyRedirections:
72
68
        raise errors.NotABundle(transport.clone(filename).base)
73
 
    except (errors.ConnectionReset, errors.ConnectionError), e:
 
69
    except (errors.ConnectionReset, errors.ConnectionError) as e:
74
70
        raise
75
 
    except (errors.TransportError, errors.PathError), e:
 
71
    except (errors.TransportError, errors.PathError) as e:
76
72
        raise errors.NotABundle(str(e))
77
 
    except (IOError,), e:
 
73
    except (IOError,) as e:
78
74
        # jam 20060707
79
75
        # Abstraction leakage, SFTPTransport.get('directory')
80
76
        # doesn't always fail at get() time. Sometimes it fails