git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] fetch: commit references fetched before backfilling tags

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 21, 2026, 10:05 UTC
Message-ID
<CAOLa=ZR-mg6ah4VwStR3SJvT1uWdW5uv7q9x486FN7UawkJYeg@mail.gmail.com>
In-Reply-To
<atftdOihoUHTdvfu@denethor>
Justin Tobler <jltobler@gmail.com> writes:
Show 24 quoted lines
> On 26/10/15 11:24PM, Karthik Nayak wrote:
>> In 0e358de64a (fetch: use batched reference updates, 2025-05-19), the
>> fetch code was modified to use batched updates to provide a good
>> performance improvement. Batched updates are used both for the fetched
>> references and to backfill tags.
>>
>> 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 newly fetched refs
>> are not available for advertisement in the 'haves' section. This can
>> cause the server to send all objects the client already has.
>
> Ok, without the earlier fetched references committed, the backfill fetch
> may ultimately ask for objects it already got. Make sense.
>
>> The issue always existed when the '--atomic' flag was used, as both the
>> regular ref updates and the tags need to be part of the same
>> transaction.
>
> So IIUC, you are saying that this problem already existed prior to
> 0e358de64a, but only for atomic fetches. Furthermore, this patch doesn't
> fix anything for atomic fetches as they can only use a single
> transaction.
>

Yup, there's nothing we can do for atomic fetches with the current approach.

Show 17 quoted lines
>> Fix this by committing the previous batched update and initiating a new
>> one for backfilling tags. Use a separate error variable for tracking the
>> reference updates: One, it ensures that errors from the regular ref
>> updates don't cause a total failure. Two, if starting the transaction
>> for backfilling tags fails, only those updates are not made to disk. The
>> initial error is now printed straight away to clear the buffer for
>> further errors.
>
> Naively, I think it would be nice if it were possible supplement the
> backfill fetch "haves" with the non-committed references in the pending
> transaction directly. That would avoid having to commit the references
> in the middle and probably also fix it for atomic fetches too, but I'm
> uncertain if that would be a simple or reasonable thing to do.
>
> Committing the intermediate state here does in part fix the issue, so it
> may be a good first step regardless.
>
I've replied to this with Patrick's email, let's continue there.
[snip]
Show 35 quoted lines
>> diff --git a/builtin/fetch.c b/builtin/fetch.c
>> index b2decc6cfd..34fc37b58a 100644
>> --- a/builtin/fetch.c
>> +++ b/builtin/fetch.c
>> @@ -1923,6 +1923,7 @@ static int do_fetch(struct transport *transport,
>>  	struct strmap rejected_refs = STRMAP_INIT;
>>  	int summary_width = 0;
>>  	int follow_remote_head;
>> +	int commit_ref_ret = 0;
>>
>>  	if (tags == TAGS_DEFAULT) {
>>  		if (transport->remote->fetch_tags == 2)
>> @@ -2076,6 +2077,30 @@ 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);
>> +
>> +		/*
>> +		 * As negotiation only reads references from disk, commit the references
>> +		 * fetched so far, so that the backfill negotiation can advertise them as
>> +		 * 'have's. Otherwise the server may re-send objects.
>> +		 */
>> +		if (tags_ref_map && !atomic_fetch) {
>> +			commit_ref_ret = commit_ref_transaction(&transaction, false,
>> +								transport->remote->name,
>> +								&rejected_refs, &err);
>> +			if (err.len) {
>> +				error("%s", err.buf);
>> +				strbuf_reset(&err);
>> +			}
>
> It looks like we log the error and continue even if committing the
> transaction failed. Is there a reason we would want to still try to
> start the next transaction?
>

Since we use batched updates, some refs could fail, but we continue as we may have still applied some updates and we can continue doing the rest of the work.

Show 36 quoted lines
>> +
>> +			transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
>> +								  REF_TRANSACTION_ALLOW_FAILURE, &err);
>> +			if (!transaction) {
>> +				free_refs(tags_ref_map);
>> +				tags_ref_map = NULL;
>> +				commit_ref_ret = -1;
>> +			}
>> +		}
>> +
>>  		if (tags_ref_map) {
>>  			/*
>>  			 * If backfilling of tags fails then we want to tell
>> @@ -2099,9 +2124,16 @@ static int do_fetch(struct transport *transport,
>>  	if (verbosity >= 0)
>>  		summary_width = transport_summary_width(ref_map);
>>
>> -	retcode = commit_ref_transaction(&transaction, atomic_fetch,
>> -					 transport->remote->name,
>> -					 &rejected_refs, &err);
>> +	/*
>> +	 * The transaction may have failed to initialize, meaning there is nothing
>> +	 * to commit. Carry forward with other operations in such cases.
>> +	 */
>> +	if (transaction)
>> +		retcode = commit_ref_transaction(&transaction, atomic_fetch,
>> +						 transport->remote->name,
>> +						 &rejected_refs, &err);
>> +	retcode |= commit_ref_ret;
>
> hmmm, the error paths here are confusing me a bit. If the transaction
> failed to be created in the first place, wouldn't we want to stop
> earlier on?
>
> Thanks,
> -Justin

Not really, since we use batched updates, the backfilling tags transaction could fail to initialize but we still want to set upstreams and set HEAD.

Previous: Karthik NayakNext: Karthik Nayak
Message 15 of 36 in “fetch: commit references fetched before backfilling tags”
  1. fetch: commit references fetched before backfilling tagsKarthik Nayak, Oct 8, 2026
  2. Patrick SteinhardtOct 9, 2026
  3. Justin ToblerOct 9, 2026
  4. Karthik NayakOct 9, 2026
  5. Karthik NayakOct 9, 2026
  6. fetch: commit references fetched before backfilling tagsKarthik Nayak, Oct 12, 2026
  7. Junio C HamanoOct 12, 2026
  8. Karthik NayakOct 15, 2026
  9. fetch: commit references fetched before backfilling tagsKarthik Nayak, Oct 15, 2026
  10. Justin ToblerOct 20, 2026
  11. Patrick SteinhardtOct 21, 2026
  12. Karthik NayakOct 21, 2026
  13. Justin ToblerOct 21, 2026
  14. Karthik NayakOct 22, 2026
  15. Karthik NayakOct 21, 2026
  16. fetch: advertise fetched refs when backfilling tagsKarthik Nayak, Oct 22, 2026
  17. Patrick SteinhardtOct 23, 2026
  18. Karthik NayakOct 23, 2026
  19. Patrick SteinhardtOct 23, 2026
  20. Karthik NayakOct 23, 2026
  21. Karthik NayakOct 23, 2026
  22. 0/3 fetch: advertise fetched refs when backfilling tagsKarthik Nayak, Oct 28, 2026
  23. 1/3 transport: add `transport_options_release()`Karthik Nayak, Oct 28, 2026
  24. Patrick SteinhardtOct 28, 2026
  25. Karthik NayakOct 28, 2026
  26. Patrick SteinhardtOct 29, 2026
  27. Karthik NayakOct 29, 2026
  28. 2/3 fetch: advertise fetched refs when backfilling tagsKarthik Nayak, Oct 28, 2026
  29. 3/3 t5510: cover upstream info update on fetch failureKarthik Nayak, Oct 28, 2026
  30. Patrick SteinhardtOct 28, 2026
  31. Karthik NayakOct 28, 2026
  32. 0/3 fetch: advertise fetched refs when backfilling tagsKarthik Nayak, Oct 29, 2026
  33. 1/3 t5510: cover upstream info update on fetch failureKarthik Nayak, Oct 29, 2026
  34. 2/3 transport: add `transport_options_release()`Karthik Nayak, Oct 29, 2026
  35. 3/3 fetch: advertise fetched refs when backfilling tagsKarthik Nayak, Oct 29, 2026
  36. Patrick SteinhardtOct 29, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.