@@ -1143,6 +1143,7 @@ static void add_common(struct strbuf *req_buf, struct oidset *common)
1143
1143
}
1144
1144
1145
1145
static int add_haves (struct fetch_negotiator * negotiator ,
1146
+ int seen_ack ,
1146
1147
struct strbuf * req_buf ,
1147
1148
int * haves_to_send , int * in_vain )
1148
1149
{
@@ -1157,7 +1158,7 @@ static int add_haves(struct fetch_negotiator *negotiator,
1157
1158
}
1158
1159
1159
1160
* in_vain += haves_added ;
1160
- if (!haves_added || * in_vain >= MAX_IN_VAIN ) {
1161
+ if (!haves_added || ( seen_ack && * in_vain >= MAX_IN_VAIN ) ) {
1161
1162
/* Send Done */
1162
1163
packet_buf_write (req_buf , "done\n" );
1163
1164
ret = 1 ;
@@ -1173,7 +1174,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1173
1174
struct fetch_pack_args * args ,
1174
1175
const struct ref * wants , struct oidset * common ,
1175
1176
int * haves_to_send , int * in_vain ,
1176
- int sideband_all )
1177
+ int sideband_all , int seen_ack )
1177
1178
{
1178
1179
int ret = 0 ;
1179
1180
struct strbuf req_buf = STRBUF_INIT ;
@@ -1230,7 +1231,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1230
1231
add_common (& req_buf , common );
1231
1232
1232
1233
/* 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 );
1234
1236
}
1235
1237
1236
1238
/* Send request */
@@ -1268,9 +1270,29 @@ static int process_section_header(struct packet_reader *reader,
1268
1270
return ret ;
1269
1271
}
1270
1272
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 )
1274
1296
{
1275
1297
/* received */
1276
1298
int received_ready = 0 ;
@@ -1285,6 +1307,7 @@ static int process_acks(struct fetch_negotiator *negotiator,
1285
1307
1286
1308
if (skip_prefix (reader -> line , "ACK " , & arg )) {
1287
1309
struct object_id oid ;
1310
+ received_ack = 1 ;
1288
1311
if (!get_oid_hex (arg , & oid )) {
1289
1312
struct commit * commit ;
1290
1313
oidset_insert (common , & oid );
@@ -1319,8 +1342,8 @@ static int process_acks(struct fetch_negotiator *negotiator,
1319
1342
if (!received_ready && reader -> status != PACKET_READ_FLUSH )
1320
1343
die (_ ("expected no other sections to be sent after no 'ready'" ));
1321
1344
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 );
1324
1347
}
1325
1348
1326
1349
static 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,
1444
1467
int haves_to_send = INITIAL_FLUSH ;
1445
1468
struct fetch_negotiator negotiator_alloc ;
1446
1469
struct fetch_negotiator * negotiator ;
1470
+ int seen_ack = 0 ;
1447
1471
1448
1472
if (args -> no_dependents ) {
1449
1473
negotiator = NULL ;
@@ -1500,21 +1524,23 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1500
1524
if (send_fetch_request (negotiator , fd [1 ], args , ref ,
1501
1525
& common ,
1502
1526
& haves_to_send , & in_vain ,
1503
- reader .use_sideband ))
1527
+ reader .use_sideband ,
1528
+ seen_ack ))
1504
1529
state = FETCH_GET_PACK ;
1505
1530
else
1506
1531
state = FETCH_PROCESS_ACKS ;
1507
1532
break ;
1508
1533
case FETCH_PROCESS_ACKS :
1509
1534
/* Process ACKs/NAKs */
1510
1535
switch (process_acks (negotiator , & reader , & common )) {
1511
- case 2 :
1536
+ case READY :
1512
1537
state = FETCH_GET_PACK ;
1513
1538
break ;
1514
- case 1 :
1539
+ case COMMON_FOUND :
1515
1540
in_vain = 0 ;
1541
+ seen_ack = 1 ;
1516
1542
/* fallthrough */
1517
- default :
1543
+ case NO_COMMON_FOUND :
1518
1544
state = FETCH_SEND_REQUEST ;
1519
1545
break ;
1520
1546
}
0 commit comments