refs: store the main ref store inside the repository struct

This moves the 'main_ref_store', which was a global variable in refs.c into the repository struct. This patch does not deal with the parts in the refs subsystem which deal with the submodules there. A later patch needs to get rid of the submodule exposure in the refs API, such as 'get_submodule_ref_store(path)'. Acked-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Apr 11, 2018 at 17:21 UTC 64a741619d27ede27788d2d444257635f4af8ffd
4 files changed +9 -15
refs.c
+5 -8
@@ -1608,9 +1608,6 @@ static struct ref_store_hash_entry *alloc_ref_store_hash_entry(
1608 return entry;
1609 }
1610
1611 -/* A pointer to the ref_store for the main repository: */
1612 -static struct ref_store *main_ref_store;
1613 -
1611 /* A hashmap of ref_stores, stored by submodule name: */
1612 static struct hashmap submodule_ref_stores;
1613
@@ -1652,13 +1649,13 @@ static struct ref_store *ref_store_init(const char *gitdir,
1649 return refs;
1650 }
1651
1655 -struct ref_store *get_main_ref_store_the_repository(void)
1652 +struct ref_store *get_main_ref_store(struct repository *r)
1653 {
1657 - if (main_ref_store)
1658 - return main_ref_store;
1654 + if (r->refs)
1655 + return r->refs;
1656
1660 - main_ref_store = ref_store_init(get_git_dir(), REF_STORE_ALL_CAPS);
1661 - return main_ref_store;
1657 + r->refs = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS);
1658 + return r->refs;
1659 }
1660
1661 /*
refs.h
+1 -3
@@ -760,9 +760,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,
760
761 int ref_storage_backend_exists(const char *name);
762
763 -#define get_main_ref_store(r) \
764 - get_main_ref_store_##r()
765 -struct ref_store *get_main_ref_store_the_repository(void);
763 +struct ref_store *get_main_ref_store(struct repository *r);
764 /*
765 * Return the ref_store instance for the specified submodule. For the
766 * main repository, use submodule==NULL; such a call cannot fail. For
refs/files-backend.c
-4
@@ -61,10 +61,6 @@ struct ref_lock {
61 struct object_id old_oid;
62 };
63
64 -/*
65 - * Future: need to be in "struct repository"
66 - * when doing a full libification.
67 - */
64 struct files_ref_store {
65 struct ref_store base;
66 unsigned int store_flags;
repository.h
+3
@@ -26,6 +26,9 @@ struct repository {
26 */
27 struct raw_object_store *objects;
28
29 + /* The store in which the refs are held. */
30 + struct ref_store *refs;
31 +
32 /*
33 * Path to the repository's graft file.
34 * Cannot be NULL after initialization.