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

Re: [PATCH v5 09/11] reftable: split up write options

From
Justin Tobler <jltobler@gmail.com>
Date
Jun 24, 2026, 22:06 UTC
Message-ID
<ajxR2fLRsIvNYFtz@denethor>
In-Reply-To
<20260622-b4-pks-refs-avoid-chdir-notify-reparent-v5-9-018475013dbc@pks.im>
On 26/06/22 10:28AM, Patrick Steinhardt wrote:
Show 13 quoted lines
> When initializing the reftable stack the caller may optionally pass some
> write options. These write options mix up two different concerns though:
> 
>   - Of course, they allow the caller to configure how new reftables are
>     being written.
> 
>   - But they also allow the caller to configure the stack itself, like
>     its hash ID and the `on_reload` callback.
> 
> This is somewhat awkward, as it doesn't easily give the caller the
> flexibility to for example write multiple reftables with different
> options. Furthermore, this requires us to eagerly parse relevant
> configuration when initializing the reftable backend.

Naive question: are there any current use cases where callers may want to write multiple reftables with a different set of options? Can reftables written with different options pose any correctness issues?

> Refactor the code by splitting out those options that configure the
> stack itself. Creating a new stack will thus only require this limited
> set of options, whereas the caller is expected to pass write options to
> all functions that end up writing tables.
Splitting this up sounds reasonable.
Show 27 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  refs/reftable-backend.c             |  29 +++---
>  reftable/reftable-stack.h           |  30 +++++-
>  reftable/reftable-writer.h          |  17 +---
>  reftable/stack.c                    | 100 ++++++++++++-------
>  reftable/stack.h                    |   2 +-
>  reftable/writer.c                   |  21 ++--
>  reftable/writer.h                   |   1 +
>  t/helper/test-reftable.c            |   2 +-
>  t/unit-tests/lib-reftable.c         |   8 +-
>  t/unit-tests/lib-reftable.h         |   2 +
>  t/unit-tests/u-reftable-merged.c    |   9 +-
>  t/unit-tests/u-reftable-readwrite.c |  38 ++++++--
>  t/unit-tests/u-reftable-stack.c     | 189 ++++++++++++++++--------------------
>  t/unit-tests/u-reftable-table.c     |   8 +-
>  14 files changed, 258 insertions(+), 198 deletions(-)
> 
> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index 5115a3f4ce..608d71cf10 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -48,9 +48,9 @@ static void reftable_backend_on_reload(void *payload)
>  
>  static int reftable_backend_init(struct reftable_backend *be,
>  				 const char *path,
> -				 const struct reftable_write_options *_opts)

Ok so now during init we only care about `struct reftable_stack_options`. The `struct reftable_write_options` are only needed during reftable writes.

[snip]
Show 17 quoted lines
> +/* Options related to opening a stack. */
> +struct reftable_stack_options {
> +	/*
> +	 * 4-byte identifier ("sha1", "s256") of the hash. Defaults to SHA1 if
> +	 * unset.
> +	 */
> +	enum reftable_hash hash_id;
> +
> +	/*
> +	 * Callback function to execute whenever the stack is being reloaded.
> +	 * This can be used e.g. to discard cached information that relies on
> +	 * the old stack's data. The payload data will be passed as argument to
> +	 * the callback.
> +	 */
> +	void (*on_reload)(void *payload);
> +	void *on_reload_payload;
> +};

These are the options split out from `struct reftable_write_options` and are the options used at initialization and expected to remain consistent across reftable writes. I assume these also won't depend on reading the config prior to the ref store being initialzed.

[snip]
Show 30 quoted lines
> diff --git a/reftable/reftable-writer.h b/reftable/reftable-writer.h
> index a66db415c8..6ff4ddfc60 100644
> --- a/reftable/reftable-writer.h
> +++ b/reftable/reftable-writer.h
> @@ -28,11 +28,6 @@ struct reftable_write_options {
>  	/* how often to write complete keys in each block. */
>  	uint16_t restart_interval;
>  
> -	/* 4-byte identifier ("sha1", "s256") of the hash.
> -	 * Defaults to SHA1 if unset
> -	 */
> -	enum reftable_hash hash_id;
> -
>  	/* Default mode for creating files. If unset, use 0666 (+umask) */
>  	unsigned int default_permissions;
>  
> @@ -60,15 +55,6 @@ struct reftable_write_options {
>  	 * negative value will cause us to block indefinitely.
>  	 */
>  	long lock_timeout_ms;
> -
> -	/*
> -	 * Callback function to execute whenever the stack is being reloaded.
> -	 * This can be used e.g. to discard cached information that relies on
> -	 * the old stack's data. The payload data will be passed as argument to
> -	 * the callback.
> -	 */
> -	void (*on_reload)(void *payload);
> -	void *on_reload_payload;
>  };

These write options are explicitly passed around during write operations. I assume some of these options must be parsed from the config and thus will need to be lazy-loaded to avoid "onbranch" conditions prior to the ref store being initialzed.

The rest of this patch looks to be adjusting call sites to wire these options through as needed and looks correct. I don't see any changes to lazy-load write option configuration yet, but I suppose that will happen in a subsequent patch.

-Justin
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 83 of 88 in “refs: stop using `chdir_notify_reparent()`”
  1. 0/9 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 10, 2026
  2. 1/9 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 10, 2026
  3. 2/9 setup: stop applying repository format twicePatrick Steinhardt, Jun 10, 2026
  4. Karthik NayakJun 12, 2026
  5. Patrick SteinhardtJun 15, 2026
  6. 3/9 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 10, 2026
  7. Junio C HamanoJun 10, 2026
  8. Patrick SteinhardtJun 12, 2026
  9. 4/9 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 10, 2026
  10. Karthik NayakJun 12, 2026
  11. Patrick SteinhardtJun 15, 2026
  12. 5/9 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 10, 2026
  13. 6/9 repository: free main reference databasePatrick Steinhardt, Jun 10, 2026
  14. Karthik NayakJun 12, 2026
  15. 7/9 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 10, 2026
  16. 8/9 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 10, 2026
  17. 9/9 refs: always use absolute paths for reference storesPatrick Steinhardt, Jun 10, 2026
  18. Karthik NayakJun 12, 2026
  19. Patrick SteinhardtJun 15, 2026
  20. Jeff KingJun 11, 2026
  21. Patrick SteinhardtJun 12, 2026
  22. Jeff KingJun 13, 2026
  23. Patrick SteinhardtJun 15, 2026
  24. 0/8 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 15, 2026
  25. 1/8 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 15, 2026
  26. 2/8 setup: stop applying repository format twicePatrick Steinhardt, Jun 15, 2026
  27. Justin ToblerJun 17, 2026
  28. 3/8 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 15, 2026
  29. Justin ToblerJun 17, 2026
  30. Patrick SteinhardtJun 18, 2026
  31. 4/8 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 15, 2026
  32. Justin ToblerJun 17, 2026
  33. Justin ToblerJun 17, 2026
  34. Patrick SteinhardtJun 18, 2026
  35. 5/8 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 15, 2026
  36. 6/8 repository: free main reference databasePatrick Steinhardt, Jun 15, 2026
  37. Justin ToblerJun 17, 2026
  38. 7/8 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 15, 2026
  39. Justin ToblerJun 17, 2026
  40. Patrick SteinhardtJun 18, 2026
  41. Justin ToblerJun 18, 2026
  42. Patrick SteinhardtJun 18, 2026
  43. Justin ToblerJun 18, 2026
  44. Jeff KingJun 18, 2026
  45. Patrick SteinhardtJun 19, 2026
  46. Jeff KingJun 21, 2026
  47. Patrick SteinhardtJun 22, 2026
  48. 8/8 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 15, 2026
  49. 0/8 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 18, 2026
  50. 1/8 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 18, 2026
  51. 2/8 setup: stop applying repository format twicePatrick Steinhardt, Jun 18, 2026
  52. 3/8 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 18, 2026
  53. 4/8 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 18, 2026
  54. 5/8 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 18, 2026
  55. 6/8 repository: free main reference databasePatrick Steinhardt, Jun 18, 2026
  56. 7/8 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 18, 2026
  57. 8/8 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 18, 2026
  58. 00/10 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 19, 2026
  59. 01/10 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 19, 2026
  60. 02/10 setup: stop applying repository format twicePatrick Steinhardt, Jun 19, 2026
  61. 03/10 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 19, 2026
  62. 04/10 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 19, 2026
  63. 05/10 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 19, 2026
  64. 06/10 repository: free main reference databasePatrick Steinhardt, Jun 19, 2026
  65. 07/10 refs: move parsing of "core.logAllRefUpdates" back into ref storesPatrick Steinhardt, Jun 19, 2026
  66. 08/10 refs/reftable-backend: manually parse "core.sharedRepository"Patrick Steinhardt, Jun 19, 2026
  67. 09/10 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 19, 2026
  68. 10/10 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 19, 2026
  69. 00/11 refs: fix "onbranch" conditionsPatrick Steinhardt, Jun 22, 2026
  70. 01/11 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 22, 2026
  71. 02/11 setup: stop applying repository format twicePatrick Steinhardt, Jun 22, 2026
  72. 03/11 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 22, 2026
  73. 04/11 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 22, 2026
  74. 05/11 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 22, 2026
  75. 06/11 repository: free main reference databasePatrick Steinhardt, Jun 22, 2026
  76. 07/11 refs: move parsing of "core.logAllRefUpdates" back into ref storesPatrick Steinhardt, Jun 22, 2026
  77. Justin ToblerJun 24, 2026
  78. Patrick SteinhardtJun 25, 2026
  79. 08/11 refs/files: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 22, 2026
  80. Justin ToblerJun 24, 2026
  81. Patrick SteinhardtJun 25, 2026
  82. 09/11 reftable: split up write optionsPatrick Steinhardt, Jun 22, 2026
  83. Justin ToblerJun 24, 2026
  84. Patrick SteinhardtJun 25, 2026
  85. 10/11 refs/reftable: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 22, 2026
  86. Justin ToblerJun 24, 2026
  87. Patrick SteinhardtJun 25, 2026
  88. 11/11 refs: protect against chicken-and-egg recursionPatrick Steinhardt, Jun 22, 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.