]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/packed: de-globalize handling of "core.packedRefsTimeout"
authorPatrick Steinhardt <ps@pks.im>
Thu, 16 Jul 2026 05:33:02 +0000 (07:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jul 2026 14:40:21 +0000 (07:40 -0700)
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>
refs/packed-backend.c

index 499cb55dface4fd62e797bf1821c79d223f87e09..c5d96793fa5841efca309df4e177ac8b497b03b9 100644 (file)
@@ -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;
        }