fetch-pack: refactor process_acks()
A subsequent commit will need part, but not all, of the functionality in process_acks(), so move some of its functionality to its sole caller do_fetch_pack_v2(). As a side effect, the resulting code is also shorter. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6db01a7308
commit
8102570374
70
fetch-pack.c
70
fetch-pack.c
@ -1351,35 +1351,11 @@ static int process_section_header(struct packet_reader *reader,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum common_found {
|
static int process_ack(struct fetch_negotiator *negotiator,
|
||||||
/*
|
struct packet_reader *reader,
|
||||||
* No commit was found to be possessed by both the client and the
|
struct object_id *common_oid,
|
||||||
* server, and "ready" was not received.
|
int *received_ready)
|
||||||
*/
|
|
||||||
NO_COMMON_FOUND,
|
|
||||||
|
|
||||||
/*
|
|
||||||
* At least one commit was found to be possessed by both the client and
|
|
||||||
* the server, and "ready" was not received.
|
|
||||||
*/
|
|
||||||
COMMON_FOUND,
|
|
||||||
|
|
||||||
/*
|
|
||||||
* "ready" was received, indicating that the server is ready to send
|
|
||||||
* the packfile without any further negotiation.
|
|
||||||
*/
|
|
||||||
READY
|
|
||||||
};
|
|
||||||
|
|
||||||
static enum common_found process_acks(struct fetch_negotiator *negotiator,
|
|
||||||
struct packet_reader *reader,
|
|
||||||
struct oidset *common)
|
|
||||||
{
|
{
|
||||||
/* received */
|
|
||||||
int received_ready = 0;
|
|
||||||
int received_ack = 0;
|
|
||||||
|
|
||||||
process_section_header(reader, "acknowledgments", 0);
|
|
||||||
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
|
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
|
||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
@ -1387,20 +1363,17 @@ static enum common_found process_acks(struct fetch_negotiator *negotiator,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (skip_prefix(reader->line, "ACK ", &arg)) {
|
if (skip_prefix(reader->line, "ACK ", &arg)) {
|
||||||
struct object_id oid;
|
if (!get_oid_hex(arg, common_oid)) {
|
||||||
received_ack = 1;
|
|
||||||
if (!get_oid_hex(arg, &oid)) {
|
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
oidset_insert(common, &oid);
|
commit = lookup_commit(the_repository, common_oid);
|
||||||
commit = lookup_commit(the_repository, &oid);
|
|
||||||
if (negotiator)
|
if (negotiator)
|
||||||
negotiator->ack(negotiator, commit);
|
negotiator->ack(negotiator, commit);
|
||||||
}
|
}
|
||||||
continue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(reader->line, "ready")) {
|
if (!strcmp(reader->line, "ready")) {
|
||||||
received_ready = 1;
|
*received_ready = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1418,13 +1391,12 @@ static enum common_found process_acks(struct fetch_negotiator *negotiator,
|
|||||||
* sent. Therefore, a DELIM is expected if "ready" is sent, and a FLUSH
|
* sent. Therefore, a DELIM is expected if "ready" is sent, and a FLUSH
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
if (received_ready && reader->status != PACKET_READ_DELIM)
|
if (*received_ready && reader->status != PACKET_READ_DELIM)
|
||||||
die(_("expected packfile to be sent after 'ready'"));
|
die(_("expected packfile to be sent after 'ready'"));
|
||||||
if (!received_ready && reader->status != PACKET_READ_FLUSH)
|
if (!*received_ready && reader->status != PACKET_READ_FLUSH)
|
||||||
die(_("expected no other sections to be sent after no 'ready'"));
|
die(_("expected no other sections to be sent after no 'ready'"));
|
||||||
|
|
||||||
return received_ready ? READY :
|
return 0;
|
||||||
(received_ack ? COMMON_FOUND : NO_COMMON_FOUND);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void receive_shallow_info(struct fetch_pack_args *args,
|
static void receive_shallow_info(struct fetch_pack_args *args,
|
||||||
@ -1573,6 +1545,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
|||||||
struct fetch_negotiator negotiator_alloc;
|
struct fetch_negotiator negotiator_alloc;
|
||||||
struct fetch_negotiator *negotiator;
|
struct fetch_negotiator *negotiator;
|
||||||
int seen_ack = 0;
|
int seen_ack = 0;
|
||||||
|
struct object_id common_oid;
|
||||||
|
int received_ready = 0;
|
||||||
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
|
struct string_list packfile_uris = STRING_LIST_INIT_DUP;
|
||||||
int i;
|
int i;
|
||||||
struct strvec index_pack_args = STRVEC_INIT;
|
struct strvec index_pack_args = STRVEC_INIT;
|
||||||
@ -1631,22 +1605,22 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
|||||||
break;
|
break;
|
||||||
case FETCH_PROCESS_ACKS:
|
case FETCH_PROCESS_ACKS:
|
||||||
/* Process ACKs/NAKs */
|
/* Process ACKs/NAKs */
|
||||||
switch (process_acks(negotiator, &reader, &common)) {
|
process_section_header(&reader, "acknowledgments", 0);
|
||||||
case READY:
|
while (process_ack(negotiator, &reader, &common_oid,
|
||||||
|
&received_ready)) {
|
||||||
|
in_vain = 0;
|
||||||
|
seen_ack = 1;
|
||||||
|
oidset_insert(&common, &common_oid);
|
||||||
|
}
|
||||||
|
if (received_ready) {
|
||||||
/*
|
/*
|
||||||
* Don't check for response delimiter; get_pack() will
|
* Don't check for response delimiter; get_pack() will
|
||||||
* read the rest of this response.
|
* read the rest of this response.
|
||||||
*/
|
*/
|
||||||
state = FETCH_GET_PACK;
|
state = FETCH_GET_PACK;
|
||||||
break;
|
} else {
|
||||||
case COMMON_FOUND:
|
|
||||||
in_vain = 0;
|
|
||||||
seen_ack = 1;
|
|
||||||
/* fallthrough */
|
|
||||||
case NO_COMMON_FOUND:
|
|
||||||
do_check_stateless_delimiter(args, &reader);
|
do_check_stateless_delimiter(args, &reader);
|
||||||
state = FETCH_SEND_REQUEST;
|
state = FETCH_SEND_REQUEST;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FETCH_GET_PACK:
|
case FETCH_GET_PACK:
|
||||||
|
Loading…
Reference in New Issue
Block a user