From: Patrick Steinhardt Date: Thu, 16 Jul 2026 05:33:02 +0000 (+0200) Subject: refs/packed: de-globalize handling of "core.packedRefsTimeout" X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5abbd7c3a2e0b484e23377ae405af2b282286274;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 499cb55dfa..c5d96793fa 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "../git-compat-util.h" @@ -162,6 +161,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 +1239,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 +1255,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; }