summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-01-08 10:05:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2024-01-08 21:17:30 (GMT)
commitc358d165f2a4b3176b527e18c207105f6821335e (patch)
tree8c6771b903286615e3cc8e30224df4933fbc8566 /refs/files-backend.c
parent2e573d61ffe3d1e7ea94673757fb69477c1499bc (diff)
downloadgit-c358d165f2a4b3176b527e18c207105f6821335e.zip
git-c358d165f2a4b3176b527e18c207105f6821335e.tar.gz
git-c358d165f2a4b3176b527e18c207105f6821335e.tar.bz2
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>
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 153efe6..054ecdb 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3229,8 +3229,25 @@ static int files_init_db(struct ref_store *ref_store,
struct strbuf sb = STRBUF_INIT;
/*
+ * We need to create a "refs" dir in any case so that older versions of
+ * Git can tell that this is a repository. This serves two main purposes:
+ *
+ * - Clients will know to stop walking the parent-directory chain when
+ * detecting the Git repository. Otherwise they may end up detecting
+ * a Git repository in a parent directory instead.
+ *
+ * - Instead of failing to detect a repository with unknown reference
+ * format altogether, old clients will print an error saying that
+ * they do not understand the reference format extension.
+ */
+ strbuf_addf(&sb, "%s/refs", ref_store->gitdir);
+ safe_create_dir(sb.buf, 1);
+ adjust_shared_perm(sb.buf);
+
+ /*
* Create .git/refs/{heads,tags}
*/
+ strbuf_reset(&sb);
files_ref_path(refs, &sb, "refs/heads");
safe_create_dir(sb.buf, 1);