Skip to content

Commit d6522d0

Browse files
pks-tgitster
authored andcommitted
refs: protect against chicken-and-egg recursion
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>
1 parent 79fa75d commit d6522d0

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

refs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,15 +2359,22 @@ void ref_store_release(struct ref_store *ref_store)
23592359

23602360
struct ref_store *get_main_ref_store(struct repository *r)
23612361
{
2362+
static bool initializing;
2363+
23622364
if (r->refs_private)
23632365
return r->refs_private;
23642366

23652367
if (!r->gitdir)
23662368
BUG("attempting to get main_ref_store outside of repository");
2369+
if (initializing)
2370+
BUG("initialization of main ref store is recursing");
23672371

2372+
initializing = true;
23682373
r->refs_private = ref_store_init(r, r->ref_storage_format,
23692374
r->gitdir, REF_STORE_ALL_CAPS);
23702375
r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private);
2376+
initializing = false;
2377+
23712378
return r->refs_private;
23722379
}
23732380

0 commit comments

Comments
 (0)