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

Re: [PATCH 04/10] packed_delete_refs(): implement method

From
BWBrandon Williams <bmwill@google.com>
Date
Aug 29, 2017, 18:07 UTC
Message-ID
<20170829180732.GA131745@google.com>
In-Reply-To
<7c61f04574e32d6172062a6a8ffa8ade5c90bb1d.1503993268.git.mhagger@alum.mit.edu>
On 08/29, Michael Haggerty wrote:
Show 41 quoted lines
> Implement `packed_delete_refs()` using a reference transaction. This
> means that `files_delete_refs()` can use `refs_delete_refs()` instead
> of `repack_without_refs()` to delete any packed references, decreasing
> the coupling between the classes.
> 
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
>  refs/files-backend.c  |  2 +-
>  refs/packed-backend.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index fccbc24ac4..2c78f63494 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -1157,7 +1157,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
>  	if (packed_refs_lock(refs->packed_ref_store, 0, &err))
>  		goto error;
>  
> -	if (repack_without_refs(refs->packed_ref_store, refnames, &err)) {
> +	if (refs_delete_refs(refs->packed_ref_store, msg, refnames, flags)) {
>  		packed_refs_unlock(refs->packed_ref_store);
>  		goto error;
>  	}
> diff --git a/refs/packed-backend.c b/refs/packed-backend.c
> index d19b3bfba5..83a088118f 100644
> --- a/refs/packed-backend.c
> +++ b/refs/packed-backend.c
> @@ -1082,7 +1082,50 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store,
>  static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
>  			     struct string_list *refnames, unsigned int flags)
>  {
> -	die("BUG: not implemented yet");
> +	struct packed_ref_store *refs =
> +		packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
> +	struct strbuf err = STRBUF_INIT;
> +	struct ref_transaction *transaction;
> +	struct string_list_item *item;
> +	int ret;
> +
> +	(void)refs; /* We need the check above, but don't use the variable */

Can't say I've seen a line like this before, Is the intent to just mark that this variable won't be used like you mention in the comment?

Show 42 quoted lines
> +
> +	if (!refnames->nr)
> +		return 0;
> +
> +	/*
> +	 * Since we don't check the references' old_oids, the
> +	 * individual updates can't fail, so we can pack all of the
> +	 * updates into a single transaction.
> +	 */
> +
> +	transaction = ref_store_transaction_begin(ref_store, &err);
> +	if (!transaction)
> +		return -1;
> +
> +	for_each_string_list_item(item, refnames) {
> +		if (ref_transaction_delete(transaction, item->string, NULL,
> +					   flags, msg, &err)) {
> +			warning(_("could not delete reference %s: %s"),
> +				item->string, err.buf);
> +			strbuf_reset(&err);
> +		}
> +	}
> +
> +	ret = ref_transaction_commit(transaction, &err);
> +
> +	if (ret) {
> +		if (refnames->nr == 1)
> +			error(_("could not delete reference %s: %s"),
> +			      refnames->items[0].string, err.buf);
> +		else
> +			error(_("could not delete references: %s"), err.buf);
> +	}
> +
> +	ref_transaction_free(transaction);
> +	strbuf_release(&err);
> +	return ret;
>  }
>  
>  static int packed_pack_refs(struct ref_store *ref_store, unsigned int flags)
> -- 
> 2.14.1
> 
-- 
Brandon Williams
Previous: Michael HaggertyNext: Michael Haggerty
Message 4 of 31 in “Implement transactions for the packed ref store”
  1. 00/10 Implement transactions for the packed ref storeMichael Haggerty, Aug 29, 2017
  2. 05/10 files_pack_refs(): use a reference transaction to write packed refsMichael Haggerty, Aug 29, 2017
  3. 04/10 packed_delete_refs(): implement methodMichael Haggerty, Aug 29, 2017
  4. Brandon WilliamsAug 29, 2017
  5. Michael HaggertyAug 30, 2017
  6. 06/10 files_initial_transaction_commit(): use a transaction for packed refsMichael Haggerty, Aug 29, 2017
  7. Jeff KingSep 8, 2017
  8. Michael HaggertySep 8, 2017
  9. 07/10 t1404: demonstrate two problems with reference transactionsMichael Haggerty, Aug 29, 2017
  10. Stefan BellerAug 30, 2017
  11. Michael HaggertyAug 31, 2017
  12. Junio C HamanoSep 8, 2017
  13. Jeff KingSep 8, 2017
  14. Michael HaggertySep 8, 2017
  15. 09/10 packed-backend: rip out some now-unused codeMichael Haggerty, Aug 29, 2017
  16. Brandon WilliamsAug 29, 2017
  17. 08/10 files_ref_store: use a transaction to update packed refsMichael Haggerty, Aug 29, 2017
  18. Jeff KingSep 8, 2017
  19. Michael HaggertySep 8, 2017
  20. Jeff KingSep 8, 2017
  21. 10/10 files_transaction_finish(): delete reflogs before referencesMichael Haggerty, Aug 29, 2017
  22. 01/10 packed-backend: don't adjust the reference count on lock/unlockMichael Haggerty, Aug 29, 2017
  23. Jeff KingSep 8, 2017
  24. Michael HaggertySep 8, 2017
  25. 02/10 struct ref_transaction: add a place for backends to store dataMichael Haggerty, Aug 29, 2017
  26. Jeff KingSep 8, 2017
  27. Michael HaggertySep 8, 2017
  28. Jeff KingSep 8, 2017
  29. 03/10 packed_ref_store: implement reference transactionsMichael Haggerty, Aug 29, 2017
  30. Brandon WilliamsAug 29, 2017
  31. Jeff KingSep 8, 2017

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.