Commit d69c7a72 by Edward Thomson

transport: transports understand oid type

Teach the smart transport more about oid types, instead of assuming SHA1.
parent 72139ef2
......@@ -53,6 +53,8 @@ static int ack_pkt(
git_pkt_ack *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_ack));
GIT_ERROR_CHECK_ALLOC(pkt);
pkt->type = GIT_PKT_ACK;
......@@ -450,6 +452,8 @@ static int shallow_pkt(
git_pkt_shallow *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt);
......@@ -487,6 +491,8 @@ static int unshallow_pkt(
git_pkt_shallow *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt);
......
......@@ -256,13 +256,20 @@ int git_smart__detect_caps(
return 0;
}
static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf)
static int recv_pkt(
git_pkt **out_pkt,
git_pkt_type *out_type,
transport_smart *t,
gitno_buffer *buf)
{
const char *ptr = buf->data, *line_end = ptr;
git_pkt *pkt = NULL;
git_pkt_parse_data pkt_parse_data = { 0 };
int error = 0, ret;
pkt_parse_data.oid_type = t->owner->repo->oid_type;
pkt_parse_data.seen_capabilities = 1;
do {
if (buf->offset > 0)
error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset, &pkt_parse_data);
......@@ -303,7 +310,7 @@ static int store_common(transport_smart *t)
int error;
do {
if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
if ((error = recv_pkt(&pkt, NULL, t, buf)) < 0)
return error;
if (pkt->type != GIT_PKT_ACK) {
......@@ -320,7 +327,7 @@ static int store_common(transport_smart *t)
return 0;
}
static int wait_while_ack(gitno_buffer *buf)
static int wait_while_ack(transport_smart *t, gitno_buffer *buf)
{
int error;
git_pkt *pkt = NULL;
......@@ -329,7 +336,7 @@ static int wait_while_ack(gitno_buffer *buf)
while (1) {
git_pkt_free(pkt);
if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
if ((error = recv_pkt(&pkt, NULL, t, buf)) < 0)
return error;
if (pkt->type == GIT_PKT_NAK)
......@@ -400,8 +407,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error;
while ((error = recv_pkt((git_pkt **)&pkt, NULL, buf)) == 0) {
while ((error = recv_pkt((git_pkt **)&pkt, NULL, t, buf)) == 0) {
if (pkt->type == GIT_PKT_SHALLOW) {
git_shallowarray_add(wants->shallow_roots, &pkt->oid);
} else if (pkt->type == GIT_PKT_UNSHALLOW) {
......@@ -463,7 +469,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = store_common(t)) < 0)
goto on_error;
} else {
if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
if ((error = recv_pkt(NULL, &pkt_type, t, buf)) < 0)
goto on_error;
if (pkt_type == GIT_PKT_ACK) {
......@@ -535,7 +541,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
/* Now let's eat up whatever the server gives us */
if (!t->caps.multi_ack && !t->caps.multi_ack_detailed) {
if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
if ((error = recv_pkt(NULL, &pkt_type, t, buf)) < 0)
return error;
if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
......@@ -543,7 +549,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
return -1;
}
} else {
error = wait_while_ack(buf);
error = wait_while_ack(t, buf);
}
return error;
......@@ -659,7 +665,7 @@ int git_smart__download_pack(
goto done;
}
if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) {
if ((error = recv_pkt(&pkt, NULL, t, buf)) >= 0) {
/* Check cancellation after network call */
if (t->cancelled.val) {
git_error_clear();
......
......@@ -25,7 +25,7 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data,
size_t linelen = strlen(line) + 1;
const char *endptr;
git_pkt_data *pkt;
git_pkt_parse_data pkt_parse_data = { 0 };
git_pkt_parse_data pkt_parse_data = { 1, GIT_OID_SHA1 };
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data));
cl_assert_equal_i(pkt->type, GIT_PKT_DATA);
......@@ -71,7 +71,7 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g
const char *endptr;
git_pkt_ack *pkt;
git_oid oid;
git_pkt_parse_data pkt_parse_data = { 0 };
git_pkt_parse_data pkt_parse_data = { 1, GIT_OID_SHA1 };
cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment