@matheusbsbs / matheus-bagliano / commits / d1185aa6fa
Fork 0

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 <jonathantanmy@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Apr 27, 2020 at 17:01 UTC d1185aa6fab2c12016e92ac9b9e448984cdc6c5d
1 file changed +28 -8
fetch-pack.c
+28 -8
@@ -1268,9 +1268,29 @@ static int process_section_header(struct packet_reader *reader,
1268 return ret;
1269 }
1270
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)
1294 {
1295 /* received */
1296 int received_ready = 0;
@@ -1319,8 +1339,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
1339 if (!received_ready && reader->status != PACKET_READ_FLUSH)
1340 die(_("expected no other sections to be sent after no 'ready'"));
1341
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);
1344 }
1345
1346 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,
1528 case FETCH_PROCESS_ACKS:
1529 /* Process ACKs/NAKs */
1530 switch (process_acks(negotiator, &reader, &common)) {
1511 - case 2:
1531 + case READY:
1532 state = FETCH_GET_PACK;
1533 break;
1514 - case 1:
1534 + case COMMON_FOUND:
1535 in_vain = 0;
1536 /* fallthrough */
1517 - default:
1537 + case NO_COMMON_FOUND:
1538 state = FETCH_SEND_REQUEST;
1539 break;
1540 }