setup: move creation of "refs/" into the files backend
commitc358d165f2a4b3176b527e18c207105f6821335e
authorPatrick Steinhardt <ps@pks.im>
Mon, 8 Jan 2024 10:05:30 +0000 (8 11:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Jan 2024 21:17:30 +0000 (8 13:17 -0800)
tree8c6771b903286615e3cc8e30224df4933fbc8566
parent2e573d61ffe3d1e7ea94673757fb69477c1499bc
setup: move creation of "refs/" into the files backend

When creating the ref database we unconditionally create the "refs/"
directory in "setup.c". This is a mandatory prerequisite for all Git
repositories regardless of the ref backend in use, because Git will be
unable to detect the directory as a repository if "refs/" doesn't exist.

We are about to add another new caller that will want to create a ref
database when creating worktrees. We would require the same logic to
create the "refs/" directory even though the caller really should not
care about such low-level details. Ideally, the ref database should be
fully initialized after calling `refs_init_db()`.

Move the code to create the directory into the files backend itself to
make it so. This means that future ref backends will also need to have
equivalent logic around to ensure that the directory exists, but it
seems a lot more sensible to have it this way round than to require
callers to create the directory themselves.

An alternative to this would be to create "refs/" in `refs_init_db()`
directly. This feels conceptually unclean though as the creation of the
refdb is now cluttered across different callsites. Furthermore, both the
"files" and the upcoming "reftable" backend write backend-specific data
into the "refs/" directory anyway, so splitting up this logic would only
make it harder to reason about.

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