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 42cc7485a2 ("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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Aug 1, 2018 at 15:18 UTC
af3a67de014a145216ef06b588733cd0db002990
3 files changed
+34
-4
Documentation/config.txt
+2
-1
@@ -1496,9 +1496,10 @@ fetch.negotiationAlgorithm::
1496
sent when negotiating the contents of the packfile to be sent by the
1497
server. Set to "skipping" to use an algorithm that skips commits in an
1498
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
1500
that never skips commits (unless the server has acknowledged it or one
1501
of its descendants).
1502
+ Unknown values will cause 'git fetch' to error out.
1503
1504
format.attach::
1505
Enable multipart/mixed attachments as the default for
fetch-negotiator.c
+9
-3
@@ -6,9 +6,15 @@
6
void fetch_negotiator_init(struct fetch_negotiator *negotiator,
7
const char *algorithm)
8
{
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
+ }
18
}
19
default_negotiator_init(negotiator);
20
}
t/t5552-skipping-fetch-negotiator.sh
+23
@@ -47,6 +47,29 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
47
have_not_sent c6 c4 c3
48
'
49
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
+
73
test_expect_success 'when two skips collide, favor the larger one' '
74
rm -rf server client trace &&
75
git init server &&