]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: don't apply "GIT_REFERENCE_BACKEND" without a repository
authorPatrick Steinhardt <ps@pks.im>
Thu, 25 Jun 2026 09:20:01 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2026 20:19:57 +0000 (13:19 -0700)
When discovering a repository we eventually also apply the
"GIT_REFERENCE_BACKEND" environment variable to the repository. There's
two problems with that:

  - We do this unconditionally, which is rather pointless: we really
    only have to configure the repository when we have found one.

  - We have already applied the repository format at that point in time,
    so we need to manually reapply it.

Move the logic around so that we only apply the environment variable
when a repository was discovered. This also allows us to drop the
explcit call to `repo_set_ref_storage_format()` because we now adjust
the format before we apply it via `apply_repository_format()`.

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

diff --git a/setup.c b/setup.c
index 27481559644bc8aa3ca65548f15172ee56b5f4ee..79125db56567b758bfb0f7fc92d1a650ceabab1c 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1906,7 +1906,6 @@ const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
        static struct strbuf cwd = STRBUF_INIT;
        struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT, report = STRBUF_INIT;
        const char *prefix = NULL;
-       const char *ref_backend_uri;
        struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
 
        /*
@@ -2032,6 +2031,25 @@ const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
 
                if (startup_info->have_repository) {
                        struct strbuf err = STRBUF_INIT;
+                       const char *ref_backend_uri;
+
+                       /*
+                        * The env variable should override the repository config
+                        * for 'extensions.refStorage'.
+                        */
+                       ref_backend_uri = getenv(GIT_REFERENCE_BACKEND_ENVIRONMENT);
+                       if (ref_backend_uri) {
+                               char *format;
+
+                               free(repo_fmt.ref_storage_payload);
+
+                               parse_reference_uri(ref_backend_uri, &format, &repo_fmt.ref_storage_payload);
+                               repo_fmt.ref_storage_format = ref_storage_format_by_name(format);
+                               if (repo_fmt.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+                                       die(_("unknown ref storage format: '%s'"), format);
+
+                               free(format);
+                       }
 
                        if (apply_repository_format(repo, &repo_fmt,
                                                    APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
@@ -2057,25 +2075,6 @@ const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
                setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
        }
 
-       /*
-        * The env variable should override the repository config
-        * for 'extensions.refStorage'.
-        */
-       ref_backend_uri = getenv(GIT_REFERENCE_BACKEND_ENVIRONMENT);
-       if (ref_backend_uri) {
-               char *backend, *payload;
-               enum ref_storage_format format;
-
-               parse_reference_uri(ref_backend_uri, &backend, &payload);
-               format = ref_storage_format_by_name(backend);
-               if (format == REF_STORAGE_FORMAT_UNKNOWN)
-                       die(_("unknown ref storage format: '%s'"), backend);
-               repo_set_ref_storage_format(repo, format, payload);
-
-               free(backend);
-               free(payload);
-       }
-
        setup_original_cwd(repo);
 
        strbuf_release(&dir);