git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code
@ 2011-03-16 16:56 Jakob Pfender
  2011-03-16 21:13 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jakob Pfender @ 2011-03-16 16:56 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jens.Lehmann, johannes.schindelin

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.

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;

-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code
  2011-03-16 16:56 [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code Jakob Pfender
@ 2011-03-16 21:13 ` Junio C Hamano
  2011-03-16 22:21   ` Re* " Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-03-16 21:13 UTC (permalink / raw)
  To: Jakob Pfender; +Cc: git, Jens.Lehmann, johannes.schindelin

Jakob Pfender <jpfender@elegosoft.com> writes:

> 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?

> 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;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re* [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code
  2011-03-16 21:13 ` Junio C Hamano
@ 2011-03-16 22:21   ` Junio C Hamano
  2011-03-16 23:09     ` [PATCH] diff --quiet: disable optimization when --diff-filter=X is used Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-03-16 22:21 UTC (permalink / raw)
  To: Jakob Pfender; +Cc: git, Jens.Lehmann, johannes.schindelin

Junio C Hamano <gitster@pobox.com> writes:

> 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.

What I was hinting at was perhaps to do it something like the attached; it
is totally untested, and merely for illustration purposes.

I didn't even try to cover -w/-S which may or may not involve inspecting
DIFF_FROM_CONTENTS bit in the options.

 diff-lib.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index 1e22992..2870de4 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -103,7 +103,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		unsigned dirty_submodule = 0;
 
 		if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
-			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
+		    !revs->diffopt.filter &&
+		    DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
 			break;
 
 		if (!ce_path_match(ce, &revs->prune_data))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] diff --quiet: disable optimization when --diff-filter=X is used
  2011-03-16 22:21   ` Re* " Junio C Hamano
@ 2011-03-16 23:09     ` Junio C Hamano
  2011-03-17 11:15       ` Jakob Pfender
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-03-16 23:09 UTC (permalink / raw)
  To: git; +Cc: Jakob Pfender, Jens.Lehmann, johannes.schindelin

The code notices that the caller does not want any detail of the changes
and only wants to know if there is a change or not by specifying --quiet.
And it breaks out of the loop when it knows it already found any change.

When you have a post-process filter (e.g. --diff-filter), however, the
path we found to be different in the previous round and set HAS_CHANGES
bit may end up being uninteresting, and there may be no output at the end.
The optimization needs to be disabled for such case.

Note that the f245194 (diff: change semantics of "ignore whitespace"
options, 2009-05-22) already disables this optimization by refraining
from setting HAS_CHANGES when post-process filters that need to inspect
the contents of the files (e.g. -S, -w) in diff_change() function.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * This time with tests, on top of 90b1994 (diff: Rename QUIET internal
   option to QUICK, 2009-05-23), which was the last commit in the series
   that introduced the incorrect optimization in the first place.

   Note that the test script was renamed to t/t4040 in today's codebase,
   but it merges cleanly.

 diff-lib.c                   |    3 ++-
 t/t4037-whitespace-status.sh |    7 +++++++
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index b7813af..bfa6503 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -74,7 +74,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		int changed;
 
 		if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
-			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
+		    !revs->diffopt.filter &&
+		    DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
 			break;
 
 		if (!ce_path_match(ce, revs->prune_data))
diff --git a/t/t4037-whitespace-status.sh b/t/t4037-whitespace-status.sh
index a30b03b..abc4934 100755
--- a/t/t4037-whitespace-status.sh
+++ b/t/t4037-whitespace-status.sh
@@ -60,4 +60,11 @@ test_expect_success 'diff-files -b -p --exit-code' '
 	git diff-files -b -p --exit-code
 '
 
+test_expect_success 'diff-files --diff-filter --quiet' '
+	git reset --hard &&
+	rm a/d &&
+	echo x >>b/e &&
+	test_must_fail git diff-files --diff-filter=M --quiet
+'
+
 test_done
-- 
1.7.4.1.430.g5aa4d

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] diff --quiet: disable optimization when --diff-filter=X is used
  2011-03-16 23:09     ` [PATCH] diff --quiet: disable optimization when --diff-filter=X is used Junio C Hamano
@ 2011-03-17 11:15       ` Jakob Pfender
  0 siblings, 0 replies; 5+ messages in thread
From: Jakob Pfender @ 2011-03-17 11:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jens.Lehmann, johannes.schindelin



On 03/17/2011 12:09 AM, Junio C Hamano wrote:
> The code notices that the caller does not want any detail of the changes
> and only wants to know if there is a change or not by specifying --quiet.
> And it breaks out of the loop when it knows it already found any change.
>
> When you have a post-process filter (e.g. --diff-filter), however, the
> path we found to be different in the previous round and set HAS_CHANGES
> bit may end up being uninteresting, and there may be no output at the end.
> The optimization needs to be disabled for such case.
>
> Note that the f245194 (diff: change semantics of "ignore whitespace"
> options, 2009-05-22) already disables this optimization by refraining
> from setting HAS_CHANGES when post-process filters that need to inspect
> the contents of the files (e.g. -S, -w) in diff_change() function.

That fixes it nicely, thank you.

>
> Signed-off-by: Junio C Hamano<gitster@pobox.com>
> ---
>
>   * This time with tests, on top of 90b1994 (diff: Rename QUIET internal
>     option to QUICK, 2009-05-23), which was the last commit in the series
>     that introduced the incorrect optimization in the first place.
>
>     Note that the test script was renamed to t/t4040 in today's codebase,
>     but it merges cleanly.
>
>   diff-lib.c                   |    3 ++-
>   t/t4037-whitespace-status.sh |    7 +++++++
>   2 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/diff-lib.c b/diff-lib.c
> index b7813af..bfa6503 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -74,7 +74,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
>   		int changed;
>
>   		if (DIFF_OPT_TST(&revs->diffopt, QUICK)&&
> -			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
> +		    !revs->diffopt.filter&&
> +		    DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
>   			break;
>
>   		if (!ce_path_match(ce, revs->prune_data))
> diff --git a/t/t4037-whitespace-status.sh b/t/t4037-whitespace-status.sh
> index a30b03b..abc4934 100755
> --- a/t/t4037-whitespace-status.sh
> +++ b/t/t4037-whitespace-status.sh
> @@ -60,4 +60,11 @@ test_expect_success 'diff-files -b -p --exit-code' '
>   	git diff-files -b -p --exit-code
>   '
>
> +test_expect_success 'diff-files --diff-filter --quiet' '
> +	git reset --hard&&
> +	rm a/d&&
> +	echo x>>b/e&&
> +	test_must_fail git diff-files --diff-filter=M --quiet
> +'
> +
>   test_done

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-17 11:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-16 16:56 [PATCH] diff-lib.c: Fix diff-files --diff-filter --quiet exit code Jakob Pfender
2011-03-16 21:13 ` Junio C Hamano
2011-03-16 22:21   ` Re* " Junio C Hamano
2011-03-16 23:09     ` [PATCH] diff --quiet: disable optimization when --diff-filter=X is used Junio C Hamano
2011-03-17 11:15       ` Jakob Pfender

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).