From: Jeff King <peff@peff.net>
To: Tim Henigan <tim.henigan@gmail.com>
Cc: gitster@pobox.com, git@vger.kernel.org
Subject: Re: [PATCH v3] diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes
Date: Mon, 18 Jun 2012 15:45:30 -0400 [thread overview]
Message-ID: <20120618194530.GA10725@sigill.intra.peff.net> (raw)
In-Reply-To: <1340047704-8752-1-git-send-email-tim.henigan@gmail.com>
On Mon, Jun 18, 2012 at 03:28:24PM -0400, Tim Henigan wrote:
> When running 'git diff --quiet <file1> <file2>', if file1 or file2
> is outside the repository, it will exit(0) even if the files differ.
> It should exit(1) when they differ.
Can we explain in the commit message a bit about why the patch works? If
I hadn't just dug into this a few days ago, the patch would be somewhat
confusing. Maybe something like:
The problem comes from checking diff_options's found_changes member to
see whether any changes were found. This flag is set only when we
actually run xdiff and it finds a change. However, the diff machinery
will optimize out the actual xdiff call when it is not necessary
(i.e., when we are doing a straight byte-for-byte comparison and do
not care about the output). As a result, this flag was never set, and
we must check the HAS_CHANGES flag instead, just like the regular
index-aware diff code paths do.
I am also tempted to suggest that found_changes be renamed to
xdiff_found_changes or something similar, because it really is quite
misleading as-is.
> diff --git a/diff-no-index.c b/diff-no-index.c
> index f0b0010..b935d2a 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -273,5 +273,6 @@ void diff_no_index(struct rev_info *revs,
> * The return code for --no-index imitates diff(1):
> * 0 = no changes, 1 = changes, else error
> */
> - exit(revs->diffopt.found_changes);
> + int result = diff_result_code(&revs->diffopt, 0);
> + exit(result);
This is a declaration-after-statement, no? We try to stick to C89, which
does not allow this.
I don't see any reason why the extra variable could not be removed
entirely:
exit(diff_result_code(&revs->diffopt, 0));
-Peff
next prev parent reply other threads:[~2012-06-18 19:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-18 19:28 [PATCH v3] diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes Tim Henigan
2012-06-18 19:45 ` Jeff King [this message]
2012-06-18 20:09 ` Junio C Hamano
2012-06-19 13:05 ` Tim Henigan
2012-06-19 13:58 ` Jeff King
2012-06-19 16:47 ` Tim Henigan
2012-06-20 13:38 ` Tim Henigan
2012-06-20 16:06 ` Jeff King
2012-06-20 18:44 ` Junio C Hamano
2012-06-20 18:52 ` Jeff King
2012-06-20 19:21 ` Junio C Hamano
2012-06-21 15:07 ` Tim Henigan
2012-06-21 16:55 ` 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=20120618194530.GA10725@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=tim.henigan@gmail.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).