refs: add struct repository parameter in get_files_ref_lock_timeout_ms()

get_files_ref_lock_timeout_ms() calls repo_config_get_int() using the_repository, as no repository instance is available in its scope. Add a struct repository parameter and use it instead of the_repository. Update all callers accordingly. In files-backend.c, lock_raw_ref() can obtain repository instance from the struct ref_transaction via transaction->ref_store->repo and pass it down. For create_reflock(), which is used as a callback, introduce a small wrapper struct to pass both struct lock_file and struct repository through the callback data. This reduces reliance on the_repository global, though the function still uses static variables and is not yet fully repository-scoped. This can be addressed in a follow-up change. Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> Acked-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shreyansh Paliwal committed Apr 4, 2026 at 19:28 UTC b886f0b5dc71030bc9dcf58376533cf8e1098e9a
3 files changed +16 -9
refs.c
+2 -2
@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,
989 return REF_WORKTREE_SHARED;
990 }
991
992 -long get_files_ref_lock_timeout_ms(void)
992 +long get_files_ref_lock_timeout_ms(struct repository *repo)
993 {
994 static int configured = 0;
995
@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)
997 static int timeout_ms = 100;
998
999 if (!configured) {
1000 - repo_config_get_int(the_repository, "core.filesreflocktimeout", &timeout_ms);
1000 + repo_config_get_int(repo, "core.filesreflocktimeout", &timeout_ms);
1001 configured = 1;
1002 }
1003
refs/files-backend.c
+13 -6
@@ -792,7 +792,7 @@ retry:
792
793 if (hold_lock_file_for_update_timeout(
794 &lock->lk, ref_file.buf, LOCK_NO_DEREF,
795 - get_files_ref_lock_timeout_ms()) < 0) {
795 + get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
796 int myerr = errno;
797 errno = 0;
798 if (myerr == ENOENT && --attempts_remaining > 0) {
@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)
1190 return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
1191 }
1192
1193 +struct create_reflock_cb {
1194 + struct lock_file *lk;
1195 + struct repository *repo;
1196 +};
1197 +
1198 static int create_reflock(const char *path, void *cb)
1199 {
1195 - struct lock_file *lk = cb;
1196 -
1200 + struct create_reflock_cb *data = cb;
1201 return hold_lock_file_for_update_timeout(
1198 - lk, path, LOCK_NO_DEREF,
1199 - get_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;
1202 + data->lk, path, LOCK_NO_DEREF,
1203 + get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
1204 }
1205
1206 /*
@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
1212 {
1213 struct strbuf ref_file = STRBUF_INIT;
1214 struct ref_lock *lock;
1215 + struct create_reflock_cb cb_data;
1216
1217 files_assert_main_repository(refs, "lock_ref_oid_basic");
1218 assert(err);
@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
1234
1235 lock->ref_name = xstrdup(refname);
1236 lock->count = 1;
1237 + cb_data.lk = &lock->lk;
1238 + cb_data.repo = refs->base.repo;
1239
1233 - if (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {
1240 + if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
1241 unable_to_lock_message(ref_file.buf, errno, err);
1242 goto error_return;
1243 }
refs/refs-internal.h
+1 -1
@@ -43,7 +43,7 @@ struct ref_transaction;
43 * Return the length of time to retry acquiring a loose reference lock
44 * before giving up, in milliseconds:
45 */
46 -long get_files_ref_lock_timeout_ms(void);
46 +long get_files_ref_lock_timeout_ms(struct repository *repo);
47
48 /*
49 * Return true iff refname is minimally safe. "Safe" here means that