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

[PATCH v4 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()

From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Date
Apr 3, 2026, 12:08 UTC
Message-ID
<20260403120938.1142533-2-shreyanshpaliwalcmsmn@gmail.com>
In-Reply-To
<20260403120938.1142533-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.
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
Previous: Shreyansh PaliwalNext: Tian Yuchen
Message 39 of 48 in “refs: reduce reliance on the_repository global state”
  1. 0/5 refs: reduce reliance on the_repository global stateShreyansh Paliwal, Mar 25, 2026
  2. 1/5 refs: make branchname helpers repository awareShreyansh Paliwal, Mar 25, 2026
  3. Patrick SteinhardtMar 27, 2026
  4. Shreyansh PaliwalMar 28, 2026
  5. 2/5 refs: make get_files_ref_lock_timeout_ms() repostory awareShreyansh Paliwal, Mar 25, 2026
  6. Patrick SteinhardtMar 27, 2026
  7. Burak Kaan KaraçayMar 27, 2026
  8. Shreyansh PaliwalMar 28, 2026
  9. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 25, 2026
  10. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 25, 2026
  11. Patrick SteinhardtMar 27, 2026
  12. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 25, 2026
  13. 0/5 refs: reduce reliance on the_repository global stateShreyansh Paliwal, Mar 28, 2026
  14. 1/5 refs: make branchname helpers repository awareShreyansh Paliwal, Mar 28, 2026
  15. Tian YuchenMar 28, 2026
  16. Shreyansh PaliwalMar 29, 2026
  17. Tian YuchenMar 29, 2026
  18. 2/5 refs: make get_files_ref_lock_timeout_ms() repostory awareShreyansh Paliwal, Mar 28, 2026
  19. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 28, 2026
  20. Tian YuchenMar 28, 2026
  21. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 28, 2026
  22. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 28, 2026
  23. Tian YuchenMar 28, 2026
  24. Shreyansh PaliwalMar 29, 2026
  25. 0/5 replace the_repository with local repository instancesShreyansh Paliwal, Mar 29, 2026
  26. 1/5 refs: add struct repository parameter to branchname helpersShreyansh Paliwal, Mar 29, 2026
  27. Patrick SteinhardtApr 2, 2026
  28. Burak Kaan KaraçayApr 2, 2026
  29. Tian YuchenApr 2, 2026
  30. Patrick SteinhardtApr 2, 2026
  31. Shreyansh PaliwalApr 3, 2026
  32. 2/5 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Mar 29, 2026
  33. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 29, 2026
  34. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 29, 2026
  35. Patrick SteinhardtApr 2, 2026
  36. Shreyansh PaliwalApr 3, 2026
  37. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 29, 2026
  38. 0/3 refs: reduce reliance on global stateShreyansh Paliwal, Apr 3, 2026
  39. 1/3 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Apr 3, 2026
  40. Tian YuchenApr 3, 2026
  41. 2/3 refs: remove the_hash_algo global stateShreyansh Paliwal, Apr 3, 2026
  42. 3/3 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Apr 3, 2026
  43. 0/3 refs: reduce reliance on global stateShreyansh Paliwal, Apr 4, 2026
  44. 1/3 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Apr 4, 2026
  45. 2/3 refs: remove the_hash_algo global stateShreyansh Paliwal, Apr 4, 2026
  46. 3/3 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Apr 4, 2026
  47. Patrick SteinhardtApr 8, 2026
  48. Junio C HamanoApr 8, 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.