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

Re: [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2011, 21:13 UTC
Message-ID
<7v62ri7oqm.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4D80EBC1.7010105@elegosoft.com>
Jakob Pfender <jpfender@elegosoft.com> writes:
Show 24 quoted lines
> Given the following status:
>
> 	$ git status -s
> 	 M bar
> 	UU foo
>
> There is an unexpected difference in the return code of git diff-files
> when used with --quiet as opposed to --exit-code:
>
> 	$ git diff-files --diff-filter=U --quiet
> 	$ echo $?
> 	0
>
> 	$ git diff-files --diff-filter=U --exit-code
> 	<usual output, lots of 0's and U<TAB>foo>
> 	$ echo $?
> 	1
>
> Notice the different return codes. Now, according to the documentation,
> --quiet implies --return-code. However, the return code of the former is
> clearly not correct if --return-code was supposed to be on.
>
> This patch removes a useless bit of code that caused the return codes to
> differ.
How did you determine it is "useless bit"?

The code notices that the caller, by specifying --quiet, does not want any details of the changes and instead wants to know if there is a change or not. And it breaks out of the loop because it already found what it wanted to know, namely, there is a change.

When you have a post-process filter (like -w or -S), the path we found to be different here may be uninteresting and there may be no output (hence we should exit with status 0). So it is true that the optimization you are removing needs to be disabled in _some_ situations, and the current code doesn't, and it needs fixing.

But is it a justifiable fix to disable the optimization for even the normal cases?

Show 20 quoted lines
> Signed-off-by: Jakob Pfender <jpfender@elegosoft.com>
> ---
>  diff-lib.c |    4 ----
>  1 files changed, 0 insertions(+), 4 deletions(-)
>
> diff --git a/diff-lib.c b/diff-lib.c
> index 392ce2b..a7aa42b 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -102,10 +102,6 @@ int run_diff_files(struct rev_info *revs,
> unsigned int option)
>  		int changed;
>  		unsigned dirty_submodule = 0;
>
> -		if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
> -			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
> -			break;
> -
>  		if (!ce_path_match(ce, revs->prune_data))
>  			continue;
Previous: Jakob PfenderNext: Junio C Hamano
Message 2 of 5 in “diff-lib.c: Fix diff-files --diff-filter --quiet exit code”
  1. diff-lib.c: Fix diff-files --diff-filter --quiet exit codeJakob Pfender, Mar 16, 2011
  2. Junio C HamanoMar 16, 2011
  3. Re* [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit codeJunio C Hamano, Mar 16, 2011
  4. diff --quiet: disable optimization when --diff-filter=X is usedJunio C Hamano, Mar 16, 2011
  5. Jakob PfenderMar 17, 2011

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.