public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Paulo Casaretto via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Taylor Blau" <me@ttaylorr.com>,
	"D. Ben Knoble" <ben.knoble@gmail.com>,
	"Torsten Bögershausen" <tboegi@web.de>,
	"Jeff King" <peff@peff.net>,
	"Paulo Casaretto (Shopify)" <paulo.casaretto@shopify.com>,
	"Patrick Steinhardt" <ps@pks.im>,
	"Paulo Casaretto" <pcasaretto@gmail.com>
Subject: Re: [PATCH v5] lockfile: add PID file for debugging stale locks
Date: Tue, 20 Jan 2026 12:02:37 -0800	[thread overview]
Message-ID: <xmqqjyxcyrvm.fsf@gitster.g> (raw)
In-Reply-To: <pull.2011.v5.git.1768933954845.gitgitgadget@gmail.com> (Paulo Casaretto via GitGitGadget's message of "Tue, 20 Jan 2026 18:32:34 +0000")

"Paulo Casaretto via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Existing PID files are always read when displaying lock errors,
> regardless of the core.lockfilePid setting. This ensures helpful
> diagnostics even when the feature was previously enabled and later
> disabled.

> +core.lockfilePid::
> +	If true, Git will create a PID file alongside lock files. When a

Hmph, are there cases where a single process grab two more more lock
files and a single PID file helps identify who holds these multiple
lock files?  I somehow had an impression that with the configuration
on, we create an extra PID file for each lock file we create.

> diff --git a/builtin/commit.c b/builtin/commit.c
> index 0243f17d53..4378256fa5 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -539,8 +539,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
>  
>  	path = repo_git_path(the_repository, "next-index-%"PRIuMAX,
>  			     (uintmax_t) getpid());
> -	hold_lock_file_for_update(&false_lock, path,
> -				  LOCK_DIE_ON_ERROR);
> +	hold_lock_file_for_update(&false_lock, path, LOCK_DIE_ON_ERROR);

A change that is not necessary/essential for the purpose of the
topic?

> diff --git a/builtin/gc.c b/builtin/gc.c
> index 92c6e7b954..1dcc8dd550 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -748,8 +748,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
>  		xsnprintf(my_host, sizeof(my_host), "unknown");
>  
>  	pidfile_path = repo_git_path(the_repository, "gc.pid");
> -	fd = hold_lock_file_for_update(&lock, pidfile_path,
> -				       LOCK_DIE_ON_ERROR);
> +	fd = hold_lock_file_for_update(&lock, pidfile_path, LOCK_DIE_ON_ERROR);

Likewise?

> @@ -1016,8 +1015,7 @@ int cmd_gc(int argc,
>  
>  	if (daemonized) {
>  		char *path = repo_git_path(the_repository, "gc.log");
> -		hold_lock_file_for_update(&log_lock, path,
> -					  LOCK_DIE_ON_ERROR);
> +		hold_lock_file_for_update(&log_lock, path, LOCK_DIE_ON_ERROR);

Likewise?

> +static void get_pid_path(struct strbuf *out, const char *path)
> +{
> +	strbuf_addstr(out, path);
> +	strbuf_addstr(out, LOCK_PID_INFIX);
> +	strbuf_addstr(out, LOCK_SUFFIX);
> +}

If we get rid of LOCK_PID_INFIX, and instead did

    #define PID_LOCK_SUFFIX "~pid.lock"

wouldn't it make the overall patch simpler?  I do not see any code
that uses LOCK_PID_INFIX independently (other than the above code,
obviously).  Then get_pid_path() would become

        static void get_pid_path(struct strbuf *out, const char *path)
        {
                strbuf_addstr(out, path);
                strbuf_addstr(out, PID_LOCK_SUFFIX);
        }

While at it, we can also lose LOCK_PID_INFIX_LEN that nobody uses ...

> @@ -127,6 +128,22 @@ struct lock_file {
>  #define LOCK_SUFFIX ".lock"
>  #define LOCK_SUFFIX_LEN 5
>  
> +/*
> + * PID file naming: for a lock file "foo.lock", the PID file is "foo~pid.lock".
> + * The tilde is forbidden in refnames and allowed in Windows filenames, avoiding
> + * namespace collisions (e.g., refs "foo" and "foo~pid" cannot both exist).
> + */
> +#define LOCK_PID_INFIX "~pid"
> +#define LOCK_PID_INFIX_LEN 4

... from here.

> +
> +/* Maximum length for PID file content */
> +#define LOCK_PID_MAXLEN 32

This is used as the last parameter to strbuf_read_file(), which does
not mean we stop reading after reaching this length at all, so the
name of this constant is very misleading.  We only read the file in
the error code path so there isn't much point in trying to optimize
reading from these files too heavily.  I'd suggest getting rid of
this constant, and passing 0 to the function instead to signal "we
are willing to take the default given by the strbuf subsystem".


  reply	other threads:[~2026-01-20 20:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 15:07 [PATCH] lockfile: add PID file for debugging stale locks Paulo Casaretto via GitGitGadget
2025-12-02 22:29 ` D. Ben Knoble
2025-12-03 19:48 ` Torsten Bögershausen
2025-12-03 21:16 ` Jeff King
2025-12-03 22:21   ` Junio C Hamano
2025-12-03 22:32     ` Jeff King
2025-12-03 23:19   ` Taylor Blau
2025-12-05 11:03     ` Patrick Steinhardt
2025-12-05 18:46     ` Jeff King
2025-12-03 23:39 ` Taylor Blau
2025-12-17 18:59 ` [PATCH v2] " Paulo Casaretto via GitGitGadget
2025-12-18  0:32   ` Junio C Hamano
2025-12-18  0:47   ` Junio C Hamano
2025-12-18  1:33     ` Junio C Hamano
2025-12-18  3:38   ` Ben Knoble
2025-12-18  8:07   ` Patrick Steinhardt
2025-12-24 12:24   ` [PATCH v3] " Paulo Casaretto via GitGitGadget
2025-12-25  0:01     ` Junio C Hamano
2025-12-27  7:50     ` Jeff King
2026-01-05 12:23       ` Patrick Steinhardt
2026-01-07 16:45     ` [PATCH v4] " Paulo Casaretto via GitGitGadget
2026-01-08  1:59       ` Junio C Hamano
2026-01-08 14:19         ` D. Ben Knoble
2026-01-20 18:32       ` [PATCH v5] " Paulo Casaretto via GitGitGadget
2026-01-20 20:02         ` Junio C Hamano [this message]
2026-01-21  7:13         ` Jeff King
2026-01-21  8:13           ` Eric Sunshine
2026-01-21 10:14             ` Johannes Sixt
2026-01-21 16:39             ` Jeff King
2026-01-21 18:55               ` Junio C Hamano
2026-01-21 19:53                 ` Jeff King
2026-01-21 16:23           ` Junio C Hamano
2026-01-22 19:23         ` [PATCH v6] " Paulo Casaretto via GitGitGadget
2026-01-22 20:17           ` Junio C Hamano
2026-02-06 16:27           ` Patrick Steinhardt
2026-02-06 19:31             ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=xmqqjyxcyrvm.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=me@ttaylorr.com \
    --cc=paulo.casaretto@shopify.com \
    --cc=pcasaretto@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=tboegi@web.de \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox