fetch-pack: in protocol v2, reset in_vain upon ACK
In the function process_acks() in fetch-pack.c, the variable received_ack is meant to track that an ACK was received, but it was never set. This results in negotiation terminating prematurely through the in_vain counter, when the counter should have been reset upon every ACK. Therefore, reset the in_vain counter upon every ACK. Helped-by: Jonathan Nieder <jrnieder@gmail.com> 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
2f0a093dd640e0dad0b261dae2427f2541b5426c
2 files changed
+31
fetch-pack.c
+1
@@ -1307,6 +1307,7 @@ static enum common_found process_acks(struct fetch_negotiator *negotiator,
1307
1308
if (skip_prefix(reader->line, "ACK ", &arg)) {
1309
struct object_id oid;
1310
+ received_ack = 1;
1311
if (!get_oid_hex(arg, &oid)) {
1312
struct commit *commit;
1313
oidset_insert(common, &oid);
t/t5500-fetch-pack.sh
+30
@@ -403,6 +403,36 @@ test_expect_success 'in_vain not triggered before first ACK' '
403
test_i18ngrep "Total 3 " trace
404
'
405
406
+test_expect_success 'in_vain resetted upon ACK' '
407
+ rm -rf myserver myclient trace &&
408
+ git init myserver &&
409
+
410
+ # Linked list of commits on master. The first is common; the rest are
411
+ # not.
412
+ test_commit -C myserver first_master_commit &&
413
+ git clone "file://$(pwd)/myserver" myclient &&
414
+ test_commit_bulk -C myclient 255 &&
415
+
416
+ # Another linked list of commits on anotherbranch with no connection to
417
+ # master. The first is common; the rest are not.
418
+ git -C myserver checkout --orphan anotherbranch &&
419
+ test_commit -C myserver first_anotherbranch_commit &&
420
+ git -C myclient fetch origin anotherbranch:refs/heads/anotherbranch &&
421
+ git -C myclient checkout anotherbranch &&
422
+ test_commit_bulk -C myclient 255 &&
423
+
424
+ # The new commit that the client wants to fetch.
425
+ git -C myserver checkout master &&
426
+ test_commit -C myserver to_fetch &&
427
+
428
+ # The client will send (as "have"s) all 256 commits in anotherbranch
429
+ # first. The 256th commit is common between the client and the server,
430
+ # and should reset in_vain. This allows negotiation to continue until
431
+ # the client reports that first_anotherbranch_commit is common.
432
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C myclient fetch --progress origin master &&
433
+ test_i18ngrep "Total 3 " trace
434
+'
435
+
436
test_expect_success 'fetch in shallow repo unreachable shallow objects' '
437
(
438
git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&