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 <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Mar 31, 2023 at 15:59 UTC 25bccb4b79dce1d5c259228ef3c91eadcd13d8ac
3 files changed +49 -1
builtin/fetch.c
+6 -1
@@ -1955,7 +1955,12 @@ static int fetch_multiple(struct string_list *list, int max_children)
1955 return errcode;
1956 }
1957
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",
1964 "--no-write-commit-graph", NULL);
1965 add_options_to_argv(&argv);
1966
bundle-uri.c
+9
@@ -792,6 +792,15 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
792
793 init_bundle_list(&list);
794
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 +
804 /* If a bundle is added to this global list, then it is required. */
805 list.mode = BUNDLE_MODE_ALL;
806
t/t5558-clone-bundle-uri.sh
+34
@@ -1018,6 +1018,40 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
1018 test_cmp expect refs
1019 '
1020
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 +'
1055 # Do not add tests here unless they use the HTTP server, as they will
1056 # not run unless the HTTP dependencies exist.
1057