Skip to content

Commit af3a67d

Browse files
avargitster
authored andcommitted
negotiator: unknown fetch.negotiationAlgorithm should error out
Change the handling of fetch.negotiationAlgorithm=<str> to error out on unknown strings, i.e. everything except "default" or "skipping". This changes the behavior added in 42cc748 ("negotiator/skipping: skip commits during fetch", 2018-07-16) which would ignore all unknown values and silently fall back to the "default" value. For a feature like this it's much better to produce an error than proceed. We don't want users to debug some amazingly slow fetch that should benefit from "skipping", only to find that they'd forgotten to deploy the new git version on that particular machine. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35e22d5 commit af3a67d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Documentation/config.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,10 @@ fetch.negotiationAlgorithm::
14961496
sent when negotiating the contents of the packfile to be sent by the
14971497
server. Set to "skipping" to use an algorithm that skips commits in an
14981498
effort to converge faster, but may result in a larger-than-necessary
1499-
packfile; any other value instructs Git to use the default algorithm
1499+
packfile; The default is "default" which instructs Git to use the default algorithm
15001500
that never skips commits (unless the server has acknowledged it or one
15011501
of its descendants).
1502+
Unknown values will cause 'git fetch' to error out.
15021503

15031504
format.attach::
15041505
Enable multipart/mixed attachments as the default for

fetch-negotiator.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
void fetch_negotiator_init(struct fetch_negotiator *negotiator,
77
const char *algorithm)
88
{
9-
if (algorithm && !strcmp(algorithm, "skipping")) {
10-
skipping_negotiator_init(negotiator);
11-
return;
9+
if (algorithm) {
10+
if (!strcmp(algorithm, "skipping")) {
11+
skipping_negotiator_init(negotiator);
12+
return;
13+
} else if (!strcmp(algorithm, "default")) {
14+
/* Fall through to default initialization */
15+
} else {
16+
die("unknown fetch negotiation algorithm '%s'", algorithm);
17+
}
1218
}
1319
default_negotiator_init(negotiator);
1420
}

t/t5552-skipping-fetch-negotiator.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
4747
have_not_sent c6 c4 c3
4848
'
4949

50+
test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
51+
rm -rf server client trace &&
52+
git init server &&
53+
test_commit -C server to_fetch &&
54+
55+
git init client &&
56+
test_commit -C client on_client &&
57+
git -C client checkout on_client &&
58+
59+
test_config -C client fetch.negotiationAlgorithm invalid &&
60+
test_must_fail git -C client fetch "$(pwd)/server" 2>err &&
61+
test_i18ngrep "unknown fetch negotiation algorithm" err &&
62+
63+
# Explicit "default" value
64+
test_config -C client fetch.negotiationAlgorithm default &&
65+
git -C client -c fetch.negotiationAlgorithm=default fetch "$(pwd)/server" &&
66+
67+
# Implementation detail: If there is nothing to fetch, we will not error out
68+
test_config -C client fetch.negotiationAlgorithm invalid &&
69+
git -C client fetch "$(pwd)/server" 2>err &&
70+
test_i18ngrep ! "unknown fetch negotiation algorithm" err
71+
'
72+
5073
test_expect_success 'when two skips collide, favor the larger one' '
5174
rm -rf server client trace &&
5275
git init server &&

0 commit comments

Comments
 (0)