mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Use packet_reader instead of packet_read_line
By using and sharing a packet_reader while handling a Git pack protocol request, the same reader option is used throughout the code. This makes it easy to set a reader option to the request parsing code. Signed-off-by: Masaya Suzuki <masayasuzuki@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b21ebb671b
commit
01f9ec64c8
37
send-pack.c
37
send-pack.c
@@ -135,38 +135,36 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int receive_unpack_status(int in)
|
||||
static int receive_unpack_status(struct packet_reader *reader)
|
||||
{
|
||||
const char *line = packet_read_line(in, NULL);
|
||||
if (!line)
|
||||
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
|
||||
return error(_("unexpected flush packet while reading remote unpack status"));
|
||||
if (!skip_prefix(line, "unpack ", &line))
|
||||
return error(_("unable to parse remote unpack status: %s"), line);
|
||||
if (strcmp(line, "ok"))
|
||||
return error(_("remote unpack failed: %s"), line);
|
||||
if (!skip_prefix(reader->line, "unpack ", &reader->line))
|
||||
return error(_("unable to parse remote unpack status: %s"), reader->line);
|
||||
if (strcmp(reader->line, "ok"))
|
||||
return error(_("remote unpack failed: %s"), reader->line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int receive_status(int in, struct ref *refs)
|
||||
static int receive_status(struct packet_reader *reader, struct ref *refs)
|
||||
{
|
||||
struct ref *hint;
|
||||
int ret;
|
||||
|
||||
hint = NULL;
|
||||
ret = receive_unpack_status(in);
|
||||
ret = receive_unpack_status(reader);
|
||||
while (1) {
|
||||
char *refname;
|
||||
const char *refname;
|
||||
char *msg;
|
||||
char *line = packet_read_line(in, NULL);
|
||||
if (!line)
|
||||
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
|
||||
break;
|
||||
if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
|
||||
error("invalid ref status from remote: %s", line);
|
||||
if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) {
|
||||
error("invalid ref status from remote: %s", reader->line);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
refname = line + 3;
|
||||
refname = reader->line + 3;
|
||||
msg = strchr(refname, ' ');
|
||||
if (msg)
|
||||
*msg++ = '\0';
|
||||
@@ -187,7 +185,7 @@ static int receive_status(int in, struct ref *refs)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line[0] == 'o' && line[1] == 'k')
|
||||
if (reader->line[0] == 'o' && reader->line[1] == 'k')
|
||||
hint->status = REF_STATUS_OK;
|
||||
else {
|
||||
hint->status = REF_STATUS_REMOTE_REJECT;
|
||||
@@ -390,6 +388,7 @@ int send_pack(struct send_pack_args *args,
|
||||
int ret;
|
||||
struct async demux;
|
||||
const char *push_cert_nonce = NULL;
|
||||
struct packet_reader reader;
|
||||
|
||||
/* Does the other end support the reporting? */
|
||||
if (server_supports("report-status"))
|
||||
@@ -559,6 +558,8 @@ int send_pack(struct send_pack_args *args,
|
||||
in = demux.out;
|
||||
}
|
||||
|
||||
packet_reader_init(&reader, in, NULL, 0, PACKET_READ_CHOMP_NEWLINE);
|
||||
|
||||
if (need_pack_data && cmds_sent) {
|
||||
if (pack_objects(out, remote_refs, extra_have, args) < 0) {
|
||||
for (ref = remote_refs; ref; ref = ref->next)
|
||||
@@ -573,7 +574,7 @@ int send_pack(struct send_pack_args *args,
|
||||
* are failing, and just want the error() side effects.
|
||||
*/
|
||||
if (status_report)
|
||||
receive_unpack_status(in);
|
||||
receive_unpack_status(&reader);
|
||||
|
||||
if (use_sideband) {
|
||||
close(demux.out);
|
||||
@@ -590,7 +591,7 @@ int send_pack(struct send_pack_args *args,
|
||||
packet_flush(out);
|
||||
|
||||
if (status_report && cmds_sent)
|
||||
ret = receive_status(in, remote_refs);
|
||||
ret = receive_status(&reader, remote_refs);
|
||||
else
|
||||
ret = 0;
|
||||
if (args->stateless_rpc)
|
||||
|
||||
Reference in New Issue
Block a user