refs/files: drop `USE_THE_REPOSITORY_VARIABLE`

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 16, 2026 at 07:33 UTC af57f7361d51ad76bead03829c6b1618a0c8adbb
1 file changed +17 -14
refs/files-backend.c
+17 -14
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "../git-compat-util.h"
@@ -29,6 +28,9 @@
28 #include "../revision.h"
29 #include <wildmatch.h>
30
31 +/* So that we can drop `USE_THE_REPOSITORY_VARIABLE`. */
32 +extern int ignore_case;
33 +
34 /*
35 * This backend uses the following flags in `ref_update::flags` for
36 * 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,
790 files_ref_path(refs, &ref_file, refname);
791
792 retry:
791 - switch (safe_create_leading_directories(the_repository, ref_file.buf)) {
793 + switch (safe_create_leading_directories(refs->base.repo, ref_file.buf)) {
794 case SCLD_OK:
795 break; /* success */
796 case SCLD_EXISTS:
@@ -1164,7 +1166,8 @@ typedef int create_file_fn(const char *path, void *cb);
1166 * recent call of fn. fn is always called at least once, and will be
1167 * called more than once if it returns ENOENT or EISDIR.
1168 */
1167 -static int raceproof_create_file(const char *path, create_file_fn fn, void *cb)
1169 +static int raceproof_create_file(struct files_ref_store *refs,
1170 + const char *path, create_file_fn fn, void *cb)
1171 {
1172 /*
1173 * The number of times we will try to remove empty directories
@@ -1220,7 +1223,7 @@ retry_fn:
1223 strbuf_addstr(&path_copy, path);
1224
1225 do {
1223 - scld_result = safe_create_leading_directories(the_repository, path_copy.buf);
1226 + scld_result = safe_create_leading_directories(refs->base.repo, path_copy.buf);
1227 if (scld_result == SCLD_OK)
1228 goto retry_fn;
1229 } 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,
1292 cb_data.lk = &lock->lk;
1293 cb_data.repo = refs->base.repo;
1294
1292 - if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
1295 + if (raceproof_create_file(refs, ref_file.buf, create_reflock, &cb_data)) {
1296 unable_to_lock_message(ref_file.buf, errno, err);
1297 goto error_return;
1298 }
@@ -1383,7 +1386,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
1386 ref_transaction_add_update(
1387 transaction, r->name,
1388 REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING,
1386 - null_oid(the_hash_algo), &r->oid, NULL, NULL, NULL,
1389 + null_oid(refs->base.repo->hash_algo), &r->oid, NULL, NULL, NULL,
1390 NULL, NULL);
1391 if (ref_transaction_commit(transaction, &err))
1392 goto cleanup;
@@ -1629,7 +1632,7 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
1632 files_reflog_path(refs, &path, newrefname);
1633 files_reflog_path(refs, &tmp, TMP_RENAMED_LOG);
1634 cb.tmp_renamed_log = tmp.buf;
1632 - ret = raceproof_create_file(path.buf, rename_tmp_log_callback, &cb);
1635 + ret = raceproof_create_file(refs, path.buf, rename_tmp_log_callback, &cb);
1636 if (ret) {
1637 if (errno == EISDIR)
1638 error("directory not empty: %s", path.buf);
@@ -1916,13 +1919,13 @@ static int log_ref_setup(struct files_ref_store *refs,
1919 char *logfile;
1920
1921 if (log_refs_cfg == LOG_REFS_UNSET)
1919 - log_refs_cfg = is_bare_repository(the_repository) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
1922 + log_refs_cfg = is_bare_repository(refs->base.repo) ? LOG_REFS_NONE : LOG_REFS_NORMAL;
1923
1924 files_reflog_path(refs, &logfile_sb, refname);
1925 logfile = strbuf_detach(&logfile_sb, NULL);
1926
1927 if (force_create || should_autocreate_reflog(log_refs_cfg, refname)) {
1925 - if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) {
1928 + if (raceproof_create_file(refs, logfile, open_or_create_logfile, logfd)) {
1929 if (errno == ENOENT)
1930 strbuf_addf(err, "unable to create directory for '%s': "
1931 "%s", logfile, strerror(errno));
@@ -1955,7 +1958,7 @@ static int log_ref_setup(struct files_ref_store *refs,
1958 }
1959
1960 if (*logfd >= 0)
1958 - adjust_shared_perm(the_repository, logfile);
1961 + adjust_shared_perm(refs->base.repo, logfile);
1962
1963 free(logfile);
1964 return 0;
@@ -3672,8 +3675,8 @@ static int files_ref_store_create_on_disk(struct ref_store *ref_store,
3675 * they do not understand the reference format extension.
3676 */
3677 strbuf_addf(&sb, "%s/refs", ref_store->gitdir);
3675 - safe_create_dir(the_repository, sb.buf, 1);
3676 - adjust_shared_perm(the_repository, sb.buf);
3678 + safe_create_dir(refs->base.repo, sb.buf, 1);
3679 + adjust_shared_perm(refs->base.repo, sb.buf);
3680
3681 /*
3682 * 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,
3688 */
3689 strbuf_reset(&sb);
3690 files_ref_path(refs, &sb, "refs/heads");
3688 - safe_create_dir(the_repository, sb.buf, 1);
3691 + safe_create_dir(refs->base.repo, sb.buf, 1);
3692
3693 strbuf_reset(&sb);
3694 files_ref_path(refs, &sb, "refs/tags");
3692 - safe_create_dir(the_repository, sb.buf, 1);
3695 + safe_create_dir(refs->base.repo, sb.buf, 1);
3696 }
3697
3698 strbuf_release(&sb);