Re: [PATCH 2/6] setup: move creation of "refs/" into the files backend
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jan 2, 2024, 13:23 UTC
- Message-ID
- <CAOLa=ZTR6aW5aoxcMOS3U3TL1VxSfmyVno9fu7B5201pJTqyyg@mail.gmail.com>
- In-Reply-To
- <ae013eaa4aba0d68172ff03dbe9f2c2bca596285.1703754513.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> 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. >
Why not move it to refs.c:refs_init_db() instead? this way each implementation doesn't have to do it?
@@ -2020,14 +2024,30 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs, /* backend functions */ int refs_init_db(struct ref_store *refs, int flags, struct strbuf *err) { + /* + * 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. + */ + safe_create_dir(git_path("refs"), 1); + adjust_shared_perm(git_path("refs")); + return refs->be->init_db(refs, flags, err); }