aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorKarthik Nayak <karthik.188@gmail.com>2026-02-25 10:40:46 +0100
committerJunio C Hamano <gitster@pobox.com>2026-02-25 09:40:00 -0800
commit53592d68e86814fcc4a8df6cc38340597e56fe5a (patch)
treeba40af5ae430ea79abd4f1898562c736f4f408b9 /refs.c
parent01dc84594ee365ee7086fccc7f590ab527730531 (diff)
downloadgit-53592d68e86814fcc4a8df6cc38340597e56fe5a.tar.xz
refs: add GIT_REFERENCE_BACKEND to specify reference backend
Git allows setting a different object directory via 'GIT_OBJECT_DIRECTORY', but provides no equivalent for references. In the previous commit we extended the 'extensions.refStorage' config to also support an URI input for reference backend with location. Let's also add a new environment variable 'GIT_REFERENCE_BACKEND' that takes in the same input as the config variable. Having an environment variable allows us to modify the reference backend and location on the fly for individual Git commands. The environment variable also allows usage of alternate reference directories during 'git-clone(1)' and 'git-init(1)'. Add the config to the repository when created with the environment variable set. When initializing the repository with an alternate reference folder, create the required stubs in the repositories $GIT_DIR. The inverse, i.e. removal of the ref store doesn't clean up the stubs in the $GIT_DIR since that would render it unusable. Removal of ref store is only used when migrating between ref formats and cleanup of the $GIT_DIR doesn't make sense in such a situation. Helped-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/refs.c b/refs.c
index ef1902e85c..a700a66f08 100644
--- a/refs.c
+++ b/refs.c
@@ -2192,13 +2192,17 @@ int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *e
{
int ret = refs->be->create_on_disk(refs, flags, err);
- if (!ret &&
- ref_storage_format_by_name(refs->be->name) != REF_STORAGE_FORMAT_FILES) {
- struct strbuf msg = STRBUF_INIT;
-
- strbuf_addf(&msg, "this repository uses the %s format", refs->be->name);
- refs_create_refdir_stubs(refs->repo, refs->gitdir, msg.buf);
- strbuf_release(&msg);
+ if (!ret) {
+ /* Creation of stubs for linked worktrees are handled in the worktree code. */
+ if (!(flags & REF_STORE_CREATE_ON_DISK_IS_WORKTREE) && refs->repo->ref_storage_payload) {
+ refs_create_refdir_stubs(refs->repo, refs->repo->gitdir,
+ "repository uses alternate refs storage");
+ } else if (ref_storage_format_by_name(refs->be->name) != REF_STORAGE_FORMAT_FILES) {
+ struct strbuf msg = STRBUF_INIT;
+ strbuf_addf(&msg, "this repository uses the %s format", refs->be->name);
+ refs_create_refdir_stubs(refs->repo, refs->gitdir, msg.buf);
+ strbuf_release(&msg);
+ }
}
return ret;
@@ -2208,10 +2212,18 @@ int ref_store_remove_on_disk(struct ref_store *refs, struct strbuf *err)
{
int ret = refs->be->remove_on_disk(refs, err);
- if (!ret &&
- ref_storage_format_by_name(refs->be->name) != REF_STORAGE_FORMAT_FILES) {
+ if (!ret) {
+ enum ref_storage_format format = ref_storage_format_by_name(refs->be->name);
struct strbuf sb = STRBUF_INIT;
+ /* Backends apart from the files backend create stubs. */
+ if (format == REF_STORAGE_FORMAT_FILES)
+ return ret;
+
+ /* Alternate refs backend require stubs in the gitdir. */
+ if (refs->repo->ref_storage_payload)
+ return ret;
+
strbuf_addf(&sb, "%s/HEAD", refs->gitdir);
if (unlink(sb.buf) < 0) {
strbuf_addf(err, "could not delete stub HEAD: %s",