Skip to content

Commit d1185aa

Browse files
jonathantanmygitster
authored andcommitted
fetch-pack: return enum from process_acks()
process_acks() returns 0, 1, or 2, depending on whether "ready" was received and if not, whether at least one commit was found to be common. Replace these magic numbers with a documented enum. Signed-off-by: Jonathan Tan <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7397ca3 commit d1185aa

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

fetch-pack.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,29 @@ static int process_section_header(struct packet_reader *reader,
12681268
return ret;
12691269
}
12701270

1271-
static int process_acks(struct fetch_negotiator *negotiator,
1272-
struct packet_reader *reader,
1273-
struct oidset *common)
1271+
enum common_found {
1272+
/*
1273+
* No commit was found to be possessed by both the client and the
1274+
* server, and "ready" was not received.
1275+
*/
1276+
NO_COMMON_FOUND,
1277+
1278+
/*
1279+
* At least one commit was found to be possessed by both the client and
1280+
* the server, and "ready" was not received.
1281+
*/
1282+
COMMON_FOUND,
1283+
1284+
/*
1285+
* "ready" was received, indicating that the server is ready to send
1286+
* the packfile without any further negotiation.
1287+
*/
1288+
READY
1289+
};
1290+
1291+
static enum common_found process_acks(struct fetch_negotiator *negotiator,
1292+
struct packet_reader *reader,
1293+
struct oidset *common)
12741294
{
12751295
/* received */
12761296
int received_ready = 0;
@@ -1319,8 +1339,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
13191339
if (!received_ready && reader->status != PACKET_READ_FLUSH)
13201340
die(_("expected no other sections to be sent after no 'ready'"));
13211341

1322-
/* return 0 if no common, 1 if there are common, or 2 if ready */
1323-
return received_ready ? 2 : (received_ack ? 1 : 0);
1342+
return received_ready ? READY :
1343+
(received_ack ? COMMON_FOUND : NO_COMMON_FOUND);
13241344
}
13251345

13261346
static void receive_shallow_info(struct fetch_pack_args *args,
@@ -1508,13 +1528,13 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
15081528
case FETCH_PROCESS_ACKS:
15091529
/* Process ACKs/NAKs */
15101530
switch (process_acks(negotiator, &reader, &common)) {
1511-
case 2:
1531+
case READY:
15121532
state = FETCH_GET_PACK;
15131533
break;
1514-
case 1:
1534+
case COMMON_FOUND:
15151535
in_vain = 0;
15161536
/* fallthrough */
1517-
default:
1537+
case NO_COMMON_FOUND:
15181538
state = FETCH_SEND_REQUEST;
15191539
break;
15201540
}

0 commit comments

Comments
 (0)