Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, mail@thomasbachem.com,
	ttaylorr@openai.com
Subject: Re: [PATCH v2] maintenance: improve handling of lock acquisition failures
Date: Mon, 2 Nov 2026 13:51:23 +0100	[thread overview]
Message-ID: <auiHS_439EeHCGH6@pks.im> (raw)
In-Reply-To: <20261102122955.143018-2-pushkarkumarsingh1970@gmail.com>

On Mon, Nov 02, 2026 at 12:29:56PM +0000, Pushkar Singh wrote:
> Changes in v2:
> - Report lock acquisition failures for manual invocations as errors.
> - Print a warning for automatic invocations while preserving successful exit status.
> - Trace the reason for all automatic lock acquisition failures, not just EEXIST.
> - Add tests for automatic and manual lock failure behavior.

This really should be two patches now:

  - One patch that changes how we handle the failure to lock.

  - One patch that introduces your trace2 string.

One note though: please wait a bit before rerolling again so that others
can chime in first. You should ideally reroll at most once per day.

> diff --git a/builtin/gc.c b/builtin/gc.c
> index 81cecf6b6c..9223409750 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1402,6 +1402,8 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
>  	enum auto_gc_hook_result auto_gc_hook_result = AUTO_GC_HOOK_UNDECIDED;
>  
>  	if (repo_hold_lock_file_for_update(r, &lk, lock_path, LOCK_NO_DEREF) < 0) {
> +		int err = errno;
> +
>  		/*
>  		 * Another maintenance command is running.
>  		 *
> @@ -1409,11 +1411,29 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
>  		 * recursive process stack. Do not report an error in
>  		 * that case.
>  		 */
> -		if (!opts->auto_flag && !opts->quiet)
> -			warning(_("lock file '%s' exists, skipping maintenance"),
> -				lock_path);
> +		if (opts->auto_flag) {
> +			trace2_data_string("maintenance", r, "lock/skip",
> +				(err == EEXIST) ? "exists" : strerror(err));

Why don't you use strerror(3p) for both cases?

> +			if (!opts->quiet) {
> +				struct strbuf buf = STRBUF_INIT;
> +				unable_to_lock_message(lock_path, err, &buf);
> +				warning("%s", buf.buf);
> +				strbuf_release(&buf);
> +			}
> +
> +			free(lock_path);
> +			return 0;
> +		}
> +
> +		if (!opts->quiet) {
> +			struct strbuf buf = STRBUF_INIT;
> +			unable_to_lock_message(lock_path, err, &buf);
> +			error("%s", buf.buf);
> +			strbuf_release(&buf);

There's some duplication here with the auto-flag case. Can't we
deduplicate that?

Thanks!

Patrick

      reply	other threads:[~2026-11-02 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 10:59 [PATCH] maintenance: trace when auto maintenance skips due to lock Pushkar Singh
2026-11-02  8:29 ` Patrick Steinhardt
2026-11-02 12:23   ` Pushkar Singh
2026-11-02 12:29 ` [PATCH v2] maintenance: improve handling of lock acquisition failures Pushkar Singh
2026-11-02 12:51   ` Patrick Steinhardt [this message]

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=auiHS_439EeHCGH6@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mail@thomasbachem.com \
    --cc=pushkarkumarsingh1970@gmail.com \
    --cc=ttaylorr@openai.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox