refs: introduce `ref_store_init_options`

Reference backends are initiated via the `init()` function. When initiating the function, the backend is also provided flags which denote the access levels of the initiator. Create a new structure `ref_store_init_options` to house such options and move the access flags to this structure. This allows easier extension of providing further options to the backends. In the following commit, we'll also provide config around reflog creation to the backends via the same structure. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed May 4, 2026 at 19:44 UTC d194dffcfd3ad26105149f8e0fbd3b6537bf1986
6 files changed +26 -10
refs.c
+5 -1
@@ -2295,6 +2295,9 @@ static struct ref_store *ref_store_init(struct repository *repo,
2295 {
2296 const struct ref_storage_be *be;
2297 struct ref_store *refs;
2298 + struct ref_store_init_options opts = {
2299 + .access_flags = flags,
2300 + };
2301
2302 be = find_ref_storage_backend(format);
2303 if (!be)
@@ -2304,7 +2307,8 @@ static struct ref_store *ref_store_init(struct repository *repo,
2307 * TODO Send in a 'struct worktree' instead of a 'gitdir', and
2308 * allow the backend to handle how it wants to deal with worktrees.
2309 */
2307 - refs = be->init(repo, repo->ref_storage_payload, gitdir, flags);
2310 + refs = be->init(repo, repo->ref_storage_payload, gitdir, &opts);
2311 +
2312 return refs;
2313 }
2314
refs/files-backend.c
+5 -3
@@ -108,7 +108,7 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
108 static struct ref_store *files_ref_store_init(struct repository *repo,
109 const char *payload,
110 const char *gitdir,
111 - unsigned int flags)
111 + const struct ref_store_init_options *opts)
112 {
113 struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
114 struct ref_store *ref_store = (struct ref_store *)refs;
@@ -120,11 +120,13 @@ static struct ref_store *files_ref_store_init(struct repository *repo,
120 &ref_common_dir);
121
122 base_ref_store_init(ref_store, repo, refdir.buf, &refs_be_files);
123 - refs->store_flags = flags;
123 +
124 refs->gitcommondir = strbuf_detach(&ref_common_dir, NULL);
125 refs->packed_ref_store =
126 - packed_ref_store_init(repo, NULL, refs->gitcommondir, flags);
126 + packed_ref_store_init(repo, NULL, refs->gitcommondir, opts);
127 + refs->store_flags = opts->access_flags;
128 refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
129 +
130 repo_config_get_bool(repo, "core.prefersymlinkrefs", &refs->prefer_symlink_refs);
131
132 chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
refs/packed-backend.c
+2 -2
@@ -218,14 +218,14 @@ static size_t snapshot_hexsz(const struct snapshot *snapshot)
218 struct ref_store *packed_ref_store_init(struct repository *repo,
219 const char *payload UNUSED,
220 const char *gitdir,
221 - unsigned int store_flags)
221 + const struct ref_store_init_options *opts)
222 {
223 struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
224 struct ref_store *ref_store = (struct ref_store *)refs;
225 struct strbuf sb = STRBUF_INIT;
226
227 base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
228 - refs->store_flags = store_flags;
228 + refs->store_flags = opts->access_flags;
229
230 strbuf_addf(&sb, "%s/packed-refs", gitdir);
231 refs->path = strbuf_detach(&sb, NULL);
refs/packed-backend.h
+2 -1
@@ -3,6 +3,7 @@
3
4 struct repository;
5 struct ref_transaction;
6 +struct ref_store_init_options;
7
8 /*
9 * Support for storing references in a `packed-refs` file.
@@ -16,7 +17,7 @@ struct ref_transaction;
17 struct ref_store *packed_ref_store_init(struct repository *repo,
18 const char *payload,
19 const char *gitdir,
19 - unsigned int store_flags);
20 + const struct ref_store_init_options *options);
21
22 /*
23 * Lock the packed-refs file for writing. Flags is passed to
refs/refs-internal.h
+10 -1
@@ -385,6 +385,15 @@ struct ref_store;
385 REF_STORE_ODB | \
386 REF_STORE_MAIN)
387
388 +/*
389 + * Options for initializing the ref backend. All backend-agnostic information
390 + * which backends required will be held here.
391 + */
392 +struct ref_store_init_options {
393 + /* The kind of operations that the ref_store is allowed to perform. */
394 + unsigned int access_flags;
395 +};
396 +
397 /*
398 * Initialize the ref_store for the specified gitdir. These functions
399 * should call base_ref_store_init() to initialize the shared part of
@@ -393,7 +402,7 @@ struct ref_store;
402 typedef struct ref_store *ref_store_init_fn(struct repository *repo,
403 const char *payload,
404 const char *gitdir,
396 - unsigned int flags);
405 + const struct ref_store_init_options *opts);
406 /*
407 * Release all memory and resources associated with the ref store.
408 */
refs/reftable-backend.c
+2 -2
@@ -369,7 +369,7 @@ static int reftable_be_config(const char *var, const char *value,
369 static struct ref_store *reftable_be_init(struct repository *repo,
370 const char *payload,
371 const char *gitdir,
372 - unsigned int store_flags)
372 + const struct ref_store_init_options *opts)
373 {
374 struct reftable_ref_store *refs = xcalloc(1, sizeof(*refs));
375 struct strbuf ref_common_dir = STRBUF_INIT;
@@ -386,8 +386,8 @@ static struct ref_store *reftable_be_init(struct repository *repo,
386
387 base_ref_store_init(&refs->base, repo, refdir.buf, &refs_be_reftable);
388 strmap_init(&refs->worktree_backends);
389 - refs->store_flags = store_flags;
389 refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
390 + refs->store_flags = opts->access_flags;
391
392 switch (repo->hash_algo->format_id) {
393 case GIT_SHA1_FORMAT_ID: