Merge branch 'en/fetch-negotiation-default-fix'

Interaction between fetch.negotiationAlgorithm and
feature.experimental configuration variables has been corrected.

* en/fetch-negotiation-default-fix:
  repo-settings: rename the traditional default fetch.negotiationAlgorithm
  repo-settings: fix error handling for unknown values
  repo-settings: fix checking for fetch.negotiationAlgorithm=default
This commit is contained in:
Junio C Hamano
2022-02-16 15:14:30 -08:00
5 changed files with 44 additions and 18 deletions

View File

@ -56,18 +56,19 @@ fetch.output::
OUTPUT in linkgit:git-fetch[1] for detail. OUTPUT in linkgit:git-fetch[1] for detail.
fetch.negotiationAlgorithm:: fetch.negotiationAlgorithm::
Control how information about the commits in the local repository is Control how information about the commits in the local repository
sent when negotiating the contents of the packfile to be sent by the is sent when negotiating the contents of the packfile to be sent by
server. Set to "skipping" to use an algorithm that skips commits in an the server. Set to "consecutive" to use an algorithm that walks
effort to converge faster, but may result in a larger-than-necessary over consecutive commits checking each one. Set to "skipping" to
packfile; or set to "noop" to not send any information at all, which use an algorithm that skips commits in an effort to converge
will almost certainly result in a larger-than-necessary packfile, but faster, but may result in a larger-than-necessary packfile; or set
will skip the negotiation step. to "noop" to not send any information at all, which will almost
The default is "default" which instructs Git to use the default algorithm certainly result in a larger-than-necessary packfile, but will skip
that never skips commits (unless the server has acknowledged it or one the negotiation step. Set to "default" to override settings made
of its descendants). If `feature.experimental` is enabled, then this previously and use the default behaviour. The default is normally
setting defaults to "skipping". "consecutive", but if `feature.experimental` is true, then the
Unknown values will cause 'git fetch' to error out. default is "skipping". Unknown values will cause 'git fetch' to
error out.
+ +
See also the `--negotiate-only` and `--negotiation-tip` options to See also the `--negotiate-only` and `--negotiation-tip` options to
linkgit:git-fetch[1]. linkgit:git-fetch[1].

View File

@ -18,7 +18,7 @@ void fetch_negotiator_init(struct repository *r,
noop_negotiator_init(negotiator); noop_negotiator_init(negotiator);
return; return;
case FETCH_NEGOTIATION_DEFAULT: case FETCH_NEGOTIATION_CONSECUTIVE:
default_negotiator_init(negotiator); default_negotiator_init(negotiator);
return; return;
} }

View File

@ -26,7 +26,7 @@ void prepare_repo_settings(struct repository *r)
/* Defaults */ /* Defaults */
r->settings.index_version = -1; r->settings.index_version = -1;
r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT; r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
/* Booleans config or default, cascades to other settings */ /* Booleans config or default, cascades to other settings */
repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
@ -81,10 +81,17 @@ void prepare_repo_settings(struct repository *r)
} }
if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) { if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
int fetch_default = r->settings.fetch_negotiation_algorithm;
if (!strcasecmp(strval, "skipping")) if (!strcasecmp(strval, "skipping"))
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
else if (!strcasecmp(strval, "noop")) else if (!strcasecmp(strval, "noop"))
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP; r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
else if (!strcasecmp(strval, "consecutive"))
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
else if (!strcasecmp(strval, "default"))
r->settings.fetch_negotiation_algorithm = fetch_default;
else
die("unknown fetch negotiation algorithm '%s'", strval);
} }
/* /*

View File

@ -20,7 +20,7 @@ enum untracked_cache_setting {
}; };
enum fetch_negotiation_setting { enum fetch_negotiation_setting {
FETCH_NEGOTIATION_DEFAULT, FETCH_NEGOTIATION_CONSECUTIVE,
FETCH_NEGOTIATION_SKIPPING, FETCH_NEGOTIATION_SKIPPING,
FETCH_NEGOTIATION_NOOP, FETCH_NEGOTIATION_NOOP,
}; };

View File

@ -927,7 +927,8 @@ test_expect_success 'fetching deepen' '
) )
' '
test_expect_success 'use ref advertisement to prune "have" lines sent' ' test_negotiation_algorithm_default () {
test_when_finished rm -rf clientv0 clientv2 &&
rm -rf server client && rm -rf server client &&
git init server && git init server &&
test_commit -C server both_have_1 && test_commit -C server both_have_1 &&
@ -946,7 +947,7 @@ test_expect_success 'use ref advertisement to prune "have" lines sent' '
rm -f trace && rm -f trace &&
cp -r client clientv0 && cp -r client clientv0 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv0 \ GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv0 \
fetch origin server_has both_have_2 && "$@" fetch origin server_has both_have_2 &&
grep "have $(git -C client rev-parse client_has)" trace && grep "have $(git -C client rev-parse client_has)" trace &&
grep "have $(git -C client rev-parse both_have_2)" trace && grep "have $(git -C client rev-parse both_have_2)" trace &&
! grep "have $(git -C client rev-parse both_have_2^)" trace && ! grep "have $(git -C client rev-parse both_have_2^)" trace &&
@ -954,10 +955,27 @@ test_expect_success 'use ref advertisement to prune "have" lines sent' '
rm -f trace && rm -f trace &&
cp -r client clientv2 && cp -r client clientv2 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv2 -c protocol.version=2 \ GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv2 -c protocol.version=2 \
fetch origin server_has both_have_2 && "$@" fetch origin server_has both_have_2 &&
grep "have $(git -C client rev-parse client_has)" trace && grep "have $(git -C client rev-parse client_has)" trace &&
grep "have $(git -C client rev-parse both_have_2)" trace && grep "have $(git -C client rev-parse both_have_2)" trace &&
! grep "have $(git -C client rev-parse both_have_2^)" trace ! grep "have $(git -C client rev-parse both_have_2^)" trace
}
test_expect_success 'use ref advertisement to prune "have" lines sent' '
test_negotiation_algorithm_default
'
test_expect_success 'same as last but with config overrides' '
test_negotiation_algorithm_default \
-c feature.experimental=true \
-c fetch.negotiationAlgorithm=consecutive
'
test_expect_success 'ensure bogus fetch.negotiationAlgorithm yields error' '
test_when_finished rm -rf clientv0 &&
cp -r client clientv0 &&
test_must_fail git -C clientv0 --fetch.negotiationAlgorithm=bogus \
fetch origin server_has both_have_2
' '
test_expect_success 'filtering by size' ' test_expect_success 'filtering by size' '