@@ -1143,6 +1143,7 @@ static void add_common(struct strbuf *req_buf, struct oidset *common)
11431143}
11441144
11451145static int add_haves (struct fetch_negotiator * negotiator ,
1146+ int seen_ack ,
11461147 struct strbuf * req_buf ,
11471148 int * haves_to_send , int * in_vain )
11481149{
@@ -1157,7 +1158,7 @@ static int add_haves(struct fetch_negotiator *negotiator,
11571158 }
11581159
11591160 * in_vain += haves_added ;
1160- if (!haves_added || * in_vain >= MAX_IN_VAIN ) {
1161+ if (!haves_added || ( seen_ack && * in_vain >= MAX_IN_VAIN ) ) {
11611162 /* Send Done */
11621163 packet_buf_write (req_buf , "done\n" );
11631164 ret = 1 ;
@@ -1173,7 +1174,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
11731174 struct fetch_pack_args * args ,
11741175 const struct ref * wants , struct oidset * common ,
11751176 int * haves_to_send , int * in_vain ,
1176- int sideband_all )
1177+ int sideband_all , int seen_ack )
11771178{
11781179 int ret = 0 ;
11791180 struct strbuf req_buf = STRBUF_INIT ;
@@ -1230,7 +1231,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
12301231 add_common (& req_buf , common );
12311232
12321233 /* Add initial haves */
1233- ret = add_haves (negotiator , & req_buf , haves_to_send , in_vain );
1234+ ret = add_haves (negotiator , seen_ack , & req_buf ,
1235+ haves_to_send , in_vain );
12341236 }
12351237
12361238 /* Send request */
@@ -1268,9 +1270,29 @@ static int process_section_header(struct packet_reader *reader,
12681270 return ret ;
12691271}
12701272
1271- static int process_acks (struct fetch_negotiator * negotiator ,
1272- struct packet_reader * reader ,
1273- struct oidset * common )
1273+ enum common_found {
1274+ /*
1275+ * No commit was found to be possessed by both the client and the
1276+ * server, and "ready" was not received.
1277+ */
1278+ NO_COMMON_FOUND ,
1279+
1280+ /*
1281+ * At least one commit was found to be possessed by both the client and
1282+ * the server, and "ready" was not received.
1283+ */
1284+ COMMON_FOUND ,
1285+
1286+ /*
1287+ * "ready" was received, indicating that the server is ready to send
1288+ * the packfile without any further negotiation.
1289+ */
1290+ READY
1291+ };
1292+
1293+ static enum common_found process_acks (struct fetch_negotiator * negotiator ,
1294+ struct packet_reader * reader ,
1295+ struct oidset * common )
12741296{
12751297 /* received */
12761298 int received_ready = 0 ;
@@ -1285,6 +1307,7 @@ static int process_acks(struct fetch_negotiator *negotiator,
12851307
12861308 if (skip_prefix (reader -> line , "ACK " , & arg )) {
12871309 struct object_id oid ;
1310+ received_ack = 1 ;
12881311 if (!get_oid_hex (arg , & oid )) {
12891312 struct commit * commit ;
12901313 oidset_insert (common , & oid );
@@ -1319,8 +1342,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
13191342 if (!received_ready && reader -> status != PACKET_READ_FLUSH )
13201343 die (_ ("expected no other sections to be sent after no 'ready'" ));
13211344
1322- /* return 0 if no common, 1 if there are common, or 2 if ready */
1323- return received_ready ? 2 : (received_ack ? 1 : 0 );
1345+ return received_ready ? READY :
1346+ (received_ack ? COMMON_FOUND : NO_COMMON_FOUND );
13241347}
13251348
13261349static void receive_shallow_info (struct fetch_pack_args * args ,
@@ -1444,6 +1467,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
14441467 int haves_to_send = INITIAL_FLUSH ;
14451468 struct fetch_negotiator negotiator_alloc ;
14461469 struct fetch_negotiator * negotiator ;
1470+ int seen_ack = 0 ;
14471471
14481472 if (args -> no_dependents ) {
14491473 negotiator = NULL ;
@@ -1500,21 +1524,23 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
15001524 if (send_fetch_request (negotiator , fd [1 ], args , ref ,
15011525 & common ,
15021526 & haves_to_send , & in_vain ,
1503- reader .use_sideband ))
1527+ reader .use_sideband ,
1528+ seen_ack ))
15041529 state = FETCH_GET_PACK ;
15051530 else
15061531 state = FETCH_PROCESS_ACKS ;
15071532 break ;
15081533 case FETCH_PROCESS_ACKS :
15091534 /* Process ACKs/NAKs */
15101535 switch (process_acks (negotiator , & reader , & common )) {
1511- case 2 :
1536+ case READY :
15121537 state = FETCH_GET_PACK ;
15131538 break ;
1514- case 1 :
1539+ case COMMON_FOUND :
15151540 in_vain = 0 ;
1541+ seen_ack = 1 ;
15161542 /* fallthrough */
1517- default :
1543+ case NO_COMMON_FOUND :
15181544 state = FETCH_SEND_REQUEST ;
15191545 break ;
15201546 }
0 commit comments