Skip to content

Commit e5f32e8

Browse files
authored
Merge pull request libgit2#4514 from tiennou/fix/pkt-type-enum
Typedef git_pkt_type and clarify recv_pkt return type
2 parents fd63401 + 13a7727 commit e5f32e8

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

src/transports/smart.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
extern bool git_smart__ofs_delta_enabled;
3535

36-
enum git_pkt_type {
36+
typedef enum {
3737
GIT_PKT_CMD,
3838
GIT_PKT_FLUSH,
3939
GIT_PKT_REF,
@@ -48,9 +48,9 @@ enum git_pkt_type {
4848
GIT_PKT_OK,
4949
GIT_PKT_NG,
5050
GIT_PKT_UNPACK,
51-
};
51+
} git_pkt_type;
5252

53-
/* Used for multi_ack and mutli_ack_detailed */
53+
/* Used for multi_ack and multi_ack_detailed */
5454
enum git_ack_status {
5555
GIT_ACK_NONE,
5656
GIT_ACK_CONTINUE,
@@ -60,62 +60,62 @@ enum git_ack_status {
6060

6161
/* This would be a flush pkt */
6262
typedef struct {
63-
enum git_pkt_type type;
63+
git_pkt_type type;
6464
} git_pkt;
6565

6666
struct git_pkt_cmd {
67-
enum git_pkt_type type;
67+
git_pkt_type type;
6868
char *cmd;
6969
char *path;
7070
char *host;
7171
};
7272

7373
/* This is a pkt-line with some info in it */
7474
typedef struct {
75-
enum git_pkt_type type;
75+
git_pkt_type type;
7676
git_remote_head head;
7777
char *capabilities;
7878
} git_pkt_ref;
7979

8080
/* Useful later */
8181
typedef struct {
82-
enum git_pkt_type type;
82+
git_pkt_type type;
8383
git_oid oid;
8484
enum git_ack_status status;
8585
} git_pkt_ack;
8686

8787
typedef struct {
88-
enum git_pkt_type type;
88+
git_pkt_type type;
8989
char comment[GIT_FLEX_ARRAY];
9090
} git_pkt_comment;
9191

9292
typedef struct {
93-
enum git_pkt_type type;
93+
git_pkt_type type;
9494
int len;
9595
char data[GIT_FLEX_ARRAY];
9696
} git_pkt_data;
9797

9898
typedef git_pkt_data git_pkt_progress;
9999

100100
typedef struct {
101-
enum git_pkt_type type;
101+
git_pkt_type type;
102102
int len;
103103
char error[GIT_FLEX_ARRAY];
104104
} git_pkt_err;
105105

106106
typedef struct {
107-
enum git_pkt_type type;
107+
git_pkt_type type;
108108
char *ref;
109109
} git_pkt_ok;
110110

111111
typedef struct {
112-
enum git_pkt_type type;
112+
git_pkt_type type;
113113
char *ref;
114114
char *msg;
115115
} git_pkt_ng;
116116

117117
typedef struct {
118-
enum git_pkt_type type;
118+
git_pkt_type type;
119119
int unpack_ok;
120120
} git_pkt_unpack;
121121

src/transports/smart_protocol.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
209209
return 0;
210210
}
211211

212-
static int recv_pkt(git_pkt **out, gitno_buffer *buf)
212+
static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf)
213213
{
214214
const char *ptr = buf->data, *line_end = ptr;
215215
git_pkt *pkt = NULL;
216-
int pkt_type, error = 0, ret;
216+
int error = 0, ret;
217217

218218
do {
219219
if (buf->offset > 0)
@@ -236,13 +236,14 @@ static int recv_pkt(git_pkt **out, gitno_buffer *buf)
236236
} while (error);
237237

238238
gitno_consume(buf, line_end);
239-
pkt_type = pkt->type;
240-
if (out != NULL)
241-
*out = pkt;
239+
if (out_type != NULL)
240+
*out_type = pkt->type;
241+
if (out_pkt != NULL)
242+
*out_pkt = pkt;
242243
else
243244
git__free(pkt);
244245

245-
return pkt_type;
246+
return error;
246247
}
247248

248249
static int store_common(transport_smart *t)
@@ -252,17 +253,18 @@ static int store_common(transport_smart *t)
252253
int error;
253254

254255
do {
255-
if ((error = recv_pkt(&pkt, buf)) < 0)
256+
if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
256257
return error;
257258

258-
if (pkt->type == GIT_PKT_ACK) {
259-
if (git_vector_insert(&t->common, pkt) < 0)
260-
return -1;
261-
} else {
259+
if (pkt->type != GIT_PKT_ACK) {
262260
git__free(pkt);
263261
return 0;
264262
}
265263

264+
if (git_vector_insert(&t->common, pkt) < 0) {
265+
git__free(pkt);
266+
return -1;
267+
}
266268
} while (1);
267269

268270
return 0;
@@ -320,7 +322,7 @@ static int wait_while_ack(gitno_buffer *buf)
320322
while (1) {
321323
git__free(pkt);
322324

323-
if ((error = recv_pkt((git_pkt **)&pkt, buf)) < 0)
325+
if ((error = recv_pkt((git_pkt **)&pkt, NULL, buf)) < 0)
324326
return error;
325327

326328
if (pkt->type == GIT_PKT_NAK)
@@ -345,7 +347,8 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
345347
gitno_buffer *buf = &t->buffer;
346348
git_buf data = GIT_BUF_INIT;
347349
git_revwalk *walk = NULL;
348-
int error = -1, pkt_type;
350+
int error = -1;
351+
git_pkt_type pkt_type;
349352
unsigned int i;
350353
git_oid oid;
351354

@@ -395,16 +398,13 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
395398
if ((error = store_common(t)) < 0)
396399
goto on_error;
397400
} else {
398-
pkt_type = recv_pkt(NULL, buf);
401+
if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
402+
goto on_error;
399403

400404
if (pkt_type == GIT_PKT_ACK) {
401405
break;
402406
} else if (pkt_type == GIT_PKT_NAK) {
403407
continue;
404-
} else if (pkt_type < 0) {
405-
/* recv_pkt returned an error */
406-
error = pkt_type;
407-
goto on_error;
408408
} else {
409409
giterr_set(GITERR_NET, "Unexpected pkt type");
410410
error = -1;
@@ -470,11 +470,10 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
470470

471471
/* Now let's eat up whatever the server gives us */
472472
if (!t->caps.multi_ack && !t->caps.multi_ack_detailed) {
473-
pkt_type = recv_pkt(NULL, buf);
473+
if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0)
474+
return error;
474475

475-
if (pkt_type < 0) {
476-
return pkt_type;
477-
} else if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
476+
if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
478477
giterr_set(GITERR_NET, "Unexpected pkt type");
479478
return -1;
480479
}
@@ -594,7 +593,7 @@ int git_smart__download_pack(
594593
goto done;
595594
}
596595

597-
if ((error = recv_pkt(&pkt, buf)) >= 0) {
596+
if ((error = recv_pkt(&pkt, NULL, buf)) >= 0) {
598597
/* Check cancellation after network call */
599598
if (t->cancelled.val) {
600599
giterr_clear();

0 commit comments

Comments
 (0)