]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: add struct repository parameter in get_files_ref_lock_timeout_ms()
authorShreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Sat, 4 Apr 2026 13:58:38 +0000 (19:28 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2026 16:58:09 +0000 (09:58 -0700)
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>
refs.c
refs/files-backend.c
refs/refs-internal.h

diff --git a/refs.c b/refs.c
index 5d1d28523d617f8f09d1c1c4d73e692809be5853..4ab746a3cb555c65b79050ac91fa83546e1a0463 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,
        return REF_WORKTREE_SHARED;
 }
 
-long get_files_ref_lock_timeout_ms(void)
+long get_files_ref_lock_timeout_ms(struct repository *repo)
 {
        static int configured = 0;
 
@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)
        static int timeout_ms = 100;
 
        if (!configured) {
-               repo_config_get_int(the_repository, "core.filesreflocktimeout", &timeout_ms);
+               repo_config_get_int(repo, "core.filesreflocktimeout", &timeout_ms);
                configured = 1;
        }
 
index 0537a72b2af9e0e2180dfd34527e4dead1019611..10e4388d2ca01a64d35512f7301a363e8629ab2f 100644 (file)
@@ -792,7 +792,7 @@ retry:
 
        if (hold_lock_file_for_update_timeout(
                            &lock->lk, ref_file.buf, LOCK_NO_DEREF,
-                           get_files_ref_lock_timeout_ms()) < 0) {
+                           get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
                int myerr = errno;
                errno = 0;
                if (myerr == ENOENT && --attempts_remaining > 0) {
@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)
        return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
 }
 
+struct create_reflock_cb {
+    struct lock_file *lk;
+    struct repository *repo;
+};
+
 static int create_reflock(const char *path, void *cb)
 {
-       struct lock_file *lk = cb;
-
+       struct create_reflock_cb *data = cb;
        return hold_lock_file_for_update_timeout(
-                       lk, path, LOCK_NO_DEREF,
-                       get_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;
+                       data->lk, path, LOCK_NO_DEREF,
+                       get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
 }
 
 /*
@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
 {
        struct strbuf ref_file = STRBUF_INIT;
        struct ref_lock *lock;
+       struct create_reflock_cb cb_data;
 
        files_assert_main_repository(refs, "lock_ref_oid_basic");
        assert(err);
@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
 
        lock->ref_name = xstrdup(refname);
        lock->count = 1;
+       cb_data.lk   = &lock->lk;
+       cb_data.repo = refs->base.repo;
 
-       if (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {
+       if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
                unable_to_lock_message(ref_file.buf, errno, err);
                goto error_return;
        }
index d79e35fd269a6c4afc581d355687132db5e413f0..e4cfd9e19ee74fdb5e6057addd773abbda1a4979 100644 (file)
@@ -43,7 +43,7 @@ struct ref_transaction;
  * Return the length of time to retry acquiring a loose reference lock
  * before giving up, in milliseconds:
  */
-long get_files_ref_lock_timeout_ms(void);
+long get_files_ref_lock_timeout_ms(struct repository *repo);
 
 /*
  * Return true iff refname is minimally safe. "Safe" here means that