All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, gitster@pobox.com, a3205153416@gmail.com,
	bkkaracay@gmail.com,
	Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Subject: [PATCH v5 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()
Date: Sat,  4 Apr 2026 19:28:38 +0530	[thread overview]
Message-ID: <20260404135914.61195-2-shreyanshpaliwalcmsmn@gmail.com> (raw)
In-Reply-To: <20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com>

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>
---
 refs.c               |  4 ++--
 refs/files-backend.c | 19 +++++++++++++------
 refs/refs-internal.h |  2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/refs.c b/refs.c
index 685a0c247b..214ebfd5ce 100644
--- 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;
 	}
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7ce0d57478..ee8dd771a4 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,
 
 	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;
 	}
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index d79e35fd26..e4cfd9e19e 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -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
-- 
2.53.0


  reply	other threads:[~2026-04-04 13:59 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 16:44 [PATCH 0/5] refs: reduce reliance on the_repository global state Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 1/5] refs: make branchname helpers repository aware Shreyansh Paliwal
2026-03-27  7:49   ` Patrick Steinhardt
2026-03-28 12:45     ` Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware Shreyansh Paliwal
2026-03-27  7:50   ` Patrick Steinhardt
2026-03-27  9:23   ` Burak Kaan Karaçay
2026-03-28 12:51     ` Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-25 16:44 ` [PATCH 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-03-27  7:50   ` Patrick Steinhardt
2026-03-25 16:44 ` [PATCH 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-03-28 14:09 ` [PATCH v2 0/5] refs: reduce reliance on the_repository global state Shreyansh Paliwal
2026-03-28 14:09   ` [PATCH v2 1/5] refs: make branchname helpers repository aware Shreyansh Paliwal
2026-03-28 16:54     ` Tian Yuchen
2026-03-29  9:55       ` Shreyansh Paliwal
2026-03-29 15:37         ` Tian Yuchen
2026-03-28 14:09   ` [PATCH v2 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware Shreyansh Paliwal
2026-03-28 14:09   ` [PATCH v2 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-28 17:03     ` Tian Yuchen
2026-03-28 14:09   ` [PATCH v2 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-03-28 14:09   ` [PATCH v2 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-03-28 17:08     ` Tian Yuchen
2026-03-29  9:54       ` Shreyansh Paliwal
2026-03-29 10:16   ` [PATCH v3 0/5] replace the_repository with local repository instances Shreyansh Paliwal
2026-03-29 10:16     ` [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers Shreyansh Paliwal
2026-04-02  7:27       ` Patrick Steinhardt
2026-04-02 17:03         ` Burak Kaan Karaçay
2026-04-02 17:48           ` Tian Yuchen
2026-04-02 18:57           ` Patrick Steinhardt
2026-04-03 10:39             ` Shreyansh Paliwal
2026-03-29 10:16     ` [PATCH v3 2/5] refs: add struct repository parameter in get_files_ref_lock_timeout_ms() Shreyansh Paliwal
2026-03-29 10:16     ` [PATCH v3 3/5] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-03-29 10:16     ` [PATCH v3 4/5] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-02  7:27       ` Patrick Steinhardt
2026-04-03 10:43         ` Shreyansh Paliwal
2026-03-29 10:16     ` [PATCH v3 5/5] refs/packed-backend: use ref_store->repo instead " Shreyansh Paliwal
2026-04-03 12:08     ` [PATCH v4 0/3] refs: reduce reliance on global state Shreyansh Paliwal
2026-04-03 12:08       ` [PATCH v4 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms() Shreyansh Paliwal
2026-04-03 17:40         ` Tian Yuchen
2026-04-03 12:08       ` [PATCH v4 2/3] refs: remove the_hash_algo global state Shreyansh Paliwal
2026-04-03 12:09       ` [PATCH v4 3/3] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-04 13:58       ` [PATCH v5 0/3] refs: reduce reliance on global state Shreyansh Paliwal
2026-04-04 13:58         ` Shreyansh Paliwal [this message]
2026-04-04 13:58         ` [PATCH v5 2/3] refs: remove the_hash_algo " Shreyansh Paliwal
2026-04-04 13:58         ` [PATCH v5 3/3] refs/reftable-backend: drop uses of the_repository Shreyansh Paliwal
2026-04-08  8:46         ` [PATCH v5 0/3] refs: reduce reliance on global state Patrick Steinhardt
2026-04-08 17:09           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260404135914.61195-2-shreyanshpaliwalcmsmn@gmail.com \
    --to=shreyanshpaliwalcmsmn@gmail.com \
    --cc=a3205153416@gmail.com \
    --cc=bkkaracay@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.