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

[PATCH v2 3/7] refs/files: drop `USE_THE_REPOSITORY_VARIABLE`

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 15, 2026, 07:39 UTC
Message-ID
<20260715-pks-refs-wo-the-repository-v2-3-d00d364f5a3e@pks.im>
In-Reply-To
<20260715-pks-refs-wo-the-repository-v2-0-d00d364f5a3e@pks.im>

We have a bunch of users of `the_repository` in the "files" backend, all of which are trivial to convert to instead use the backend's own repo. Do so.

There is one more dependency on global state though via `ignore_case`, and thus we can't trivially remove `USE_THE_REPOSITORY_VARIABLE`. But this is the only use of global state, and we want to ensure that we don't unwittingly reintroduce a dependency on `the_repository` going forward.

Add an extern declaration for `ignore_case` so that it becomes accessible even without `USE_THE_REPOSITORY_VARIABLE` and drop the define itself.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/files-backend.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 3df56c25c8..09e1be838a 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "../git-compat-util.h"
@@ -29,6 +28,9 @@
 #include "../revision.h"
 #include <wildmatch.h>
 
+/* So that we can drop `USE_THE_REPOSITORY_VARIABLE`. */
+extern int ignore_case;
+
 /*
  * This backend uses the following flags in `ref_update::flags` for
  * internal bookkeeping purposes. Their numerical values must not
@@ -788,7 +790,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,
 	files_ref_path(refs, &ref_file, refname);
 
 retry:
-	switch (safe_create_leading_directories(the_repository, ref_file.buf)) {
+	switch (safe_create_leading_directories(refs->base.repo, ref_file.buf)) {
 	case SCLD_OK:
 		break; /* success */
 	case SCLD_EXISTS:
@@ -1164,7 +1166,8 @@ typedef int create_file_fn(const char *path, void *cb);
  * recent call of fn. fn is always called at least once, and will be
  * called more than once if it returns ENOENT or EISDIR.
  */
-static int raceproof_create_file(const char *path, create_file_fn fn, void *cb)
+static int raceproof_create_file(struct files_ref_store *refs,
+				 const char *path, create_file_fn fn, void *cb)
 {
 	/*
 	 * The number of times we will try to remove empty directories
@@ -1220,7 +1223,7 @@ static int raceproof_create_file(const char *path, create_file_fn fn, void *cb)
 			strbuf_addstr(&path_copy, path);
 
 		do {
-			scld_result = safe_create_leading_directories(the_repository, path_copy.buf);
+			scld_result = safe_create_leading_directories(refs->base.repo, path_copy.buf);
 			if (scld_result == SCLD_OK)
 				goto retry_fn;
 		} while (scld_result == SCLD_VANISHED && create_directories_remaining-- > 0);
@@ -1289,7 +1292,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
 	cb_data.lk   = &lock->lk;
 	cb_data.repo = refs->base.repo;
 
-	if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
+	if (raceproof_create_file(refs, ref_file.buf, create_reflock, &cb_data)) {
 		unable_to_lock_message(ref_file.buf, errno, err);
 		goto error_return;
 	}
@@ -1383,7 +1386,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
 	ref_transaction_add_update(
 			transaction, r->name,
 			REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING,
-			null_oid(the_hash_algo), &r->oid, NULL, NULL, NULL,
+			null_oid(refs->base.repo->hash_algo), &r->oid, NULL, NULL, NULL,
 			NULL, NULL);
 	if (ref_transaction_commit(transaction, &err))
 		goto cleanup;
@@ -1629,7 +1632,7 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
 	files_reflog_path(refs, &path, newrefname);
 	files_reflog_path(refs, &tmp, TMP_RENAMED_LOG);
 	cb.tmp_renamed_log = tmp.buf;
-	ret = raceproof_create_file(path.buf, rename_tmp_log_callback, &cb);
+	ret = raceproof_create_file(refs, path.buf, rename_tmp_log_callback, &cb);
 	if (ret) {
 		if (errno == EISDIR)
 			error("directory not empty: %s", path.buf);
@@ -1916,13 +1919,13 @@ static int log_ref_setup(struct files_ref_store *refs,
 	char *logfile;
 
 	if (log_refs_cfg == LOG_REFS_UNSET)
-		log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
+		log_refs_cfg = is_bare_repository(refs->base.repo) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
 
 	files_reflog_path(refs, &logfile_sb, refname);
 	logfile = strbuf_detach(&logfile_sb, NULL);
 
 	if (force_create || should_autocreate_reflog(log_refs_cfg, refname)) {
-		if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) {
+		if (raceproof_create_file(refs, logfile, open_or_create_logfile, logfd)) {
 			if (errno == ENOENT)
 				strbuf_addf(err, "unable to create directory for '%s': "
 					    "%s", logfile, strerror(errno));
@@ -1955,7 +1958,7 @@ static int log_ref_setup(struct files_ref_store *refs,
 	}
 
 	if (*logfd >= 0)
-		adjust_shared_perm(the_repository, logfile);
+		adjust_shared_perm(refs->base.repo, logfile);
 
 	free(logfile);
 	return 0;
@@ -3672,8 +3675,8 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store,
 	 *   they do not understand the reference format extension.
 	 */
 	strbuf_addf(&sb, "%s/refs", ref_store->gitdir);
-	safe_create_dir(the_repository, sb.buf, 1);
-	adjust_shared_perm(the_repository, sb.buf);
+	safe_create_dir(refs->base.repo, sb.buf, 1);
+	adjust_shared_perm(refs->base.repo, sb.buf);
 
 	/*
 	 * There is no need to create directories for common refs when creating
@@ -3685,11 +3688,11 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store,
 		 */
 		strbuf_reset(&sb);
 		files_ref_path(refs, &sb, "refs/heads");
-		safe_create_dir(the_repository, sb.buf, 1);
+		safe_create_dir(refs->base.repo, sb.buf, 1);
 
 		strbuf_reset(&sb);
 		files_ref_path(refs, &sb, "refs/tags");
-		safe_create_dir(the_repository, sb.buf, 1);
+		safe_create_dir(refs->base.repo, sb.buf, 1);
 	}
 
 	strbuf_release(&sb);
-- 
2.55.0.313.g8d093f411d.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 22 of 38 in “refs: remove use of `the_repository`”
  1. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 9, 2026
  2. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 9, 2026
  3. Junio C HamanoJul 9, 2026
  4. Patrick SteinhardtJul 10, 2026
  5. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  6. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  7. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 9, 2026
  8. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 9, 2026
  9. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 9, 2026
  10. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 9, 2026
  11. Junio C HamanoJul 9, 2026
  12. Patrick SteinhardtJul 10, 2026
  13. Patrick SteinhardtJul 10, 2026
  14. Junio C HamanoJul 10, 2026
  15. Junio C HamanoJul 10, 2026
  16. Junio C HamanoJul 10, 2026
  17. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 15, 2026
  18. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 15, 2026
  19. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  20. Toon ClaesJul 15, 2026
  21. Patrick SteinhardtJul 16, 2026
  22. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  23. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 15, 2026
  24. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 15, 2026
  25. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 15, 2026
  26. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 15, 2026
  27. Toon ClaesJul 15, 2026
  28. Junio C HamanoJul 15, 2026
  29. 0/6 refs: remove use of `the_repository`Patrick Steinhardt, Jul 16, 2026
  30. 1/6 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 16, 2026
  31. 2/6 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 16, 2026
  32. 3/6 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 16, 2026
  33. 4/6 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 16, 2026
  34. 5/6 worktree: pass repository to public functionsPatrick Steinhardt, Jul 16, 2026
  35. 6/6 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 16, 2026
  36. Christian CouderJul 16, 2026
  37. Junio C HamanoJul 16, 2026
  38. Toon ClaesJul 16, 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.