Re: [PATCH v2 5/6] reftable/stack: allow passing flags to `reftable_stack_add()`
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Aug 11, 2025, 19:34 UTC
- Message-ID
- <6gcuu35ey34nrxtsgpelfykvgxo7vqqhgsq3obnbducmplaymv@blgaxqyp6low>
- In-Reply-To
- <20250804-pks-reftable-fixes-for-libgit2-v2-5-fef06209a984@pks.im>
On 25/08/04 11:40AM, Patrick Steinhardt wrote:
Show 19 quoted lines
> The `reftable_stack_add()` function is a simple wrapper to lock the > stack, add records to it via a callback and then commit the > result. One problem with it though is that it doesn't accept any flags > for creating the addition. This makes it impossible to automatically > reload the stack in case it was modified before we managed to lock the > stack. > > Add a `flags` field to plug this gap and pass it through accordingly. > For now this new flag won't be used by us, but it will be used by > libgit2. > > Signed-off-by: Patrick Steinhardt <ps@pks.im> > --- > refs/reftable-backend.c | 8 +++---- > reftable/reftable-stack.h | 9 +++++--- > reftable/stack.c | 8 +++---- > t/unit-tests/t-reftable-stack.c | 50 ++++++++++++++++++++--------------------- > 4 files changed, 39 insertions(+), 36 deletions(-) >
[snip]
Show 37 quoted lines
> diff --git a/reftable/reftable-stack.h b/reftable/reftable-stack.h
> index 910ec6ef3a2..d70fcb705dc 100644
> --- a/reftable/reftable-stack.h
> +++ b/reftable/reftable-stack.h
> @@ -68,12 +68,15 @@ int reftable_addition_commit(struct reftable_addition *add);
> * transaction. Releases the lock if held. */
> void reftable_addition_destroy(struct reftable_addition *add);
>
> -/* add a new table to the stack. The write_table function must call
> - * reftable_writer_set_limits, add refs and return an error value. */
> +/*
> + * Add a new table to the stack. The write_table function must call
> + * reftable_writer_set_limits, add refs and return an error value.
> + * The flags are passed through to `reftable_stack_new_addition()`.
> + */
> int reftable_stack_add(struct reftable_stack *st,
> int (*write_table)(struct reftable_writer *wr,
> void *write_arg),
> - void *write_arg);
> + void *write_arg, unsigned flags);
>
> struct reftable_iterator;
>
> diff --git a/reftable/stack.c b/reftable/stack.c
> index d6e4ea93a37..f77d7f58e8e 100644
> --- a/reftable/stack.c
> +++ b/reftable/stack.c
> @@ -737,10 +737,10 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
> static int stack_try_add(struct reftable_stack *st,
> int (*write_table)(struct reftable_writer *wr,
> void *arg),
> - void *arg)
> + void *arg, unsigned flags)
> {
> struct reftable_addition add = REFTABLE_ADDITION_INIT;
> - int err = reftable_stack_init_addition(&add, st, 0);
> + int err = reftable_stack_init_addition(&add, st, flags);Ok, so now if the `REFTABLE_STACK_NEW_ADDITION_RELOAD` flag is provided, reftable_stack_init_addition() will attempt to reload the stack if it is outdated before locking the stack. I assume Git itself hasn't needed this because it just uses reftable_stack_new_addition() directly when neccessary.
This patch looks good.
-Justin