~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/__init__.py

  • Committer: Aaron Bentley
  • Date: 2007-07-25 19:32:22 UTC
  • mto: (1551.19.24 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2664.
  • Revision ID: abentley@panoramicfeedback.com-20070725193222-lcq4z4980ffd4bf5
Stop using _merge_helper for merging

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
def read_bundle_from_url(url):
35
35
    return read_mergeable_from_url(url, _do_directive=False)
36
36
 
 
37
 
37
38
def read_mergeable_from_url(url, _do_directive=True):
38
39
    """Read mergable object from a given URL.
39
40
 
40
41
    :return: An object supporting get_target_revision.  Raises NotABundle if
41
42
        the target is not a mergeable type.
42
43
    """
43
 
    from bzrlib.merge_directive import MergeDirective
44
44
    url = urlutils.normalize_url(url)
45
45
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
46
46
    if not filename:
48
48
        # definitely not a bundle
49
49
        raise errors.NotABundle('A directory cannot be a bundle')
50
50
 
 
51
    transport = get_transport(url)
 
52
    mergeable, transport = read_mergeable_from_transport(transport, filename,
 
53
                                                         _do_directive)
 
54
    return mergeable
 
55
 
 
56
 
 
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.
54
61
    try:
55
 
        transport = get_transport(url)
56
 
 
57
62
        def get_bundle(transport):
58
 
            return transport.get(filename)
 
63
            return transport.get(filename), transport
59
64
 
60
65
        def redirected_transport(transport, exception, redirection_notice):
61
66
            note(redirection_notice)
66
71
            return get_transport(url)
67
72
 
68
73
        try:
69
 
            f = do_catching_redirections(get_bundle, transport,
70
 
                                         redirected_transport)
 
74
            f, transport = do_catching_redirections(get_bundle, transport,
 
75
                                                    redirected_transport)
71
76
        except errors.TooManyRedirections:
72
77
            raise errors.NotABundle(str(url))
73
78
 
74
79
        if _do_directive:
 
80
            from bzrlib.merge_directive import MergeDirective
75
81
            directive = MergeDirective.from_lines(f.readlines())
76
 
            return directive
 
82
            return directive, transport
77
83
        else:
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:
91
97
        f.seek(0)
92
 
        return _serializer.read_bundle(f)
 
98
        return _serializer.read_bundle(f), transport