]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: introduce `ref_store_init_options`
authorKarthik Nayak <karthik.188@gmail.com>
Mon, 27 Apr 2026 10:42:03 +0000 (12:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Apr 2026 12:35:11 +0000 (21:35 +0900)
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>
refs.c
refs/files-backend.c
refs/packed-backend.c
refs/packed-backend.h
refs/refs-internal.h
refs/reftable-backend.c

diff --git a/refs.c b/refs.c
index bfcb9c7ac3d38c6c13d0b83973147fbf60106e1e..8992dd6ae865dda1106c3541a0b7ac17f5c954a8 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2295,6 +2295,9 @@ static struct ref_store *ref_store_init(struct repository *repo,
 {
        const struct ref_storage_be *be;
        struct ref_store *refs;
+       struct ref_store_init_options opts = {
+               .access_flags = flags,
+       };
 
        be = find_ref_storage_backend(format);
        if (!be)
@@ -2304,7 +2307,8 @@ static struct ref_store *ref_store_init(struct repository *repo,
         * TODO Send in a 'struct worktree' instead of a 'gitdir', and
         * allow the backend to handle how it wants to deal with worktrees.
         */
-       refs = be->init(repo, repo->ref_storage_payload, gitdir, flags);
+       refs = be->init(repo, repo->ref_storage_payload, gitdir, &opts);
+
        return refs;
 }
 
index b3b0c25f84e5033f078546a0840079b4bbaa6e90..72afe62cee59670cee39c0de8902f3b0dc893227 100644 (file)
@@ -108,7 +108,7 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
 static struct ref_store *files_ref_store_init(struct repository *repo,
                                              const char *payload,
                                              const char *gitdir,
-                                             unsigned int flags)
+                                             const struct ref_store_init_options *opts)
 {
        struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
        struct ref_store *ref_store = (struct ref_store *)refs;
@@ -120,11 +120,13 @@ static struct ref_store *files_ref_store_init(struct repository *repo,
                                         &ref_common_dir);
 
        base_ref_store_init(ref_store, repo, refdir.buf, &refs_be_files);
-       refs->store_flags = flags;
+
        refs->gitcommondir = strbuf_detach(&ref_common_dir, NULL);
        refs->packed_ref_store =
-               packed_ref_store_init(repo, NULL, refs->gitcommondir, flags);
+               packed_ref_store_init(repo, NULL, refs->gitcommondir, opts);
+       refs->store_flags = opts->access_flags;
        refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
+
        repo_config_get_bool(repo, "core.prefersymlinkrefs", &refs->prefer_symlink_refs);
 
        chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
index 23ed62984b765b6c0c7426112d88f1f35bab3728..35a0f32e1cc45e0039fd395c33fa6e3b5bd3d9b1 100644 (file)
@@ -218,14 +218,14 @@ static size_t snapshot_hexsz(const struct snapshot *snapshot)
 struct ref_store *packed_ref_store_init(struct repository *repo,
                                        const char *payload UNUSED,
                                        const char *gitdir,
-                                       unsigned int store_flags)
+                                       const struct ref_store_init_options *opts)
 {
        struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
        struct ref_store *ref_store = (struct ref_store *)refs;
        struct strbuf sb = STRBUF_INIT;
 
        base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
-       refs->store_flags = store_flags;
+       refs->store_flags = opts->access_flags;
 
        strbuf_addf(&sb, "%s/packed-refs", gitdir);
        refs->path = strbuf_detach(&sb, NULL);
index 2c2377a35653ec7c57848c39b43d04c96994860d..1db48e801d63d0c97001d96861d90037a5a5ba51 100644 (file)
@@ -3,6 +3,7 @@
 
 struct repository;
 struct ref_transaction;
+struct ref_store_init_options;
 
 /*
  * Support for storing references in a `packed-refs` file.
@@ -16,7 +17,7 @@ struct ref_transaction;
 struct ref_store *packed_ref_store_init(struct repository *repo,
                                        const char *payload,
                                        const char *gitdir,
-                                       unsigned int store_flags);
+                                       const struct ref_store_init_options *options);
 
 /*
  * Lock the packed-refs file for writing. Flags is passed to
index 2d963cc4f4e201bb712397f400c65ab513f6e7ab..f49b3807bf3382a3afa8e1c717b35ffbbb5db85c 100644 (file)
@@ -385,6 +385,15 @@ struct ref_store;
                                 REF_STORE_ODB | \
                                 REF_STORE_MAIN)
 
+/*
+ * Options for initializing the ref backend. All backend-agnostic information
+ * which backends required will be held here.
+ */
+struct ref_store_init_options {
+       /* The kind of operations that the ref_store is allowed to perform. */
+       unsigned int access_flags;
+};
+
 /*
  * Initialize the ref_store for the specified gitdir. These functions
  * should call base_ref_store_init() to initialize the shared part of
@@ -393,7 +402,7 @@ struct ref_store;
 typedef struct ref_store *ref_store_init_fn(struct repository *repo,
                                            const char *payload,
                                            const char *gitdir,
-                                           unsigned int flags);
+                                           const struct ref_store_init_options *opts);
 /*
  * Release all memory and resources associated with the ref store.
  */
index daea30a5b4cad91314b40b51d56b49a37720fc63..ad4ee2627c441877aa5bb89359da433e5cbb6f6a 100644 (file)
@@ -369,7 +369,7 @@ static int reftable_be_config(const char *var, const char *value,
 static struct ref_store *reftable_be_init(struct repository *repo,
                                          const char *payload,
                                          const char *gitdir,
-                                         unsigned int store_flags)
+                                         const struct ref_store_init_options *opts)
 {
        struct reftable_ref_store *refs = xcalloc(1, sizeof(*refs));
        struct strbuf ref_common_dir = STRBUF_INIT;
@@ -386,8 +386,8 @@ static struct ref_store *reftable_be_init(struct repository *repo,
 
        base_ref_store_init(&refs->base, repo, refdir.buf, &refs_be_reftable);
        strmap_init(&refs->worktree_backends);
-       refs->store_flags = store_flags;
        refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
+       refs->store_flags = opts->access_flags;
 
        switch (repo->hash_algo->format_id) {
        case GIT_SHA1_FORMAT_ID: