Skip to content

Commit 0f4f1f1

Browse files
KarthikNayakgitster
authored andcommitted
refs: support obtaining ref_store for given dir
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. 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a2fb14 commit 0f4f1f1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

refs.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,15 @@ void ref_store_release(struct ref_store *ref_store)
21772177
free(ref_store->gitdir);
21782178
}
21792179

2180+
static struct ref_store *get_ref_store_for_dir(struct repository *r,
2181+
char *dir,
2182+
enum ref_storage_format format)
2183+
{
2184+
struct ref_store *ref_store = ref_store_init(r, format, dir,
2185+
REF_STORE_ALL_CAPS);
2186+
return maybe_debug_wrap_ref_store(dir, ref_store);
2187+
}
2188+
21802189
struct ref_store *get_main_ref_store(struct repository *r)
21812190
{
21822191
if (r->refs_private)
@@ -2185,9 +2194,7 @@ struct ref_store *get_main_ref_store(struct repository *r)
21852194
if (!r->gitdir)
21862195
BUG("attempting to get main_ref_store outside of repository");
21872196

2188-
r->refs_private = ref_store_init(r, r->ref_storage_format,
2189-
r->gitdir, REF_STORE_ALL_CAPS);
2190-
r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private);
2197+
r->refs_private = get_ref_store_for_dir(r, r->gitdir, r->ref_storage_format);
21912198
return r->refs_private;
21922199
}
21932200

0 commit comments

Comments
 (0)