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

Re: [PATCH 34/38] refs: add method for delete_refs

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 7, 2016, 17:43 UTC
Message-ID
<xmqqporsrj21.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<17da5760ac671c98811cc5a3ec46a61f8261d8d9.1464983301.git.mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 16 quoted lines
> From: David Turner <dturner@twopensource.com>
>
> In the file-based backend, delete_refs has some special optimization
> to deal with packed refs.  In other backends, we might be able to make
> ref deletion faster by putting all deletions into a single
> transaction.  So we need a special backend function for this.
>
> Signed-off-by: David Turner <dturner@twopensource.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
> I think that we could get away without this method if we make
> ref_transactions a bit smarter (for example, by supporting best-effort
> updates that can fail without causing the entire transaction to be
> aborted). But that would be a significant detour, so let's leave it
> here for now.

Hmm, I actually was wondering why 'pack without' was there while reading 24/38; IIUC, that is one of the "special optimization" that is very much tied to the files backend, and it may make sense to hide it behind delete_refs() as its implementation detail.

Which is exactly what this step is about, so I am happy ;-)

Unlike other changes like the ones that did read_raw_ref(), verify_refname_available(), etc., the title does not follow the pattern "refs: make X() virtual", even though as far as I can see the intent is the same as others. Perhaps a minor retitle is in order?

Show 67 quoted lines
>  refs.c               | 7 +++++++
>  refs/files-backend.c | 6 ++++--
>  refs/refs-internal.h | 3 +++
>  3 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index 6c1e899..8ab9862 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1529,3 +1529,10 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
>  
>  	return refs->be->initial_transaction_commit(refs, transaction, err);
>  }
> +
> +int delete_refs(struct string_list *refnames, unsigned int flags)
> +{
> +	struct ref_store *refs = get_ref_store(NULL);
> +
> +	return refs->be->delete_refs(refs, refnames, flags);
> +}
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 253899f..5681141 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -2455,10 +2455,11 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
>  	return 0;
>  }
>  
> -int delete_refs(struct string_list *refnames, unsigned int flags)
> +static int files_delete_refs(struct ref_store *ref_store,
> +			     struct string_list *refnames, unsigned int flags)
>  {
>  	struct files_ref_store *refs =
> -		get_files_ref_store(NULL, "delete_refs");
> +		files_downcast(ref_store, 0, "delete_refs");
>  	struct strbuf err = STRBUF_INIT;
>  	int i, result = 0;
>  
> @@ -4070,6 +4071,7 @@ struct ref_storage_be refs_be_files = {
>  	files_pack_refs,
>  	files_peel_ref,
>  	files_create_symref,
> +	files_delete_refs,
>  
>  	files_ref_iterator_begin,
>  	files_read_raw_ref,
> diff --git a/refs/refs-internal.h b/refs/refs-internal.h
> index e462b54..f944b7a 100644
> --- a/refs/refs-internal.h
> +++ b/refs/refs-internal.h
> @@ -485,6 +485,8 @@ typedef int create_symref_fn(struct ref_store *ref_store,
>  			     const char *ref_target,
>  			     const char *refs_heads_master,
>  			     const char *logmsg);
> +typedef int delete_refs_fn(struct ref_store *ref_store,
> +			   struct string_list *refnames, unsigned int flags);
>  
>  /*
>   * Iterate over the references in the specified ref_store that are
> @@ -582,6 +584,7 @@ struct ref_storage_be {
>  	pack_refs_fn *pack_refs;
>  	peel_ref_fn *peel_ref;
>  	create_symref_fn *create_symref;
> +	delete_refs_fn *delete_refs;
>  
>  	ref_iterator_begin_fn *iterator_begin;
>  	read_raw_ref_fn *read_raw_ref;
Previous: Michael HaggertyNext: Michael Haggerty
Message 57 of 67 in “Virtualization of the refs API”
  1. 00/38 Virtualization of the refs APIMichael Haggerty, Jun 3, 2016
  2. 01/38 resolve_gitlink_ref(): eliminate temporary variableMichael Haggerty, Jun 3, 2016
  3. 02/38 rename_ref_available(): add docstringMichael Haggerty, Jun 3, 2016
  4. Junio C HamanoJun 7, 2016
  5. Michael HaggertyJun 9, 2016
  6. Junio C HamanoJun 9, 2016
  7. 03/38 refs: rename struct ref_cache to files_ref_storeMichael Haggerty, Jun 3, 2016
  8. 04/38 refs: add a backend method structureMichael Haggerty, Jun 3, 2016
  9. 05/38 refs: create a base class "ref_store" for files_ref_storeMichael Haggerty, Jun 3, 2016
  10. Junio C HamanoJun 7, 2016
  11. René ScharfeJun 9, 2016
  12. Junio C HamanoJun 7, 2016
  13. Michael HaggertyJun 9, 2016
  14. Junio C HamanoJun 9, 2016
  15. Michael HaggertyJun 10, 2016
  16. Junio C HamanoJun 10, 2016
  17. Eric SunshineJun 10, 2016
  18. Michael HaggertyJun 10, 2016
  19. 06/38 add_packed_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  20. 07/38 get_packed_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  21. 08/38 resolve_missing_loose_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  22. 09/38 {lock,commit,rollback}_packed_refs(): add files_ref_store argumentsMichael Haggerty, Jun 3, 2016
  23. 10/38 refs: add a transaction_commit() methodMichael Haggerty, Jun 3, 2016
  24. 11/38 refs: reorder definitionsMichael Haggerty, Jun 3, 2016
  25. 12/38 resolve_packed_ref(): rename function from resolve_missing_loose_ref()Michael Haggerty, Jun 3, 2016
  26. 13/38 resolve_gitlink_packed_ref(): remove functionMichael Haggerty, Jun 3, 2016
  27. 14/38 read_raw_ref(): take a (struct ref_store *) argumentMichael Haggerty, Jun 3, 2016
  28. 15/38 resolve_ref_recursively(): new functionMichael Haggerty, Jun 3, 2016
  29. 16/38 resolve_gitlink_ref(): implement using resolve_ref_recursively()Michael Haggerty, Jun 3, 2016
  30. Junio C HamanoJun 7, 2016
  31. Eric SunshineJun 14, 2016
  32. Michael HaggertyJun 16, 2016
  33. 17/38 resolve_gitlink_ref(): avoid memory allocation in many casesMichael Haggerty, Jun 3, 2016
  34. Junio C HamanoJun 7, 2016
  35. Michael HaggertyJun 9, 2016
  36. 18/38 resolve_gitlink_ref(): rename path parameter to submoduleMichael Haggerty, Jun 3, 2016
  37. 19/38 refs: make read_raw_ref() virtualMichael Haggerty, Jun 3, 2016
  38. 20/38 refs: make verify_refname_available() virtualMichael Haggerty, Jun 3, 2016
  39. 21/38 refs: make pack_refs() virtualMichael Haggerty, Jun 3, 2016
  40. Junio C HamanoJun 7, 2016
  41. Michael HaggertyJun 9, 2016
  42. 22/38 refs: make create_symref() virtualMichael Haggerty, Jun 3, 2016
  43. 23/38 refs: make peel_ref() virtualMichael Haggerty, Jun 3, 2016
  44. Junio C HamanoJun 7, 2016
  45. Michael HaggertyJun 9, 2016
  46. 24/38 repack_without_refs(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  47. 25/38 lock_raw_ref(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  48. 26/38 commit_ref_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  49. 27/38 lock_ref_for_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  50. 28/38 lock_ref_sha1_basic(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  51. 29/38 split_symref_update(): add a files_ref_store argumentMichael Haggerty, Jun 3, 2016
  52. 30/38 files_ref_iterator_begin(): take a ref_store argumentMichael Haggerty, Jun 3, 2016
  53. 31/38 refs: add method iterator_beginMichael Haggerty, Jun 3, 2016
  54. 32/38 refs: add methods for reflogMichael Haggerty, Jun 3, 2016
  55. 33/38 refs: add method for initial ref transaction commitMichael Haggerty, Jun 3, 2016
  56. 34/38 refs: add method for delete_refsMichael Haggerty, Jun 3, 2016
  57. Junio C HamanoJun 7, 2016
  58. Michael HaggertyJun 9, 2016
  59. 35/38 refs: add methods to init refs dbMichael Haggerty, Jun 3, 2016
  60. 36/38 refs: add method to rename refsMichael Haggerty, Jun 3, 2016
  61. 37/38 refs: make lock genericMichael Haggerty, Jun 3, 2016
  62. Junio C HamanoJun 7, 2016
  63. Michael HaggertyJun 9, 2016
  64. Michael HaggertyJun 9, 2016
  65. 38/38 refs: implement iteration over only per-worktree refsMichael Haggerty, Jun 3, 2016
  66. Duy NguyenJul 10, 2016
  67. Michael HaggertyJul 13, 2016

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.