Skip to content

Commit 25bccb4

Browse files
derrickstoleegitster
authored andcommitted
fetch: download bundles once, even with --all
When fetch.bundleURI is set, 'git fetch' downloads bundles from the given bundle URI before fetching from the specified remote. However, when using non-file remotes, 'git fetch --all' will launch 'git fetch' subprocesses which then read fetch.bundleURI and fetch the bundle list again. We do not expect the bundle list to have new information during these multiple runs, so avoid these extra calls by un-setting fetch.bundleURI in the subprocess arguments. Be careful to skip fetching bundles for the empty bundle string. Fetching bundles from the empty list presents some interesting test failures. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6369acd commit 25bccb4

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

builtin/fetch.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,12 @@ static int fetch_multiple(struct string_list *list, int max_children)
19551955
return errcode;
19561956
}
19571957

1958-
strvec_pushl(&argv, "fetch", "--append", "--no-auto-gc",
1958+
/*
1959+
* Cancel out the fetch.bundleURI config when running subprocesses,
1960+
* to avoid fetching from the same bundle list multiple times.
1961+
*/
1962+
strvec_pushl(&argv, "-c", "fetch.bundleURI=",
1963+
"fetch", "--append", "--no-auto-gc",
19591964
"--no-write-commit-graph", NULL);
19601965
add_options_to_argv(&argv);
19611966

bundle-uri.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,15 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
792792

793793
init_bundle_list(&list);
794794

795+
/*
796+
* Do not fetch a NULL or empty bundle URI. An empty bundle URI
797+
* could signal that a configured bundle URI has been disabled.
798+
*/
799+
if (!uri || !*uri) {
800+
result = 0;
801+
goto cleanup;
802+
}
803+
795804
/* If a bundle is added to this global list, then it is required. */
796805
list.mode = BUNDLE_MODE_ALL;
797806

t/t5558-clone-bundle-uri.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,40 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
10181018
test_cmp expect refs
10191019
'
10201020

1021+
test_expect_success 'bundles are downloaded once during fetch --all' '
1022+
test_when_finished rm -rf download-* trace*.txt fetch-mult &&
1023+
1024+
cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
1025+
[bundle]
1026+
version = 1
1027+
mode = all
1028+
heuristic = creationToken
1029+
1030+
[bundle "bundle-1"]
1031+
uri = bundle-1.bundle
1032+
creationToken = 1
1033+
1034+
[bundle "bundle-2"]
1035+
uri = bundle-2.bundle
1036+
creationToken = 2
1037+
1038+
[bundle "bundle-3"]
1039+
uri = bundle-3.bundle
1040+
creationToken = 3
1041+
EOF
1042+
1043+
git clone --single-branch --branch=left \
1044+
--bundle-uri="$HTTPD_URL/bundle-list" \
1045+
"$HTTPD_URL/smart/fetch.git" fetch-mult &&
1046+
git -C fetch-mult remote add dup1 "$HTTPD_URL/smart/fetch.git" &&
1047+
git -C fetch-mult remote add dup2 "$HTTPD_URL/smart/fetch.git" &&
1048+
1049+
GIT_TRACE2_EVENT="$(pwd)/trace-mult.txt" \
1050+
git -C fetch-mult fetch --all &&
1051+
grep "\"child_start\".*\"git-remote-https\",\"$HTTPD_URL/bundle-list\"" \
1052+
trace-mult.txt >bundle-fetches &&
1053+
test_line_count = 1 bundle-fetches
1054+
'
10211055
# Do not add tests here unless they use the HTTP server, as they will
10221056
# not run unless the HTTP dependencies exist.
10231057

0 commit comments

Comments
 (0)