Skip to content

Commit 0b3dfbf

Browse files
committed
smart_pkt: reorder and rename parameters of git_pkt_parse_line
The parameters of the `git_pkt_parse_line` function are quite confusing. First, there is no real indicator what the `out` parameter is actually all about, and it's not really clear what the `bufflen` parameter refers to. Reorder and rename the parameters to make this more obvious.
1 parent 5fabaca commit 0b3dfbf

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

src/transports/smart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
188188
int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
189189

190190
/* smart_pkt.c */
191-
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
191+
int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
192192
int git_pkt_buffer_flush(git_buf *buf);
193193
int git_pkt_send_flush(GIT_SOCKET s);
194194
int git_pkt_buffer_done(git_buf *buf);

src/transports/smart_pkt.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,13 @@ static int32_t parse_len(const char *line)
407407
*/
408408

409409
int git_pkt_parse_line(
410-
git_pkt **head, const char *line, const char **out, size_t bufflen)
410+
git_pkt **pkt, const char **endptr, const char *line, size_t linelen)
411411
{
412412
int ret;
413413
int32_t len;
414414

415415
/* Not even enough for the length */
416-
if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
416+
if (linelen > 0 && linelen < PKT_LEN_SIZE)
417417
return GIT_EBUFS;
418418

419419
len = parse_len(line);
@@ -422,7 +422,7 @@ int git_pkt_parse_line(
422422
* If we fail to parse the length, it might be because the
423423
* server is trying to send us the packfile already.
424424
*/
425-
if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) {
425+
if (linelen >= 4 && !git__prefixcmp(line, "PACK")) {
426426
giterr_set(GITERR_NET, "unexpected pack file");
427427
} else {
428428
giterr_set(GITERR_NET, "bad packet length");
@@ -435,7 +435,7 @@ int git_pkt_parse_line(
435435
* If we were given a buffer length, then make sure there is
436436
* enough in the buffer to satisfy this line
437437
*/
438-
if (bufflen > 0 && bufflen < (size_t)len)
438+
if (linelen > 0 && linelen < (size_t)len)
439439
return GIT_EBUFS;
440440

441441
/*
@@ -458,36 +458,36 @@ int git_pkt_parse_line(
458458
}
459459

460460
if (len == 0) { /* Flush pkt */
461-
*out = line;
462-
return flush_pkt(head);
461+
*endptr = line;
462+
return flush_pkt(pkt);
463463
}
464464

465465
len -= PKT_LEN_SIZE; /* the encoded length includes its own size */
466466

467467
if (*line == GIT_SIDE_BAND_DATA)
468-
ret = data_pkt(head, line, len);
468+
ret = data_pkt(pkt, line, len);
469469
else if (*line == GIT_SIDE_BAND_PROGRESS)
470-
ret = sideband_progress_pkt(head, line, len);
470+
ret = sideband_progress_pkt(pkt, line, len);
471471
else if (*line == GIT_SIDE_BAND_ERROR)
472-
ret = sideband_error_pkt(head, line, len);
472+
ret = sideband_error_pkt(pkt, line, len);
473473
else if (!git__prefixncmp(line, len, "ACK"))
474-
ret = ack_pkt(head, line, len);
474+
ret = ack_pkt(pkt, line, len);
475475
else if (!git__prefixncmp(line, len, "NAK"))
476-
ret = nak_pkt(head);
476+
ret = nak_pkt(pkt);
477477
else if (!git__prefixncmp(line, len, "ERR"))
478-
ret = err_pkt(head, line, len);
478+
ret = err_pkt(pkt, line, len);
479479
else if (*line == '#')
480-
ret = comment_pkt(head, line, len);
480+
ret = comment_pkt(pkt, line, len);
481481
else if (!git__prefixncmp(line, len, "ok"))
482-
ret = ok_pkt(head, line, len);
482+
ret = ok_pkt(pkt, line, len);
483483
else if (!git__prefixncmp(line, len, "ng"))
484-
ret = ng_pkt(head, line, len);
484+
ret = ng_pkt(pkt, line, len);
485485
else if (!git__prefixncmp(line, len, "unpack"))
486-
ret = unpack_pkt(head, line, len);
486+
ret = unpack_pkt(pkt, line, len);
487487
else
488-
ret = ref_pkt(head, line, len);
488+
ret = ref_pkt(pkt, line, len);
489489

490-
*out = line + len;
490+
*endptr = line + len;
491491

492492
return ret;
493493
}

src/transports/smart_protocol.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int git_smart__store_refs(transport_smart *t, int flushes)
4444

4545
do {
4646
if (buf->offset > 0)
47-
error = git_pkt_parse_line(&pkt, buf->data, &line_end, buf->offset);
47+
error = git_pkt_parse_line(&pkt, &line_end, buf->data, buf->offset);
4848
else
4949
error = GIT_EBUFS;
5050

@@ -217,7 +217,7 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf
217217

218218
do {
219219
if (buf->offset > 0)
220-
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset);
220+
error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset);
221221
else
222222
error = GIT_EBUFS;
223223

@@ -755,7 +755,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
755755
}
756756

757757
while (line_len > 0) {
758-
error = git_pkt_parse_line(&pkt, line, &line_end, line_len);
758+
error = git_pkt_parse_line(&pkt, &line_end, line, line_len);
759759

760760
if (error == GIT_EBUFS) {
761761
/* Buffer the data when the inner packet is split
@@ -798,8 +798,8 @@ static int parse_report(transport_smart *transport, git_push *push)
798798

799799
for (;;) {
800800
if (buf->offset > 0)
801-
error = git_pkt_parse_line(&pkt, buf->data,
802-
&line_end, buf->offset);
801+
error = git_pkt_parse_line(&pkt, &line_end,
802+
buf->data, buf->offset);
803803
else
804804
error = GIT_EBUFS;
805805

tests/transports/smart/packet.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static void assert_flush_parses(const char *line)
1212
const char *endptr;
1313
git_pkt *pkt;
1414

15-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
15+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
1616
cl_assert_equal_i(pkt->type, GIT_PKT_FLUSH);
1717
cl_assert_equal_strn(endptr, line + 4, linelen - 4);
1818

@@ -25,7 +25,7 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data,
2525
const char *endptr;
2626
git_pkt_data *pkt;
2727

28-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
28+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
2929
cl_assert_equal_i(pkt->type, GIT_PKT_DATA);
3030
cl_assert_equal_i(pkt->len, expected_len);
3131
cl_assert_equal_strn(pkt->data, expected_data, expected_len);
@@ -39,7 +39,7 @@ static void assert_sideband_progress_parses(const char *line, const char *expect
3939
const char *endptr;
4040
git_pkt_progress *pkt;
4141

42-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
42+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
4343
cl_assert_equal_i(pkt->type, GIT_PKT_PROGRESS);
4444
cl_assert_equal_i(pkt->len, expected_len);
4545
cl_assert_equal_strn(pkt->data, expected_data, expected_len);
@@ -53,7 +53,7 @@ static void assert_error_parses(const char *line, const char *expected_error, si
5353
const char *endptr;
5454
git_pkt_err *pkt;
5555

56-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
56+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
5757
cl_assert_equal_i(pkt->type, GIT_PKT_ERR);
5858
cl_assert_equal_i(pkt->len, expected_len);
5959
cl_assert_equal_strn(pkt->error, expected_error, expected_len);
@@ -70,7 +70,7 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g
7070

7171
cl_git_pass(git_oid_fromstr(&oid, expected_oid));
7272

73-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
73+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
7474
cl_assert_equal_i(pkt->type, GIT_PKT_ACK);
7575
cl_assert_equal_oid(&pkt->oid, &oid);
7676
cl_assert_equal_i(pkt->status, expected_status);
@@ -84,7 +84,7 @@ static void assert_nak_parses(const char *line)
8484
const char *endptr;
8585
git_pkt *pkt;
8686

87-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
87+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
8888
cl_assert_equal_i(pkt->type, GIT_PKT_NAK);
8989
cl_assert_equal_strn(endptr, line + 7, linelen - 7);
9090

@@ -97,7 +97,7 @@ static void assert_comment_parses(const char *line, const char *expected_comment
9797
const char *endptr;
9898
git_pkt_comment *pkt;
9999

100-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
100+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
101101
cl_assert_equal_i(pkt->type, GIT_PKT_COMMENT);
102102
cl_assert_equal_strn(pkt->comment, expected_comment, strlen(expected_comment));
103103

@@ -110,7 +110,7 @@ static void assert_ok_parses(const char *line, const char *expected_ref)
110110
const char *endptr;
111111
git_pkt_ok *pkt;
112112

113-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
113+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
114114
cl_assert_equal_i(pkt->type, GIT_PKT_OK);
115115
cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref));
116116

@@ -123,7 +123,7 @@ static void assert_unpack_parses(const char *line, bool ok)
123123
const char *endptr;
124124
git_pkt_unpack *pkt;
125125

126-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
126+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
127127
cl_assert_equal_i(pkt->type, GIT_PKT_UNPACK);
128128
cl_assert_equal_i(pkt->unpack_ok, ok);
129129

@@ -136,7 +136,7 @@ static void assert_ng_parses(const char *line, const char *expected_ref, const c
136136
const char *endptr;
137137
git_pkt_ng *pkt;
138138

139-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
139+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
140140
cl_assert_equal_i(pkt->type, GIT_PKT_NG);
141141
cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref));
142142
cl_assert_equal_strn(pkt->msg, expected_msg, strlen(expected_msg));
@@ -156,7 +156,7 @@ static void assert_ref_parses_(const char *line, size_t linelen, const char *exp
156156

157157
cl_git_pass(git_oid_fromstr(&oid, expected_oid));
158158

159-
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, line, &endptr, linelen));
159+
cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen));
160160
cl_assert_equal_i(pkt->type, GIT_PKT_REF);
161161
cl_assert_equal_oid(&pkt->head.oid, &oid);
162162
cl_assert_equal_strn(pkt->head.name, expected_ref, strlen(expected_ref));
@@ -172,7 +172,7 @@ static void assert_pkt_fails(const char *line)
172172
{
173173
const char *endptr;
174174
git_pkt *pkt;
175-
cl_git_fail(git_pkt_parse_line(&pkt, line, &endptr, strlen(line) + 1));
175+
cl_git_fail(git_pkt_parse_line(&pkt, &endptr, line, strlen(line) + 1));
176176
}
177177

178178
void test_transports_smart_packet__parsing_garbage_fails(void)

0 commit comments

Comments
 (0)