{"thread":{"id":"52274","subject":"[PATCH] enable a timeout for hold_lock_file_for_update","startedAt":"2019-11-15T16:23:33Z","lastAt":"2019-11-15T16:23:33Z","messageCount":1,"participants":["Martin Nicolay"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"386335","messageId":"20191115162331.3CD6AD756F@wsmn.osm-gmbh.de","threadId":"52274","inReplyTo":null,"subject":"[PATCH] enable a timeout for hold_lock_file_for_update","fromName":"Martin Nicolay","fromEmail":"m.nicolay@osm-ag.de","sentAt":"2019-11-15T15:41:20Z","receivedAt":"2019-11-15T16:23:33Z","isPatch":true,"sender":{"key":"m.nicolay@osm-ag.de","avatar":null},"body":"The new funktion get_files_lock_timeout_ms reads the config\ncore.fileslocktimeout analog get_files_ref_lock_timeout_ms.\n\nThis value is used in hold_lock_file_for_update instead of the\nfixed value 0.\n---\nWhile working with complex scripts invoking git multiple times my\neditor detects the changes and calls \"git status\". This leads to\naborts in \"git-stash\". With this patch and an appropriate value\ncore.fileslocktimeout this problem goes away.\n\n lockfile.c | 15 +++++++++++++++\n lockfile.h |  4 +++-\n 2 files changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/lockfile.c b/lockfile.c\nindex 8e8ab4f29f..ac19de8937 100644\n--- a/lockfile.c\n+++ b/lockfile.c\n@@ -145,6 +145,21 @@ static int lock_file_timeout(struct lock_file *lk, const char *path,\n \t}\n }\n \n+long get_files_lock_timeout_ms(void)\n+{\n+\tstatic int configured = 0;\n+\n+\t/* The default timeout is 100 ms: */\n+\tstatic int timeout_ms = 100;\n+\n+\tif (!configured) {\n+\t\tgit_config_get_int(\"core.fileslocktimeout\", &timeout_ms);\n+\t\tconfigured = 1;\n+\t}\n+\n+\treturn timeout_ms;\n+}\n+\n void unable_to_lock_message(const char *path, int err, struct strbuf *buf)\n {\n \tif (err == EEXIST) {\ndiff --git a/lockfile.h b/lockfile.h\nindex 9843053ce8..a0520e6a7b 100644\n--- a/lockfile.h\n+++ b/lockfile.h\n@@ -163,6 +163,8 @@ int hold_lock_file_for_update_timeout(\n \t\tstruct lock_file *lk, const char *path,\n \t\tint flags, long timeout_ms);\n \n+long get_files_lock_timeout_ms(void);\n+\n /*\n  * Attempt to create a lockfile for the file at `path` and return a\n  * file descriptor for writing to it, or -1 on error. The flags\n@@ -172,7 +174,7 @@ static inline int hold_lock_file_for_update(\n \t\tstruct lock_file *lk, const char *path,\n \t\tint flags)\n {\n-\treturn hold_lock_file_for_update_timeout(lk, path, flags, 0);\n+\treturn hold_lock_file_for_update_timeout(lk, path, flags, get_files_lock_timeout_ms() );\n }\n \n /*\n-- \n2.13.7\n\n"}]}