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( ...@@ -53,6 +53,8 @@ static int ack_pkt(
git_pkt_ack *pkt; git_pkt_ack *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type); size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_ack)); pkt = git__calloc(1, sizeof(git_pkt_ack));
GIT_ERROR_CHECK_ALLOC(pkt); GIT_ERROR_CHECK_ALLOC(pkt);
pkt->type = GIT_PKT_ACK; pkt->type = GIT_PKT_ACK;
...@@ -450,6 +452,8 @@ static int shallow_pkt( ...@@ -450,6 +452,8 @@ static int shallow_pkt(
git_pkt_shallow *pkt; git_pkt_shallow *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type); size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_shallow)); pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt); GIT_ERROR_CHECK_ALLOC(pkt);
...@@ -487,6 +491,8 @@ static int unshallow_pkt( ...@@ -487,6 +491,8 @@ static int unshallow_pkt(
git_pkt_shallow *pkt; git_pkt_shallow *pkt;
size_t oid_hexsize = git_oid_hexsize(data->oid_type); size_t oid_hexsize = git_oid_hexsize(data->oid_type);
GIT_ASSERT(data && data->oid_type);
pkt = git__calloc(1, sizeof(git_pkt_shallow)); pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt); GIT_ERROR_CHECK_ALLOC(pkt);
......
...@@ -256,13 +256,20 @@ int git_smart__detect_caps( ...@@ -256,13 +256,20 @@ int git_smart__detect_caps(
return 0; 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; const char *ptr = buf->data, *line_end = ptr;
git_pkt *pkt = NULL; git_pkt *pkt = NULL;
git_pkt_parse_data pkt_parse_data = { 0 }; git_pkt_parse_data pkt_parse_data = { 0 };
int error = 0, ret; int error = 0, ret;
pkt_parse_data.oid_type = t->owner->repo->oid_type;
pkt_parse_data.seen_capabilities = 1;
do { do {
if (buf->offset > 0) if (buf->offset > 0)
error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset, &pkt_parse_data); 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) ...@@ -303,7 +310,7 @@ static int store_common(transport_smart *t)
int error; int error;
do { do {
if ((error = recv_pkt(&pkt, NULL, buf)) < 0) if ((error = recv_pkt(&pkt, NULL, t, buf)) < 0)
return error; return error;
if (pkt->type != GIT_PKT_ACK) { if (pkt->type != GIT_PKT_ACK) {
...@@ -320,7 +327,7 @@ static int store_common(transport_smart *t) ...@@ -320,7 +327,7 @@ static int store_common(transport_smart *t)
return 0; return 0;
} }
static int wait_while_ack(gitno_buffer *buf) static int wait_while_ack(transport_smart *t, gitno_buffer *buf)
{ {
int error; int error;
git_pkt *pkt = NULL; git_pkt *pkt = NULL;
...@@ -329,7 +336,7 @@ static int wait_while_ack(gitno_buffer *buf) ...@@ -329,7 +336,7 @@ static int wait_while_ack(gitno_buffer *buf)
while (1) { while (1) {
git_pkt_free(pkt); git_pkt_free(pkt);
if ((error = recv_pkt(&pkt, NULL, buf)) < 0) if ((error = recv_pkt(&pkt, NULL, t, buf)) < 0)
return error; return error;
if (pkt->type == GIT_PKT_NAK) if (pkt->type == GIT_PKT_NAK)
...@@ -400,8 +407,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -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) if ((error = git_smart__negotiation_step(&t->parent, data.ptr, data.size)) < 0)
goto on_error; 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) { if (pkt->type == GIT_PKT_SHALLOW) {
git_shallowarray_add(wants->shallow_roots, &pkt->oid); git_shallowarray_add(wants->shallow_roots, &pkt->oid);
} else if (pkt->type == GIT_PKT_UNSHALLOW) { } else if (pkt->type == GIT_PKT_UNSHALLOW) {
...@@ -463,7 +469,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -463,7 +469,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
if ((error = store_common(t)) < 0) if ((error = store_common(t)) < 0)
goto on_error; goto on_error;
} else { } else {
if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0) if ((error = recv_pkt(NULL, &pkt_type, t, buf)) < 0)
goto on_error; goto on_error;
if (pkt_type == GIT_PKT_ACK) { if (pkt_type == GIT_PKT_ACK) {
...@@ -535,7 +541,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -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 */ /* Now let's eat up whatever the server gives us */
if (!t->caps.multi_ack && !t->caps.multi_ack_detailed) { 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; return error;
if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) { 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 ...@@ -543,7 +549,7 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
return -1; return -1;
} }
} else { } else {
error = wait_while_ack(buf); error = wait_while_ack(t, buf);
} }
return error; return error;
...@@ -659,7 +665,7 @@ int git_smart__download_pack( ...@@ -659,7 +665,7 @@ int git_smart__download_pack(
goto done; goto done;
} }
if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) { if ((error = recv_pkt(&pkt, NULL, t, buf)) >= 0) {
/* Check cancellation after network call */ /* Check cancellation after network call */
if (t->cancelled.val) { if (t->cancelled.val) {
git_error_clear(); git_error_clear();
......
...@@ -25,7 +25,7 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data, ...@@ -25,7 +25,7 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data,
size_t linelen = strlen(line) + 1; size_t linelen = strlen(line) + 1;
const char *endptr; const char *endptr;
git_pkt_data *pkt; 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_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data));
cl_assert_equal_i(pkt->type, GIT_PKT_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 ...@@ -71,7 +71,7 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g
const char *endptr; const char *endptr;
git_pkt_ack *pkt; git_pkt_ack *pkt;
git_oid oid; 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)); 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