git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Cc: git@vger.kernel.org, Alban Gruin <alban.gruin@gmail.com>,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH] sequencer: rectify empty hint in call of require_clean_work_tree()
Date: Thu, 27 Apr 2023 14:13:29 -0700	[thread overview]
Message-ID: <xmqqmt2thvuu.fsf@gitster.g> (raw)
In-Reply-To: <ZEorMhPZRL/w4yKM@ugly> (Oswald Buddenhagen's message of "Thu, 27 Apr 2023 09:58:42 +0200")

Oswald Buddenhagen <oswald.buddenhagen@gmx.de> writes:

> ping!
>
> On Thu, Mar 23, 2023 at 05:22:34PM +0100, Oswald Buddenhagen wrote:
>>The canonical way to represent "no error hint" is making it null, which
>>shortcuts the error() call altogether.

I won't repeat what Peff already said on another ping! we saw
recently on the list.

The call to require_clean_work_tree() with "" hint existed ever
since this part of the "rebase" machinery was rewritten in C by
b97e1873 (rebase -i: rewrite complete_action() in C, 2018-08-28).
I added the author of that change to the Cc: list.

The original implementation of require_clean_work_tree looked like
this:

require_clean_work_tree () {
	git rev-parse --verify HEAD >/dev/null || exit 1
	git update-index -q --ignore-submodules --refresh
	err=0

	if ! git diff-files --quiet --ignore-submodules
	then
		...
		err=1
	fi

	if ! git diff-index --cached --quiet --ignore-submodules HEAD --
	then
		...
		err=1
	fi

	if test $err = 1
	then
		test -n "$2" && echo "$2" >&2
		exit 1
	fi
}

I.e. the second argument, "hint", is shown only when it was a
non-empty string.  It did not add "error:" prefix before the
message.

In contrast, this is what wt-status.c has:

int require_clean_work_tree(struct repository *r,
			    const char *action,
			    const char *hint,
			    int ignore_submodules,
			    int gently)
{
	struct lock_file lock_file = LOCK_INIT;
	int err = 0, fd;

	...
	if (err) {
		if (hint)
			error("%s", hint);
		if (!gently)
			exit(128);
	}

	return err;
}

Arguably, using error() as a replacement for 'echo "$2" >&2' was a
sloppy conversion made back in ea63b393 (pull: make code more
similar to the shell script again, 2016-10-07), but I suspect that
in-tree callers that do have something to say, and the end-users who
are used to see the messages these callers produce, expect to see
the "error:" prefix these days, so it needs further study if we
wanted to "fix" the misuse of error() there.  In any case, the
observation that motivated your patch is not error() vs fputs().

For squelching a useless "hint" that is empty (other than that
mistaken "error:" prefix), however, I think you can and should do
better than replacing "" with NULL on the callers' side.  As we can
see from the comparison between the original, scripted version and
the verison in C that is in wt-status.c of require_clean_work_tree,
checking for NULL-ness of hint is another misconversion made when
it was rewritten in C.

I think the right fix would be more like the attached patch, which
will fix any other callsites that pass "" at the same time.  Of
course, you can fix the callers on top, but that is secondary.

 wt-status.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git i/wt-status.c w/wt-status.c
index 97b9c1c035..2b6dc4d6ac 100644
--- i/wt-status.c
+++ w/wt-status.c
@@ -2650,7 +2650,7 @@ int require_clean_work_tree(struct repository *r,
 	}
 
 	if (err) {
-		if (hint)
+		if (hint && *hint)
 			error("%s", hint);
 		if (!gently)
 			exit(128);


  reply	other threads:[~2023-04-27 21:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 16:22 [PATCH] sequencer: rectify empty hint in call of require_clean_work_tree() Oswald Buddenhagen
2023-04-27  7:58 ` Oswald Buddenhagen
2023-04-27 21:13   ` Junio C Hamano [this message]
2023-04-27 22:33     ` Oswald Buddenhagen
2023-05-02 18:57       ` Felipe Contreras
2023-05-03  7:15         ` Oswald Buddenhagen
2023-08-07 17:09 ` [PATCH v2] " Oswald Buddenhagen
2023-08-07 20:19   ` Junio C Hamano
2023-08-09 17:15     ` [PATCH v3] " Oswald Buddenhagen
2023-08-09 21:44       ` Junio C Hamano
2023-08-10 11:24         ` Oswald Buddenhagen
2023-08-10 16:04           ` Junio C Hamano
2023-08-24 15:00           ` [PATCH v4] " Oswald Buddenhagen
2023-08-24 15:59             ` Junio C Hamano
2023-08-09  1:24   ` [PATCH v2] " 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

  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=xmqqmt2thvuu.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=alban.gruin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=oswald.buddenhagen@gmx.de \
    --cc=phillip.wood@dunelm.org.uk \
    /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).