]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: support obtaining ref_store for given dir
authorKarthik Nayak <karthik.188@gmail.com>
Mon, 1 Dec 2025 11:24:58 +0000 (12:24 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Dec 2025 00:23:51 +0000 (16:23 -0800)
The refs subsystem uses the `get_main_ref_store()` to obtain the main
ref_store for a given repository. In the upcoming patches we also want
to create a ref_store for any given reference directory, which may exist
in arbitrary paths. For the files backend and the reftable backend, the
reference directory is generally the $GIT_DIR.

To support such behavior, extract out the core logic for creating out
the ref_store from `get_main_ref_store()` into a new function
`get_ref_store_for_dir()` which can provide the ref_store for a
given (repository, directory, reference format) combination.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c

diff --git a/refs.c b/refs.c
index 965381367e0e53914040d77bea12975354c8b854..23f46867f2662e5a5d2a72be3378220d2a908ff5 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2177,6 +2177,15 @@ void ref_store_release(struct ref_store *ref_store)
        free(ref_store->gitdir);
 }
 
+static struct ref_store *get_ref_store_for_dir(struct repository *r,
+                                              char *dir,
+                                              enum ref_storage_format format)
+{
+       struct ref_store *ref_store = ref_store_init(r, format, dir,
+                                                    REF_STORE_ALL_CAPS);
+       return maybe_debug_wrap_ref_store(dir, ref_store);
+}
+
 struct ref_store *get_main_ref_store(struct repository *r)
 {
        if (r->refs_private)
@@ -2185,9 +2194,7 @@ struct ref_store *get_main_ref_store(struct repository *r)
        if (!r->gitdir)
                BUG("attempting to get main_ref_store outside of repository");
 
-       r->refs_private = ref_store_init(r, r->ref_storage_format,
-                                        r->gitdir, REF_STORE_ALL_CAPS);
-       r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private);
+       r->refs_private = get_ref_store_for_dir(r, r->gitdir, r->ref_storage_format);
        return r->refs_private;
 }