~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-26 22:14:42 UTC
  • mto: This revision was merged to the branch mainline in revision 3747.
  • Revision ID: john@arbash-meinel.com-20080926221442-3r67j99sr9rwe9w0
Make message optional, don't check the memory flag directly.

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
 
def read_mergeable_from_url(url, _do_directive=True):
 
37
 
 
38
def read_mergeable_from_url(url, _do_directive=True, possible_transports=None):
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
 
    url = urlutils.normalize_url(url)
45
 
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
46
 
    if not filename:
 
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')
50
 
 
 
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