git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 03/11] setup: don't apply "GIT_REFERENCE_BACKEND" without a repository

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 25, 2026, 09:20 UTC
Message-ID
<20260625-b4-pks-refs-avoid-chdir-notify-reparent-v6-3-41fbca3cf5e3@pks.im>
In-Reply-To
<20260625-b4-pks-refs-avoid-chdir-notify-reparent-v6-0-41fbca3cf5e3@pks.im>

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>
---
 setup.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/setup.c b/setup.c
index 2748155964..79125db565 100644
--- 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);
-- 
2.55.0.rc1.745.g43192e7977.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 4 of 17 in “refs: fix "onbranch" conditions”
  1. 00/11 refs: fix "onbranch" conditionsPatrick Steinhardt, Jun 25, 2026
  2. 01/11 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 25, 2026
  3. 02/11 setup: stop applying repository format twicePatrick Steinhardt, Jun 25, 2026
  4. 03/11 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 25, 2026
  5. 04/11 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 25, 2026
  6. 05/11 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 25, 2026
  7. 06/11 repository: free main reference databasePatrick Steinhardt, Jun 25, 2026
  8. 07/11 refs: move parsing of "core.logAllRefUpdates" back into ref storesPatrick Steinhardt, Jun 25, 2026
  9. 08/11 refs/files: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 25, 2026
  10. 09/11 reftable: split up write optionsPatrick Steinhardt, Jun 25, 2026
  11. 10/11 refs/reftable: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 25, 2026
  12. 11/11 refs: protect against chicken-and-egg recursionPatrick Steinhardt, Jun 25, 2026
  13. Justin ToblerJun 25, 2026
  14. Junio C HamanoJun 25, 2026
  15. Junio C HamanoJun 26, 2026
  16. Patrick SteinhardtJun 26, 2026
  17. Jeff KingJun 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.