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

[PATCH v2 1/7] refs/packed: de-globalize handling of "core.packedRefsTimeout"

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 15, 2026, 07:39 UTC
Message-ID
<20260715-pks-refs-wo-the-repository-v2-1-d00d364f5a3e@pks.im>
In-Reply-To
<20260715-pks-refs-wo-the-repository-v2-0-d00d364f5a3e@pks.im>

When locking the "packed-refs" file we allow the user to configure a timeout for how long we try taking the lock. This is configurable via "core.packedRefsTimeout", which we parse in `packed_refs_lock()`.

The parsed value is stored in function-static variables though, which of course has the effect that we'll only ever use the timeout configured in the first packed reference store that we see. Consequently, if we ever were to handle stores from different repositories, then we'd use the same configuration for both stores even if they diverge.

This is of course a somewhat theoretical concern -- we don't typically handle multiple packed stores, and even if we did it's very unlikely that the user has configured different timeout values for each of them. But still, this is a code smell, and an unnecessary one, too.

Fix the issue by moving the value into `struct packed_ref_store` so that it can be parsed per store.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/packed-backend.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 499cb55dfa..14b27d24ec 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -162,6 +162,13 @@ struct packed_ref_store {
 	 * `packed_ref_store`) must not be freed.
 	 */
 	struct tempfile *tempfile;
+
+	/*
+	 * Timeout when taking the "packed-refs.lock" file. configurable via
+	 * "core.packedRefsTimeout".
+	 */
+	bool timeout_configured;
+	int timeout_value;
 };
 
 /*
@@ -1233,12 +1240,12 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
 	struct packed_ref_store *refs =
 		packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
 				"packed_refs_lock");
-	static int timeout_configured = 0;
-	static int timeout_value = 1000;
 
-	if (!timeout_configured) {
-		repo_config_get_int(the_repository, "core.packedrefstimeout", &timeout_value);
-		timeout_configured = 1;
+	if (!refs->timeout_configured) {
+		if (repo_config_get_int(ref_store->repo, "core.packedrefstimeout",
+					&refs->timeout_value))
+			refs->timeout_value = 1000;
+		refs->timeout_configured = true;
 	}
 
 	/*
@@ -1249,7 +1256,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
 	if (hold_lock_file_for_update_timeout(
 			    &refs->lock,
 			    refs->path,
-			    flags, timeout_value) < 0) {
+			    flags, refs->timeout_value) < 0) {
 		unable_to_lock_message(refs->path, errno, err);
 		return -1;
 	}
-- 
2.55.0.313.g8d093f411d.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 18 of 38 in “refs: remove use of `the_repository`”
  1. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 9, 2026
  2. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 9, 2026
  3. Junio C HamanoJul 9, 2026
  4. Patrick SteinhardtJul 10, 2026
  5. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  6. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  7. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 9, 2026
  8. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 9, 2026
  9. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 9, 2026
  10. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 9, 2026
  11. Junio C HamanoJul 9, 2026
  12. Patrick SteinhardtJul 10, 2026
  13. Patrick SteinhardtJul 10, 2026
  14. Junio C HamanoJul 10, 2026
  15. Junio C HamanoJul 10, 2026
  16. Junio C HamanoJul 10, 2026
  17. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 15, 2026
  18. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 15, 2026
  19. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  20. Toon ClaesJul 15, 2026
  21. Patrick SteinhardtJul 16, 2026
  22. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  23. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 15, 2026
  24. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 15, 2026
  25. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 15, 2026
  26. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 15, 2026
  27. Toon ClaesJul 15, 2026
  28. Junio C HamanoJul 15, 2026
  29. 0/6 refs: remove use of `the_repository`Patrick Steinhardt, Jul 16, 2026
  30. 1/6 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 16, 2026
  31. 2/6 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 16, 2026
  32. 3/6 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 16, 2026
  33. 4/6 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 16, 2026
  34. 5/6 worktree: pass repository to public functionsPatrick Steinhardt, Jul 16, 2026
  35. 6/6 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 16, 2026
  36. Christian CouderJul 16, 2026
  37. Junio C HamanoJul 16, 2026
  38. Toon ClaesJul 16, 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.