git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: Birk Tjelmeland <git@birktj.no>, git@vger.kernel.org
Subject: Re: [PATCH] stash: show error message when lockfile is present
Date: Sun, 07 Nov 2021 23:10:17 -0800	[thread overview]
Message-ID: <xmqqlf1zunqe.fsf@gitster.g> (raw)
In-Reply-To: <YYiXw41upJfPS7l0@nand.local> (Taylor Blau's message of "Sun, 7 Nov 2021 22:21:39 -0500")

Taylor Blau <me@ttaylorr.com> writes:

> I wonder if there are callers of repo_refresh_and_write_index() that
> don't want any errors reported. Not having thought about it too hard
> (much less looked through any of these callers), I would expect that
> having the choice to either error() or die() is something worth keeping.
> But I do not know if there are callers which want neither.
> ...
>>  add-interactive.c | 4 ++--
>>  add-patch.c       | 4 ++--
>>  builtin/am.c      | 2 +-
>>  builtin/merge.c   | 4 ++--
>>  builtin/stash.c   | 6 +++---
>>  cache.h           | 4 ++--
>>  read-cache.c      | 3 ++-
>>  7 files changed, 14 insertions(+), 13 deletions(-)

I think most of the changes in this patch, other than the ones to
builtin/stash.c, are unwanted, and I suspect what you wondered above
may be the same thing.  Take for example this hunk:

diff --git a/builtin/stash.c b/builtin/stash.c
index a0ccc8654d..977fcc4e40 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -501,7 +501,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
 	const struct object_id *bases[1];
 
 	read_cache_preload(NULL);
-	if (refresh_and_write_cache(REFRESH_QUIET, 0, 0))
+	if (refresh_and_write_cache(REFRESH_QUIET, 0, LOCK_REPORT_ON_ERROR, 0))
 		return -1;
 
 	if (write_cache_as_tree(&c_tree, 0, NULL))

Telling the function to be quiet and at the same time be noisy on
only one particular kind of error sounds somewhat strange.  I do not
think of any reason why we should believe that failing to lock will
be the only special kind of failure to be of interest to the users.

I would think the "fix" should look more like this:

 	read_cache_preload(NULL);
	if (refresh_and_write_cache(REFRESH_QUIET, 0, 0))
- 		return -1;
+ 		return error(_("failed to refresh the index"));

That is, tell the function that the caller will do the error
reporting (i.e. "QUIET") and do so.

Thanks.

  parent reply	other threads:[~2021-11-08  7:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07 21:30 [PATCH] stash: show error message when lockfile is present Birk Tjelmeland
2021-11-08  3:21 ` Taylor Blau
2021-11-08  4:15   ` Taylor Blau
2021-11-08  7:10   ` Junio C Hamano [this message]
2021-11-08 17:56     ` Taylor Blau
2021-11-08 19:05     ` Ævar Arnfjörð Bjarmason
2021-11-08 20:05       ` Junio C Hamano
2021-11-08 20:35         ` Birk Tjelmeland

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=xmqqlf1zunqe.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@birktj.no \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.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;
as well as URLs for NNTP newsgroup(s).