From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, "Mitja Bezenšek" <mitja.bezensek@login5.org>,
"Patrick Steinhardt" <ps@pks.im>,
"Justin Tobler" <jltobler@gmail.com>
Subject: Re: [PATCH v2] fetch: commit references fetched before backfilling tags
Date: Mon, 12 Oct 2026 12:55:11 -0700 [thread overview]
Message-ID: <xmqq4ieq66e8.fsf@gitster.g> (raw)
In-Reply-To: <20261012-799-shallow-fetch-with-tags-v2-1-4211e9a13d3c@gmail.com> (Karthik Nayak's message of "Mon, 12 Oct 2026 17:29:17 +0200")
Karthik Nayak <karthik.188@gmail.com> writes:
> When using batched updates, the references aren't yet committed to disk
> when we start backfilling tags. This means in situations such as shallow
> fetching the negotiation during backfilling tags, the client doesn't
> have any references to report in the 'have' section. Since backfilling
> doesn't use a depth limit, this can cause the server to send all the
> objects present in the repository.
Ouch.
> Fix this by committing the previous batched update and initiating a new
> one for backfilling tags. Also add a test which captures this regression.
> @@ -2076,6 +2076,27 @@ static int do_fetch(struct transport *transport,
> struct ref *tags_ref_map = NULL, **tail = &tags_ref_map;
>
> find_non_local_tags(remote_refs, transaction, &tags_ref_map, &tail);
> +
> + /*
> + * Backfilling tags has no depth limit. If we don't commit
> + * the fetched references, the backfill will report no refs
> + * in the 'have' section of the negotiation. This can cause
> + * the server to send all objects.
> + */
Does this problem only happen when the main fetch updated some ref,
or can backfilling make such a huge negotiation even when the main
fetch transaction is empty?
> + if (tags_ref_map && !atomic_fetch) {
> + retcode |= commit_ref_transaction(&transaction, false,
> + transport->remote->name,
> + &rejected_refs, &err);
This block is entered only when "--atomic" is not in effect, because
we want to update all refs or nothing, and these "all refs"
presumably includes the followed tags, but does it mean those who
want atomic fetch should be prepared to see their fetch degenerate
down to a full clone?
> +
> + transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
> + REF_TRANSACTION_ALLOW_FAILURE, &err);
> + if (!transaction) {
> + free_refs(tags_ref_map);
> + retcode = -1;
> + goto cleanup;
Is this jumping a bit too far? If our primary fetch have finished
successfully, and opening the next transaction only for tag backfill
task has failed, there are tons of processing happening we skip with
this new "goto" that we would have normally performed, starting with
computing summary_width used for later reporting, writing out
FETCH_HEAD, and setting upstream for the current branch, all of
which we should be able to do as long as the primary fetch
successfully finishes, no?
> + }
> + }
> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
> index 300bd5396d..5ba372fbcb 100755
> --- a/t/t5510-fetch.sh
> +++ b/t/t5510-fetch.sh
> @@ -1942,6 +1942,22 @@ test_expect_success "backfill tags when providing a refspec" '
> test_cmp expect actual
> '
>
> +test_expect_success 'shallow fetch does not fetch objects again for tags' '
> + test_when_finished rm -rf source target &&
> +
> + git init source &&
> + test_commit_bulk -C source 10 &&
> + git -C source tag -a tag -m tag HEAD~2 &&
> + root_oid=$(git -C source rev-parse HEAD~9) &&
> +
> + git init target &&
> + git -C target remote add origin ../source &&
> + git -C target fetch --depth 5 origin &&
> +
> + # Should not fetch objects beyond the pre-specified depth.
> + test_must_fail git -C target cat-file -e "$root_oid"
> +'
> +
> test_expect_success REFFILES "FETCH_HEAD is updated even if ref updates fail" '
> test_when_finished rm -rf base repo &&
>
>
> ---
> base-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd
> change-id: 20261007-799-shallow-fetch-with-tags-d62b3efb29f0
>
>
> Thanks
> - Karthik
prev parent reply other threads:[~2026-10-12 19:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 22:10 [PATCH] fetch: commit references fetched before backfilling tags Karthik Nayak
2026-10-09 11:26 ` Patrick Steinhardt
2026-10-09 16:51 ` Justin Tobler
2026-10-09 22:16 ` Karthik Nayak
2026-10-09 22:31 ` Karthik Nayak
2026-10-12 15:29 ` [PATCH v2] " Karthik Nayak
2026-10-12 19:55 ` Junio C Hamano [this message]
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=xmqq4ieq66e8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.com \
--cc=mitja.bezensek@login5.org \
--cc=ps@pks.im \
/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