git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: "Alex Riesen" <raa.lkml@gmail.com>
Cc: "Junio C Hamano" <junkio@cox.net>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	git@vger.kernel.org
Subject: Re: [PATCH] Allow git-diff exit with codes similar to diff(1)
Date: Wed, 14 Mar 2007 01:58:43 -0700	[thread overview]
Message-ID: <7vfy88dwvw.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <81b0412b0703140119s4691211bw8a5ef3ba25c5cbdf@mail.gmail.com> (Alex Riesen's message of "Wed, 14 Mar 2007 09:19:52 +0100")

"Alex Riesen" <raa.lkml@gmail.com> writes:

> On 3/14/07, Junio C Hamano <junkio@cox.net> wrote:
> ...
>> Exiting with 0 for no-change, 1 for has-change and other value
>> for error is something that falls into the
>>
>>     "I wish if we did it from day one, but now many people's
>>     scripts depend on the behaviour, and heck we ourselves say
>>     that the right way to see if there is difference is to check
>>     if the output is an empty string (look at a few scripts of
>>     our own), so it would be a huge backward compatibility
>>     hassle"
>>
>> category.
>>
>> e.g.
>>
>> git-am.sh:      files=$(git-diff-index --cached --name-only HEAD) || exit
>> git-am.sh:      changed="$(git-diff-index --cached --name-only HEAD)"
>
> Isn't this crazy? Get the information and never really use it?

The information is used.

The first one says "see if we have already difference stashed in
the index for our own committing --- by the way, if there is an
error, do not do any further harm but error out".  If we do not
get an error, that line is followed by this:

	files=$(git-diff-index --cached --name-only HEAD) || exit
        if [ "$files" ]
        then
        	echo "Dirty index: ..." >&2
                exit 1
	fi

I've been telling you since the #git session that I know that is
*different* from how "diff" works, and I think everybody agrees
if we were doing git from scratch today we would have done exit
status with 0/1/other to signal no-change, have-diff and error.

But the established way for scripts that use plumbing is

 - to check error with $? (or ... || )
 - to check modified-or-not with output

and people who have been learning from the scripts (we used to
have lot more scripts) would have picked up that pattern.
That's why I already told you that --exit-status is the right
thing to do if we were doing it from scratch, but is a wrong
thing to do at this point.  Maybe in a release as big as 1.5.0
that we pre-announce a lot of interface changes.

In short, Linus is right in that the current exit code is not
useful to see what the end users are interested in (and they are
not in the business of debugging git, and diff would error out
only when the repository has problems, perhaps a corrupt object
or something like that).  But being not useful and being
currently not relied upon are two different things.

And I am being conservative, especially after a big release.

  reply	other threads:[~2007-03-14  8:58 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-14  0:17 [PATCH] Allow git-diff exit with codes similar to diff(1) Alex Riesen
2007-03-14  1:03 ` Johannes Schindelin
2007-03-14  1:20   ` Linus Torvalds
2007-03-14  1:23   ` Junio C Hamano
2007-03-14  1:13 ` Linus Torvalds
2007-03-14  1:18   ` Johannes Schindelin
2007-03-14  1:34     ` Linus Torvalds
2007-03-14  1:38       ` Johannes Schindelin
2007-03-14  8:37         ` Alex Riesen
2007-03-14 12:05           ` Johannes Schindelin
2007-03-14 12:26             ` Alex Riesen
2007-03-14 12:31               ` Johannes Schindelin
2007-03-15 12:49               ` Simon 'corecode' Schubert
2007-03-15 13:56                 ` Alex Riesen
2007-03-14  1:31   ` Junio C Hamano
2007-03-14  8:19     ` Alex Riesen
2007-03-14  8:58       ` Junio C Hamano [this message]
2007-03-14  9:06         ` Junio C Hamano
2007-03-14  9:07         ` Alex Riesen
2007-03-14  9:36           ` Junio C Hamano
2007-03-14  9:46             ` Alex Riesen
2007-03-14  4:56 ` Junio C Hamano
2007-03-14  8:28   ` Alex Riesen
2007-03-14  9:04     ` Junio C Hamano
2007-03-14 14:01       ` Alex Riesen
2007-03-14 16:14         ` Junio C Hamano
2007-03-14 16:33           ` Alex Riesen
2007-03-14 16:37             ` Junio C Hamano
2007-03-14 17:12               ` Alex Riesen
2007-03-14 17:20                 ` Junio C Hamano
2007-03-14 17:06             ` Junio C Hamano
2007-03-14 17:15               ` Alex Riesen

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=7vfy88dwvw.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=raa.lkml@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /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).