]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: protect against chicken-and-egg recursion
authorPatrick Steinhardt <ps@pks.im>
Thu, 25 Jun 2026 09:20:09 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2026 20:19:58 +0000 (13:19 -0700)
In the preceding commits we have fixed recursion when creating the
reference backends due to a chicken-and-egg situation with "onbranch"
conditions. Unfortunately, this issue has existed for a while, and we
didn't really have a good mechanism to detect this recursion.

Improve the status quo by detecting the recursion when creating the main
reference store.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c

diff --git a/refs.c b/refs.c
index 5b773b1c151e94b9dfdef271e7151f69562cd837..1d2463789167c95dd02fd92ba10932f644ad656b 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2359,15 +2359,22 @@ void ref_store_release(struct ref_store *ref_store)
 
 struct ref_store *get_main_ref_store(struct repository *r)
 {
+       static bool initializing;
+
        if (r->refs_private)
                return r->refs_private;
 
        if (!r->gitdir)
                BUG("attempting to get main_ref_store outside of repository");
+       if (initializing)
+               BUG("initialization of main ref store is recursing");
 
+       initializing = true;
        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);
+       initializing = false;
+
        return r->refs_private;
 }