Commit 9561ec83 by Etienne Samson Committed by Patrick Steinhardt

smart: typedef git_pkt_type and clarify recv_pkt return type

(cherry picked from commit 08961c9d)
parent e91024e1
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
extern bool git_smart__ofs_delta_enabled; extern bool git_smart__ofs_delta_enabled;
enum git_pkt_type { typedef enum {
GIT_PKT_CMD, GIT_PKT_CMD,
GIT_PKT_FLUSH, GIT_PKT_FLUSH,
GIT_PKT_REF, GIT_PKT_REF,
...@@ -43,7 +43,7 @@ enum git_pkt_type { ...@@ -43,7 +43,7 @@ enum git_pkt_type {
GIT_PKT_OK, GIT_PKT_OK,
GIT_PKT_NG, GIT_PKT_NG,
GIT_PKT_UNPACK, GIT_PKT_UNPACK,
}; } git_pkt_type;
/* Used for multi_ack and mutli_ack_detailed */ /* Used for multi_ack and mutli_ack_detailed */
enum git_ack_status { enum git_ack_status {
...@@ -55,11 +55,11 @@ enum git_ack_status { ...@@ -55,11 +55,11 @@ enum git_ack_status {
/* This would be a flush pkt */ /* This would be a flush pkt */
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
} git_pkt; } git_pkt;
struct git_pkt_cmd { struct git_pkt_cmd {
enum git_pkt_type type; git_pkt_type type;
char *cmd; char *cmd;
char *path; char *path;
char *host; char *host;
...@@ -67,25 +67,25 @@ struct git_pkt_cmd { ...@@ -67,25 +67,25 @@ struct git_pkt_cmd {
/* This is a pkt-line with some info in it */ /* This is a pkt-line with some info in it */
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
git_remote_head head; git_remote_head head;
char *capabilities; char *capabilities;
} git_pkt_ref; } git_pkt_ref;
/* Useful later */ /* Useful later */
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
git_oid oid; git_oid oid;
enum git_ack_status status; enum git_ack_status status;
} git_pkt_ack; } git_pkt_ack;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
char comment[GIT_FLEX_ARRAY]; char comment[GIT_FLEX_ARRAY];
} git_pkt_comment; } git_pkt_comment;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
int len; int len;
char data[GIT_FLEX_ARRAY]; char data[GIT_FLEX_ARRAY];
} git_pkt_data; } git_pkt_data;
...@@ -93,24 +93,24 @@ typedef struct { ...@@ -93,24 +93,24 @@ typedef struct {
typedef git_pkt_data git_pkt_progress; typedef git_pkt_data git_pkt_progress;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
int len; int len;
char error[GIT_FLEX_ARRAY]; char error[GIT_FLEX_ARRAY];
} git_pkt_err; } git_pkt_err;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
char *ref; char *ref;
} git_pkt_ok; } git_pkt_ok;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
char *ref; char *ref;
char *msg; char *msg;
} git_pkt_ng; } git_pkt_ng;
typedef struct { typedef struct {
enum git_pkt_type type; git_pkt_type type;
int unpack_ok; int unpack_ok;
} git_pkt_unpack; } git_pkt_unpack;
......
...@@ -206,11 +206,11 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec ...@@ -206,11 +206,11 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
return 0; return 0;
} }
static int recv_pkt(git_pkt **out, gitno_buffer *buf) static int recv_pkt(git_pkt **out, git_pkt_type *pkt_type, 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;
int pkt_type, error = 0, ret; int error = 0, ret;
do { do {
if (buf->offset > 0) if (buf->offset > 0)
...@@ -233,13 +233,14 @@ static int recv_pkt(git_pkt **out, gitno_buffer *buf) ...@@ -233,13 +233,14 @@ static int recv_pkt(git_pkt **out, gitno_buffer *buf)
} while (error); } while (error);
gitno_consume(buf, line_end); gitno_consume(buf, line_end);
pkt_type = pkt->type; if (pkt_type)
*pkt_type = pkt->type;
if (out != NULL) if (out != NULL)
*out = pkt; *out = pkt;
else else
git__free(pkt); git__free(pkt);
return pkt_type; return error;
} }
static int store_common(transport_smart *t) static int store_common(transport_smart *t)
...@@ -249,7 +250,7 @@ static int store_common(transport_smart *t) ...@@ -249,7 +250,7 @@ static int store_common(transport_smart *t)
int error; int error;
do { do {
if ((error = recv_pkt(&pkt, buf)) < 0) if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
return error; return error;
if (pkt->type == GIT_PKT_ACK) { if (pkt->type == GIT_PKT_ACK) {
...@@ -317,7 +318,7 @@ static int wait_while_ack(gitno_buffer *buf) ...@@ -317,7 +318,7 @@ static int wait_while_ack(gitno_buffer *buf)
while (1) { while (1) {
git__free(pkt); git__free(pkt);
if ((error = recv_pkt((git_pkt **)&pkt, buf)) < 0) if ((error = recv_pkt((git_pkt **)&pkt, NULL, buf)) < 0)
return error; return error;
if (pkt->type == GIT_PKT_NAK) if (pkt->type == GIT_PKT_NAK)
...@@ -342,7 +343,8 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -342,7 +343,8 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
gitno_buffer *buf = &t->buffer; gitno_buffer *buf = &t->buffer;
git_buf data = GIT_BUF_INIT; git_buf data = GIT_BUF_INIT;
git_revwalk *walk = NULL; git_revwalk *walk = NULL;
int error = -1, pkt_type; int error = -1;
git_pkt_type pkt_type;
unsigned int i; unsigned int i;
git_oid oid; git_oid oid;
...@@ -392,16 +394,13 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -392,16 +394,13 @@ 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 {
pkt_type = recv_pkt(NULL, buf); error = recv_pkt(NULL, &pkt_type, buf);
if (error < 0) {
if (pkt_type == GIT_PKT_ACK) { goto on_error;
} else if (pkt_type == GIT_PKT_ACK) {
break; break;
} else if (pkt_type == GIT_PKT_NAK) { } else if (pkt_type == GIT_PKT_NAK) {
continue; continue;
} else if (pkt_type < 0) {
/* recv_pkt returned an error */
error = pkt_type;
goto on_error;
} else { } else {
giterr_set(GITERR_NET, "Unexpected pkt type"); giterr_set(GITERR_NET, "Unexpected pkt type");
error = -1; error = -1;
...@@ -467,10 +466,10 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c ...@@ -467,10 +466,10 @@ 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) {
pkt_type = recv_pkt(NULL, buf); error = recv_pkt(NULL, &pkt_type, buf);
if (pkt_type < 0) { if (error < 0) {
return pkt_type; return error;
} else if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) { } else if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
giterr_set(GITERR_NET, "Unexpected pkt type"); giterr_set(GITERR_NET, "Unexpected pkt type");
return -1; return -1;
...@@ -591,7 +590,7 @@ int git_smart__download_pack( ...@@ -591,7 +590,7 @@ int git_smart__download_pack(
goto done; goto done;
} }
if ((error = recv_pkt(&pkt, buf)) >= 0) { if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) {
/* Check cancellation after network call */ /* Check cancellation after network call */
if (t->cancelled.val) { if (t->cancelled.val) {
giterr_clear(); giterr_clear();
......
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