git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Martin Nicolay <m.nicolay@osm-ag.de>
To: git@vger.kernel.org
Cc: yuelinho777@gmail.com, gitster@pobox.com, mhagger@alum.mit.edu,
	pclouds@gmail.com
Subject: [PATCH] enable a timeout for hold_lock_file_for_update
Date: Mon, 18 Nov 2019 14:42:17 +0100	[thread overview]
Message-ID: <20191118134750.1901ED756F@wsmn.osm-gmbh.de> (raw)

The new funktion get_files_lock_timeout_ms reads the config
core.filesLockTimeout analog get_files_ref_lock_timeout_ms.

This value is used in hold_lock_file_for_update instead of the
fixed value 0.
---
While working with complex scripts invoking git multiple times
my editor (emacs with standard version control) detects the
changes and apparently calls "git status". This leads to abort
in "git stash". With this patch and an appropriate value
core.fileslocktimeout this problem goes away.

While it may be possible to patch the elisp scripts of emacs (and
all other similar callers) to call "git status" with
--no-optional-locks it seems to me a better approarch to solve this
problem at its root: calling hold_lock_file_for_update_timeout with
a timeout of 0 ms.

The implementation with the function get_files_lock_timeout_ms is 
adopted from a similar usage of get_files_ref_lock_timeout_ms.

BTW: is there a way to link this version of the patch to the previous
version to reduce the work for reviewers?

 Documentation/config/core.txt |  6 ++++++
 lockfile.c                    | 16 ++++++++++++++++
 lockfile.h                    |  4 +++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt
index 852d2ba37a..230ea02560 100644
--- a/Documentation/config/core.txt
+++ b/Documentation/config/core.txt
@@ -482,6 +482,12 @@ core.packedRefsTimeout::
 	all; -1 means to try indefinitely. Default is 1000 (i.e.,
 	retry for 1 second).
 
+core.filesLockTimeout::
+	The length of time, in milliseconds, to retry when trying to
+	lock an individual file. Value 0 means not to retry at
+	all; -1 means to try indefinitely. Default is 0 (i.e., don't
+	retry at all).
+
 core.pager::
 	Text viewer for use by Git commands (e.g., 'less').  The value
 	is meant to be interpreted by the shell.  The order of preference
diff --git a/lockfile.c b/lockfile.c
index 8e8ab4f29f..7301f393d6 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -145,6 +145,22 @@ static int lock_file_timeout(struct lock_file *lk, const char *path,
 	}
 }
 
+/*
+ * Get timeout for hold_lock_file_for_update.
+ */
+long get_files_lock_timeout_ms(void)
+{
+	static int configured = 0;
+
+	static int timeout_ms = 0; /* default */
+	if (!configured) {
+		git_config_get_int("core.fileslocktimeout", &timeout_ms);
+		configured = 1;
+	}
+
+	return timeout_ms;
+}
+
 void unable_to_lock_message(const char *path, int err, struct strbuf *buf)
 {
 	if (err == EEXIST) {
diff --git a/lockfile.h b/lockfile.h
index 9843053ce8..a0520e6a7b 100644
--- a/lockfile.h
+++ b/lockfile.h
@@ -163,6 +163,8 @@ int hold_lock_file_for_update_timeout(
 		struct lock_file *lk, const char *path,
 		int flags, long timeout_ms);
 
+long get_files_lock_timeout_ms(void);
+
 /*
  * Attempt to create a lockfile for the file at `path` and return a
  * file descriptor for writing to it, or -1 on error. The flags
@@ -172,7 +174,7 @@ static inline int hold_lock_file_for_update(
 		struct lock_file *lk, const char *path,
 		int flags)
 {
-	return hold_lock_file_for_update_timeout(lk, path, flags, 0);
+	return hold_lock_file_for_update_timeout(lk, path, flags, get_files_lock_timeout_ms() );
 }
 
 /*
-- 
2.13.7


             reply	other threads:[~2019-11-18 13:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18 13:42 Martin Nicolay [this message]
2019-11-18 17:57 ` [PATCH] enable a timeout for hold_lock_file_for_update Denton Liu
2019-11-19 14:56 ` [PATCH v3] lockfile: learn core.filesLockTimeout configuration Martin Nicolay
2019-11-20  2:38   ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2019-11-15 15:41 [PATCH] enable a timeout for hold_lock_file_for_update Martin Nicolay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191118134750.1901ED756F@wsmn.osm-gmbh.de \
    --to=m.nicolay@osm-ag.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    --cc=pclouds@gmail.com \
    --cc=yuelinho777@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).