From: Taylor Blau <me@ttaylorr.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Igor Todorovski <itodorov@ca.ibm.com>,
Bence Ferdinandy <bence@ferdinandy.com>
Subject: Re: [PATCH 6/9] fetch: ask server to advertise HEAD for config-less fetch
Date: Wed, 12 Mar 2025 17:43:24 -0400 [thread overview]
Message-ID: <Z9H//JHtYTGqHI3n@nand.local> (raw)
In-Reply-To: <20250309030847.GF2334191@coredump.intra.peff.net>
On Sat, Mar 08, 2025 at 10:08:47PM -0500, Jeff King wrote:
> If we're not given any refspecs (either on the command line or via
> config) and we have no branch merge config, then we fetch the remote
> HEAD into our local FETCH_HEAD. In that case we do not send any
> ref-prefix option to the server at all, and we see the full
> advertisement.
>
> But this is sub-optimal. We only care about HEAD, so we can just ask
> for that, and ignore all of the other refs.
>
> The new test demonstrates a case where we see fewer refs (in this case
> only one less, but in theory we could be ignoring millions of them).
>
> This also removes the only case where we care about seeing some refs
> from the other side, but don't add anything to the ref_prefixes list.
> Cleaning this up means one less maintenance burden. Before this patch,
> any code which wanted to add to the list had to make sure the list was
> not empty, since an empty list meant "ask for everything". Now it really
> means "we are not interested in any refs".
Yes. The optimization is nice on its own, but I think this is the real
benefit to this patch IMHO.
> This should let us optimize a few more cases in subsequent patches.
;-).
> Note that we'll add "HEAD" to the list of prefixes, and later code for
> updating "refs/remotes/<remote>/HEAD" may likewise do so. In theory this
> could cause duplicates in the list, but in practice these can't both
> trigger. We hit our new case only if there are no refspecs, and the
> "<remote>/HEAD" feature is enabled only when we are fetching from a
> remote with configured refspecs. We could be defensive with a flag, but
> it didn't seem worth it to me (the absolute worse case is a useless
> redundant ref-prefix line sent to the server).
Yeah, I think that we already do this in some instances that you and I
talked about off-list, but I can't remember exactly what I did to
provoke it. In either case, the server responds correctly, so I don't
think it's so urgent to deal with ATM.
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 95fd0018b9..f142756441 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1766,6 +1766,14 @@ static int do_fetch(struct transport *transport,
> branch->merge[i]->src);
> }
> }
> +
> + /*
> + * If there are no refs specified to fetch, then we just
> + * fetch HEAD; mention that to narrow the advertisement.
> + */
> + if (!transport_ls_refs_options.ref_prefixes.nr)
> + strvec_push(&transport_ls_refs_options.ref_prefixes,
> + "HEAD");
Makes sense. If we know that we just want to fetch HEAD into FETCH_HEAD
and we haven't already limited the advertisement, we are free to do so
now.
> if (tags == TAGS_SET || tags == TAGS_DEFAULT) {
> diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
> index cea8f92a3d..2f0a52a72d 100755
> --- a/t/t5702-protocol-v2.sh
> +++ b/t/t5702-protocol-v2.sh
> @@ -679,6 +679,21 @@ test_expect_success 'default refspec is used to filter ref when fetching' '
> grep "ref-prefix refs/tags/" log
> '
>
> +test_expect_success 'set up parent for prefix tests' '
> + git init prefix-parent &&
> + git -C prefix-parent commit --allow-empty -m foo &&
Any reason to use a bona-fide "commit" here instead of "test_commit"?
Not a big deal either way, of course, I'm just curious.
> + git -C prefix-parent branch unrelated-branch
> +'
> +
> +test_expect_success 'empty refspec filters refs when fetching' '
> + git init configless-child &&
> +
> + test_when_finished "rm -f log" &&
> + GIT_TRACE_PACKET="$(pwd)/log" \
> + git -C configless-child fetch ../prefix-parent &&
> + test_grep ! unrelated-branch log
Very clean, nice.
Thanks,
Taylor
next prev parent reply other threads:[~2025-03-12 21:43 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 3:49 Tags are no longer fetched when fetching specific commit Igor Todorovski
2025-02-13 22:38 ` Taylor Blau
2025-02-14 13:53 ` Bence Ferdinandy
2025-02-14 18:35 ` Junio C Hamano
2025-02-21 7:25 ` Jeff King
2025-03-07 23:27 ` [PATCH] fetch: fix following tags when fetching specific OID Taylor Blau
2025-03-07 23:32 ` Taylor Blau
2025-03-08 0:10 ` Junio C Hamano
2025-03-08 3:23 ` Bence Ferdinandy
2025-03-09 3:01 ` [PATCH 0/9] fetch: further ref-prefix cleanups and optimizations Jeff King
2025-03-09 3:01 ` [PATCH 1/9] t5702: fix typo in test name Jeff King
2025-03-12 21:30 ` Taylor Blau
2025-03-13 5:37 ` Jeff King
2025-03-09 3:01 ` [PATCH 2/9] t5516: prefer "oid" to "sha1" in some test titles Jeff King
2025-03-09 3:02 ` [PATCH 3/9] t5516: drop NEEDSWORK about v2 reachability behavior Jeff King
2025-03-12 21:30 ` Taylor Blau
2025-03-09 3:02 ` [PATCH 4/9] t5516: beef up exact-oid ref prefixes test Jeff King
2025-03-09 3:07 ` [PATCH 5/9] refspec_ref_prefixes(): clean up refspec_item logic Jeff King
2025-03-12 21:38 ` Taylor Blau
2025-03-13 5:41 ` Jeff King
2025-03-13 13:26 ` Junio C Hamano
2025-03-17 22:24 ` [PATCH 0/4] refspec: treat 'fetch' as a Boolean value Taylor Blau
2025-03-17 22:24 ` [PATCH 1/4] " Taylor Blau
2025-03-18 0:24 ` Jeff King
2025-03-18 0:26 ` Jeff King
2025-03-18 22:44 ` Taylor Blau
2025-03-17 22:24 ` [PATCH 2/4] refspec: replace `refspec_init()` with fetch/push variants Taylor Blau
2025-03-17 22:24 ` [PATCH 3/4] refspec: remove refspec_item_init_or_die() Taylor Blau
2025-03-17 22:24 ` [PATCH 4/4] refspec: replace `refspec_item_init()` with fetch/push variants Taylor Blau
2025-03-17 23:26 ` [PATCH 0/4] refspec: treat 'fetch' as a Boolean value Junio C Hamano
2025-03-18 22:40 ` Taylor Blau
2025-03-18 22:50 ` [PATCH v2 " Taylor Blau
2025-03-18 22:50 ` [PATCH v2 1/4] " Taylor Blau
2025-03-18 22:50 ` [PATCH v2 2/4] refspec: replace `refspec_init()` with fetch/push variants Taylor Blau
2025-03-18 22:50 ` [PATCH v2 3/4] refspec: remove refspec_item_init_or_die() Taylor Blau
2025-03-18 22:50 ` [PATCH v2 4/4] refspec: replace `refspec_item_init()` with fetch/push variants Taylor Blau
2025-03-19 15:31 ` [PATCH v2 0/4] refspec: treat 'fetch' as a Boolean value Elijah Newren
2025-03-17 22:00 ` [PATCH 5/9] refspec_ref_prefixes(): clean up refspec_item logic Taylor Blau
2025-03-17 23:25 ` Junio C Hamano
2025-03-18 22:47 ` Taylor Blau
2025-03-09 3:08 ` [PATCH 6/9] fetch: ask server to advertise HEAD for config-less fetch Jeff King
2025-03-12 21:43 ` Taylor Blau [this message]
2025-03-13 5:46 ` Jeff King
2025-03-13 12:26 ` Junio C Hamano
2025-03-17 22:23 ` Taylor Blau
2025-03-09 3:10 ` [PATCH 7/9] fetch: stop protecting additions to ref-prefix list Jeff King
2025-03-12 21:45 ` Taylor Blau
2025-03-09 3:20 ` [PATCH 8/9] fetch: avoid ls-refs only to ask for HEAD symref update Jeff King
2025-03-13 15:53 ` Junio C Hamano
2025-03-17 18:06 ` Jeff King
2025-03-17 19:01 ` Junio C Hamano
2025-03-18 5:39 ` [PATCH 0/2] limiting followRemoteHEAD being used Jeff King
2025-03-18 5:40 ` [PATCH 1/2] fetch: only respect followRemoteHEAD with configured refspecs Jeff King
2025-03-18 23:02 ` Taylor Blau
2025-03-18 5:41 ` [PATCH 2/2] fetch: don't ask for remote HEAD if followRemoteHEAD is "never" Jeff King
2025-03-18 19:18 ` [PATCH 0/2] limiting followRemoteHEAD being used Junio C Hamano
2025-03-18 23:02 ` Taylor Blau
2025-03-09 3:21 ` [PATCH 9/9] fetch: use ref prefix list to skip ls-refs Jeff King
2025-03-12 21:29 ` [PATCH 0/9] fetch: further ref-prefix cleanups and optimizations Taylor Blau
2025-03-12 21:49 ` Taylor Blau
2025-03-13 5:50 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9H//JHtYTGqHI3n@nand.local \
--to=me@ttaylorr.com \
--cc=bence@ferdinandy.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=itodorov@ca.ibm.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).