refs/packed: de-globalize handling of "core.packedRefsTimeout"

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. This removes the last callsite that still used `the_repository`, so drop the `USE_THE_REPOSITORY_VARIABLE` define. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 16, 2026 at 07:33 UTC 5abbd7c3a2e0b484e23377ae405af2b282286274
1 file changed +13 -7
refs/packed-backend.c
+13 -7
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "../git-compat-util.h"
@@ -162,6 +161,13 @@ struct packed_ref_store {
161 * `packed_ref_store`) must not be freed.
162 */
163 struct tempfile *tempfile;
164 +
165 + /*
166 + * Timeout when taking the "packed-refs.lock" file. configurable via
167 + * "core.packedRefsTimeout".
168 + */
169 + bool timeout_configured;
170 + int timeout_value;
171 };
172
173 /*
@@ -1233,12 +1239,12 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
1239 struct packed_ref_store *refs =
1240 packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
1241 "packed_refs_lock");
1236 - static int timeout_configured = 0;
1237 - static int timeout_value = 1000;
1242
1239 - if (!timeout_configured) {
1240 - repo_config_get_int(the_repository, "core.packedrefstimeout", &timeout_value);
1241 - timeout_configured = 1;
1243 + if (!refs->timeout_configured) {
1244 + if (repo_config_get_int(ref_store->repo, "core.packedrefstimeout",
1245 + &refs->timeout_value))
1246 + refs->timeout_value = 1000;
1247 + refs->timeout_configured = true;
1248 }
1249
1250 /*
@@ -1249,7 +1255,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
1255 if (hold_lock_file_for_update_timeout(
1256 &refs->lock,
1257 refs->path,
1252 - flags, timeout_value) < 0) {
1258 + flags, refs->timeout_value) < 0) {
1259 unable_to_lock_message(refs->path, errno, err);
1260 return -1;
1261 }