Re: [PATCH v6 4/6] refs: move out stub modification to generic layer
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Feb 17, 2026, 07:24 UTC
- Message-ID
- <aZQXpb7RMW83eGxe@pks.im>
- In-Reply-To
- <20260214-kn-alternate-ref-dir-v6-4-86a82c77cf59@gmail.com>
On Sat, Feb 14, 2026 at 11:34:17PM +0100, Karthik Nayak wrote:
Show 11 quoted lines
> When creating the reftable reference backend on disk, we create stubs to > ensure that the directory can be recognized as a Git repository. This is > done by calling `refs_create_refdir_stubs()`. Move this to the generic > layer as this is needed for all backends excluding from the files > backends. In an upcoming commit, we'll also need to extend this logic to > create stubs when using alternate reference directories. > > Similarly, move the logic for deletion of stubs to the generic layer. > The files backend recursively calls the remove function of the > 'packed-backend', here skip calling the generic function since that > would try to delete stubs.
Tiniest nit: it might make sense to reorder patches a bit so that the creation of `refs_create_refdir_stubs()` and this patch here sit next to each other.
What's missing a bit in the commit message is the motivation. What does this step enable us to do that we couldn't do before?
Show 22 quoted lines
> diff --git a/refs.c b/refs.c
> index 11d028232b..a24602c9bf 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2190,12 +2190,59 @@ void refs_create_refdir_stubs(struct repository *repo, const char *refdir,
> /* backend functions */
> int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *err)
> {
> - return refs->be->create_on_disk(refs, flags, err);
> + int ret = refs->be->create_on_disk(refs, flags, err);
> +
> + if (!ret &&
> + ref_storage_format_by_name(refs->be->name) != REF_STORAGE_FORMAT_FILES) {
> + struct strbuf msg = STRBUF_INIT;
> +
> + strbuf_addf(&msg, "this repository uses the %s format", refs->be->name);
> + refs_create_refdir_stubs(refs->repo, refs->gitdir, msg.buf);
> + strbuf_release(&msg);
> + }
> +
> + return ret;
> }This makes me wonder: if we called `refs_create_refdir_stubs()` before we call `->create_on_disk()`, could we even do it for the "files" backend? Just a thought though.
Show 12 quoted lines
> int ref_store_remove_on_disk(struct ref_store *refs, struct strbuf *err)
> {
> - return refs->be->remove_on_disk(refs, err);
> + int ret = refs->be->remove_on_disk(refs, err);
> +
> + if (!ret) {
> + enum ref_storage_format format = ref_storage_format_by_name(refs->be->name);
> + struct strbuf sb = STRBUF_INIT;
> +
> + /* Backends apart from the files backend create stubs. */
> + if (format == REF_STORAGE_FORMAT_FILES)
> + return ret;For symmetry it would be nice to not have an early return here, but also format the condition for this block in the same way as we have it for `ref_store_create_on_disk()`.
Patrick