]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: support hideRefs to speed up connectivity checks
authorEric Wong <e@80x24.org>
Sun, 12 Feb 2023 09:04:26 +0000 (09:04 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Feb 2023 17:27:03 +0000 (09:27 -0800)
With roughly 800 remotes all fetching into their own
refs/remotes/$REMOTE/* island, the connectivity check[1] gets
expensive for each fetch on systems which lack sufficient RAM to
cache objects.

To do a no-op fetch on one $REMOTE out of hundreds, hideRefs now
allows the no-op fetch to take ~30 seconds instead of ~20 minutes
on a noisy, RAM-constrained machine (localhost, so no network latency):

   git -c fetch.hideRefs=refs \
-c fetch.hideRefs='!refs/remotes/$REMOTE/' \
fetch $REMOTE

[1] `git rev-list --objects --stdin --not --all --quiet --alternate-refs'

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rev-parse.txt
Documentation/rev-list-options.txt
builtin/fetch.c
builtin/rev-list.c
revision.c
t/t5510-fetch.sh
t/t6018-rev-list-glob.sh
t/t6021-rev-list-exclude-hidden.sh

index bcd80692870ae002db0bc3c1684c9a0959673964..f26a7591e3737df6bcf190fc26f0fe2bf50fcd83 100644 (file)
@@ -197,10 +197,11 @@ respectively, and they must begin with `refs/` when applied to `--glob`
 or `--all`. If a trailing '/{asterisk}' is intended, it must be given
 explicitly.
 
---exclude-hidden=[receive|uploadpack]::
-       Do not include refs that would be hidden by `git-receive-pack` or
-       `git-upload-pack` by consulting the appropriate `receive.hideRefs` or
-       `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see
+--exclude-hidden=[fetch|receive|uploadpack]::
+       Do not include refs that would be hidden by `git-fetch`,
+       `git-receive-pack` or `git-upload-pack` by consulting the appropriate
+       `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs`
+       configuration along with `transfer.hideRefs` (see
        linkgit:git-config[1]). This option affects the next pseudo-ref option
        `--all` or `--glob` and is cleared after processing them.
 
index 0d90d5b1549aa2e50647e1a0a6195a2ed301d699..90c73d6708b1d7dc90f50380c20521a1f713ff90 100644 (file)
@@ -195,10 +195,11 @@ respectively, and they must begin with `refs/` when applied to `--glob`
 or `--all`. If a trailing '/{asterisk}' is intended, it must be given
 explicitly.
 
---exclude-hidden=[receive|uploadpack]::
-       Do not include refs that would be hidden by `git-receive-pack` or
-       `git-upload-pack` by consulting the appropriate `receive.hideRefs` or
-       `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see
+--exclude-hidden=[fetch|receive|uploadpack]::
+       Do not include refs that would be hidden by `git-fetch`,
+       `git-receive-pack` or `git-upload-pack` by consulting the appropriate
+       `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs`
+       configuration along with `transfer.hideRefs` (see
        linkgit:git-config[1]). This option affects the next pseudo-ref option
        `--all` or `--glob` and is cleared after processing them.
 
index a09606b472622c133a683513ffdbe184952f2b01..edbeb19d3bdadde8255df56ae7309bc4315e03c6 100644 (file)
@@ -1132,6 +1132,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
        if (!connectivity_checked) {
                struct check_connected_options opt = CHECK_CONNECTED_INIT;
 
+               opt.exclude_hidden_refs_section = "fetch";
                rm = ref_map;
                if (check_connected(iterate_ref_map, &rm, &opt)) {
                        rc = error(_("%s did not send all necessary objects\n"), url);
@@ -1325,6 +1326,7 @@ static int check_exist_and_connected(struct ref *ref_map)
        }
 
        opt.quiet = 1;
+       opt.exclude_hidden_refs_section = "fetch";
        return check_connected(iterate_ref_map, &rm, &opt);
 }
 
index d42db0b0cc9fa22ad8674ceddef8d1c735791f37..2ab3efd233b029c816527bb9fe64642d7f698e2b 100644 (file)
@@ -38,7 +38,7 @@ static const char rev_list_usage[] =
 "    --tags\n"
 "    --remotes\n"
 "    --stdin\n"
-"    --exclude-hidden=[receive|uploadpack]\n"
+"    --exclude-hidden=[fetch|receive|uploadpack]\n"
 "    --quiet\n"
 "  ordering output:\n"
 "    --topo-order\n"
index 21f5f572c22ec7054da6bc20fef26ee2a59a19d5..50940699e4a88992d1c91d957776f7ed82d9bbf9 100644 (file)
@@ -1574,7 +1574,8 @@ void exclude_hidden_refs(struct ref_exclusions *exclusions, const char *section)
 {
        struct exclude_hidden_refs_cb cb;
 
-       if (strcmp(section, "receive") && strcmp(section, "uploadpack"))
+       if (strcmp(section, "fetch") && strcmp(section, "receive") &&
+                       strcmp(section, "uploadpack"))
                die(_("unsupported section for hidden refs: %s"), section);
 
        if (exclusions->hidden_refs_configured)
index 34a1261520c757053bfb64c8aa2104c407514091..dc44da9c7978ab37e503614cb7524e8c6ba81632 100755 (executable)
@@ -1171,6 +1171,15 @@ test_expect_success '--no-show-forced-updates' '
        )
 '
 
+for section in fetch transfer
+do
+       test_expect_success "$section.hideRefs affects connectivity check" '
+               GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \
+                       $section.hideRefs="!refs/tags/" fetch &&
+               grep "git rev-list .*--exclude-hidden=fetch" trace
+       '
+done
+
 setup_negotiation_tip () {
        SERVER="$1"
        URL="$2"
index aabf590dda61d1ea1b7c70e79bbfa00819ea235e..67d523d40571b89b50cc5ca655ec77198c1a3ae3 100755 (executable)
@@ -187,7 +187,7 @@ test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
        compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
 '
 
-for section in receive uploadpack
+for section in fetch receive uploadpack
 do
        test_expect_success "rev-parse --exclude-hidden=$section with --all" '
                compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all"
index 11c50b7c0dd85c629ef9687eb81d36543939bddd..1a9d37e63862f03877fe3d02b94ec8428e7ea01a 100755 (executable)
@@ -22,7 +22,7 @@ test_expect_success 'invalid section' '
        test_cmp expected err
 '
 
-for section in receive uploadpack
+for section in fetch receive uploadpack
 do
        test_expect_success "$section: passed multiple times" '
                echo "fatal: --exclude-hidden= passed more than once" >expected &&