{"thread":{"id":"52273","subject":"","startedAt":"2019-11-15T16:11:56Z","lastAt":"2019-11-15T16:37:43Z","messageCount":3,"participants":["Martin Nicolay","Martin Ågren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"386334","messageId":"20191115160330.A64EBD756F@wsmn.osm-gmbh.de","threadId":"52273","inReplyTo":null,"subject":"","fromName":"Martin Nicolay","fromEmail":"martin@wsmn.osm-gmbh.de","sentAt":"2019-11-15T16:03:30Z","receivedAt":"2019-11-15T16:11:56Z","isPatch":false,"sender":{"key":"martin@wsmn.osm-gmbh.de","avatar":null},"body":"From 7f5bb47a3b5b7a5443009078d936ab62dfa1fd85 Mon Sep 17 00:00:00 2001\nFrom: Martin Nicolay <m.nicolay@osm-ag.de>\nDate: Fri, 15 Nov 2019 16:41:20 +0100\nSubject: [PATCH] enable a timeout for hold_lock_file_for_update\n\nThe 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"},{"id":"386336","messageId":"CAN0heSoW1GWEDxQN-d9bR4Vs5vzMaeDMar=QzShhcVNO1A0Sxg@mail.gmail.com","threadId":"52273","inReplyTo":"20191115160330.A64EBD756F@wsmn.osm-gmbh.de","subject":"Re:","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2019-11-15T16:29:38Z","receivedAt":"2019-11-15T16:29:51Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Hi Martin\n\nOn Fri, 15 Nov 2019 at 17:17, Martin Nicolay <martin@wsmn.osm-gmbh.de> wrote:\n\n> While working with complex scripts invoking git multiple times my\n> editor detects the changes and calls \"git status\". This leads to\n> aborts in \"git-stash\". With this patch and an appropriate value\n> core.fileslocktimeout this problem goes away.\n\nAre you able to patch your editor to call\n  git --no-optional-locks status\ninstead? See the bottom of git-status(1) (\"BACKGROUND REFRESH\") for more\non this.\n\n> +long get_files_lock_timeout_ms(void)\n> +{\n> +       static int configured = 0;\n> +\n> +       /* The default timeout is 100 ms: */\n> +       static int timeout_ms = 100;\n> +\n> +       if (!configured) {\n> +               git_config_get_int(\"core.fileslocktimeout\", &timeout_ms);\n> +               configured = 1;\n> +       }\n> +\n> +       return timeout_ms;\n> +}\n> +\n\n> @@ -172,7 +174,7 @@ static inline int hold_lock_file_for_update(\n>                 struct lock_file *lk, const char *path,\n>                 int flags)\n>  {\n> -       return hold_lock_file_for_update_timeout(lk, path, flags, 0);\n> +       return hold_lock_file_for_update_timeout(lk, path, flags, get_files_lock_timeout_ms() );\n>  }\n\nThis looks like it changes the default from 0 (\"try exactly once\") to\n100ms. Maybe we should stick with 0 for those who don't jump onto this\nnew config knob?\n\nMartin\n"},{"id":"386337","messageId":"CAN0heSprR-CMyc0qXvq5QKi4Qq5pqi+yvAU1=P+Cp+=Sg1My1g@mail.gmail.com","threadId":"52273","inReplyTo":"CAN0heSoW1GWEDxQN-d9bR4Vs5vzMaeDMar=QzShhcVNO1A0Sxg@mail.gmail.com","subject":"Re:","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2019-11-15T16:37:30Z","receivedAt":"2019-11-15T16:37:43Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"[Trying with another e-mail address for Martin Nicolay. Maybe the one\nfrom the in-body From header works better. wsmn.osm-gmbh.de couldn't be\nfound.]\n\nOn Fri, 15 Nov 2019 at 17:29, Martin Ågren <martin.agren@gmail.com> wrote:\n>\n> Hi Martin\n>\n> On Fri, 15 Nov 2019 at 17:17, Martin Nicolay <martin@wsmn.osm-gmbh.de> wrote:\n>\n> > While working with complex scripts invoking git multiple times my\n> > editor detects the changes and calls \"git status\". This leads to\n> > aborts in \"git-stash\". With this patch and an appropriate value\n> > core.fileslocktimeout this problem goes away.\n>\n> Are you able to patch your editor to call\n>   git --no-optional-locks status\n> instead? See the bottom of git-status(1) (\"BACKGROUND REFRESH\") for more\n> on this.\n>\n> > +long get_files_lock_timeout_ms(void)\n> > +{\n> > +       static int configured = 0;\n> > +\n> > +       /* The default timeout is 100 ms: */\n> > +       static int timeout_ms = 100;\n> > +\n> > +       if (!configured) {\n> > +               git_config_get_int(\"core.fileslocktimeout\", &timeout_ms);\n> > +               configured = 1;\n> > +       }\n> > +\n> > +       return timeout_ms;\n> > +}\n> > +\n>\n> > @@ -172,7 +174,7 @@ static inline int hold_lock_file_for_update(\n> >                 struct lock_file *lk, const char *path,\n> >                 int flags)\n> >  {\n> > -       return hold_lock_file_for_update_timeout(lk, path, flags, 0);\n> > +       return hold_lock_file_for_update_timeout(lk, path, flags, get_files_lock_timeout_ms() );\n> >  }\n>\n> This looks like it changes the default from 0 (\"try exactly once\") to\n> 100ms. Maybe we should stick with 0 for those who don't jump onto this\n> new config knob?\n>\n> Martin\n"}]}