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

Re: [PATCH v4 6/8] refs: implement batch reference update support

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 20, 2025, 20:26 UTC
Message-ID
<Z9x590KcwP8WGGG-@pks.im>
In-Reply-To
<20250320-245-partially-atomic-ref-updates-v4-6-3dcc1b311dc9@gmail.com>
On Thu, Mar 20, 2025 at 12:44:01PM +0100, Karthik Nayak wrote:
Show 46 quoted lines
> diff --git a/refs.c b/refs.c
> index 3d0b53d56e..b34ec198f5 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1206,11 +1210,45 @@ void ref_transaction_free(struct ref_transaction *transaction)
>  		free((char *)transaction->updates[i]->old_target);
>  		free(transaction->updates[i]);
>  	}
> +
> +	if (transaction->rejections)
> +		free(transaction->rejections->update_indices);
> +	free(transaction->rejections);
> +
>  	string_list_clear(&transaction->refnames, 0);
>  	free(transaction->updates);
>  	free(transaction);
>  }
>  
> +int ref_transaction_maybe_set_rejected(struct ref_transaction *transaction,
> +				       size_t update_idx,
> +				       enum ref_transaction_error err)
> +{
> +	if (update_idx >= transaction->nr)
> +		BUG("trying to set rejection on invalid update index");
> +
> +	if (!(transaction->flags & REF_TRANSACTION_ALLOW_FAILURE))
> +		return 0;
> +
> +	if (!transaction->rejections)
> +		BUG("transaction not inititalized with failure support");
> +
> +	/*
> +	 * Don't accept generic errors, since these errors are not user
> +	 * input related.
> +	 */
> +	if (err == REF_TRANSACTION_ERROR_GENERIC)
> +		return 0;
> +
> +	transaction->updates[update_idx]->rejection_err = err;
> +	ALLOC_GROW(transaction->rejections->update_indices,
> +		   transaction->rejections->nr + 1,
> +		   transaction->rejections->alloc);
> +	transaction->rejections->update_indices[transaction->rejections->nr++] = update_idx;
> +
> +	return 1;
> +}

If we had a `struct ref_update_rejection` we could store the update index and rejection errors in the same location, which might be a bit easier to reason about.

Show 24 quoted lines
> diff --git a/refs/packed-backend.c b/refs/packed-backend.c
> index d90bd815a3..7bf57ca948 100644
> --- a/refs/packed-backend.c
> +++ b/refs/packed-backend.c
> @@ -1327,10 +1327,11 @@ static int packed_ref_store_remove_on_disk(struct ref_store *ref_store,
>   * remain locked when it is done.
>   */
>  static enum ref_transaction_error write_with_updates(struct packed_ref_store *refs,
> -						     struct string_list *updates,
> +						     struct ref_transaction *transaction,
>  						     struct strbuf *err)
>  {
>  	enum ref_transaction_error ret = REF_TRANSACTION_ERROR_GENERIC;
> +	struct string_list *updates = &transaction->refnames;
>  	struct ref_iterator *iter = NULL;
>  	size_t i;
>  	int ok;
> @@ -1411,6 +1412,13 @@ static enum ref_transaction_error write_with_updates(struct packed_ref_store *re
>  						    "reference already exists",
>  						    update->refname);
>  					ret = REF_TRANSACTION_ERROR_CREATE_EXISTS;
> +
> +					if (ref_transaction_maybe_set_rejected(transaction, i, ret)) {
> +						strbuf_setlen(err, 0);
Nit: you can use `strbuf_reset()` for this and other instances.
Patrick
Previous: Karthik NayakNext: Karthik Nayak
Message 7 of 19 in “refs: introduce support for batched reference updates”
  1. 0/8 refs: introduce support for batched reference updatesKarthik Nayak, Mar 20, 2025
  2. 1/8 refs/files: remove redundant check in split_symref_update()Karthik Nayak, Mar 20, 2025
  3. 2/8 refs: move duplicate refname update check to generic layerKarthik Nayak, Mar 20, 2025
  4. 3/8 refs/files: remove duplicate duplicates checkKarthik Nayak, Mar 20, 2025
  5. 4/8 refs/reftable: extract code from the transaction preparationKarthik Nayak, Mar 20, 2025
  6. 6/8 refs: implement batch reference update supportKarthik Nayak, Mar 20, 2025
  7. Patrick SteinhardtMar 20, 2025
  8. Karthik NayakMar 24, 2025
  9. 5/8 refs: introduce enum-based transaction error typesKarthik Nayak, Mar 20, 2025
  10. Patrick SteinhardtMar 20, 2025
  11. Karthik NayakMar 24, 2025
  12. Patrick SteinhardtMar 25, 2025
  13. 7/8 refs: support rejection in batch updates during F/D checksKarthik Nayak, Mar 20, 2025
  14. Patrick SteinhardtMar 24, 2025
  15. Karthik NayakMar 24, 2025
  16. Patrick SteinhardtMar 25, 2025
  17. 8/8 update-ref: add --batch-updates flag for stdin modeKarthik Nayak, Mar 20, 2025
  18. Patrick SteinhardtMar 24, 2025
  19. Karthik NayakMar 24, 2025

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.