]> git.ipfire.org Git - thirdparty/git.git/commitdiff
crendential-store: use timeout when locking file
authorSimão Afonso <simao.afonso@powertools-tech.com>
Wed, 25 Nov 2020 18:31:23 +0000 (18:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Nov 2020 20:30:18 +0000 (12:30 -0800)
When holding the lock for rewriting the credential file, use a timeout
to avoid race conditions when the credentials file needs to be updated
in parallel.

An example would be doing `fetch --all` on a repository with several
remotes that need credentials, using parallel fetching.

The timeout can be configured using "credentialStore.lockTimeoutMS",
defaulting to 1 second.

Signed-off-by: Simão Afonso <simao.afonso@powertools-tech.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/credential.txt
builtin/credential-store.c

index 9d01641c282aa9cf472dc782e13cd9c430b17e3a..512f31876e17ed6892ff7f1858a891f0f7938b29 100644 (file)
@@ -28,3 +28,9 @@ credential.<url>.*::
 
 credentialCache.ignoreSIGHUP::
        Tell git-credential-cache--daemon to ignore SIGHUP, instead of quitting.
+
+credentialStore.lockTimeoutMS::
+       The length of time, in milliseconds, for git-credential-store to retry
+       when trying to lock the credentials file. Value 0 means not to retry at
+       all; -1 means to try indefinitely. Default is 1000 (i.e., retry for
+       1s).
index 5331ab151a6f6052dc532ab32875f864070e3b72..ae3c1ba75fe60306f8819b1038660e73749aa83b 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "credential.h"
 #include "string-list.h"
@@ -58,8 +59,11 @@ static void print_line(struct strbuf *buf)
 static void rewrite_credential_file(const char *fn, struct credential *c,
                                    struct strbuf *extra)
 {
-       if (hold_lock_file_for_update(&credential_lock, fn, 0) < 0)
-               die_errno("unable to get credential storage lock");
+       int timeout_ms = 1000;
+
+       git_config_get_int("credentialstore.locktimeoutms", &timeout_ms);
+       if (hold_lock_file_for_update_timeout(&credential_lock, fn, 0, timeout_ms) < 0)
+               die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
        if (extra)
                print_line(extra);
        parse_credential_file(fn, c, NULL, print_line);