git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes

From
Jeff King <peff@peff.net>
Date
Jun 18, 2012, 19:45 UTC
Message-ID
<20120618194530.GA10725@sigill.intra.peff.net>
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.

Show 11 quoted lines
> 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
Previous: Tim HeniganNext: Junio C Hamano
Message 2 of 13 in “diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changes”
  1. diff-no-index: exit(1) if 'diff --quiet <repo file> <external file>' finds changesTim Henigan, Jun 18, 2012
  2. Jeff KingJun 18, 2012
  3. Junio C HamanoJun 18, 2012
  4. Tim HeniganJun 19, 2012
  5. Jeff KingJun 19, 2012
  6. Tim HeniganJun 19, 2012
  7. Tim HeniganJun 20, 2012
  8. Jeff KingJun 20, 2012
  9. Junio C HamanoJun 20, 2012
  10. Jeff KingJun 20, 2012
  11. Junio C HamanoJun 20, 2012
  12. Tim HeniganJun 21, 2012
  13. Junio C HamanoJun 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.