Hash :
9cf0f287
Author :
Date :
2011-08-04T17:50:50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
#include "common.h"
#include "git2/types.h"
#include "git2/transport.h"
#include "git2/net.h"
#include "transport.h"
struct {
char *prefix;
git_transport_cb fn;
} transports[] = {
{"git://", git_transport_git},
{"http://", git_transport_dummy},
{"https://", git_transport_dummy},
{"file://", git_transport_local},
{"git+ssh://", git_transport_dummy},
{"ssh+git://", git_transport_dummy},
{NULL, 0}
};
static git_transport_cb transport_new_fn(const char *url)
{
int i = 0;
while (1) {
if (transports[i].prefix == NULL)
break;
if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix)))
return transports[i].fn;
++i;
}
/*
* If we still haven't found the transport, we assume we mean a
* local file.
* TODO: Parse "example.com:project.git" as an SSH URL
*/
return git_transport_local;
}
/**************
* Public API *
**************/
int git_transport_dummy(git_transport **GIT_UNUSED(transport))
{
GIT_UNUSED_ARG(transport);
return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
}
int git_transport_new(git_transport **out, const char *url)
{
git_transport_cb fn;
git_transport *transport;
int error;
fn = transport_new_fn(url);
error = fn(&transport);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to create new transport");
transport->url = git__strdup(url);
if (transport->url == NULL)
return GIT_ENOMEM;
*out = transport;
return GIT_SUCCESS;
}
int git_transport_connect(git_transport *transport, int direction)
{
return transport->connect(transport, direction);
}
int git_transport_ls(git_transport *transport, git_headarray *array)
{
return transport->ls(transport, array);
}
int git_transport_send_wants(struct git_transport *transport, git_headarray *array)
{
return transport->send_wants(transport, array);
}
int git_transport_send_have(struct git_transport *transport, git_oid *oid)
{
return transport->send_have(transport, oid);
}
int git_transport_send_flush(struct git_transport *transport)
{
return transport->send_flush(transport);
}
int git_transport_send_done(struct git_transport *transport)
{
return transport->send_done(transport);
}
int git_transport_download_pack(char **out, git_transport *transport, git_repository *repo)
{
return transport->download_pack(out, transport, repo);
}
int git_transport_close(git_transport *transport)
{
return transport->close(transport);
}
void git_transport_free(git_transport *transport)
{
transport->free(transport);
}