Skip to content

Commit 2cfe8a6

Browse files
committed
diff --quiet: disable optimization when --diff-filter=X is used
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 <[email protected]>
1 parent 90b1994 commit 2cfe8a6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

diff-lib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
7474
int changed;
7575

7676
if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
77-
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
77+
!revs->diffopt.filter &&
78+
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
7879
break;
7980

8081
if (!ce_path_match(ce, revs->prune_data))

t/t4037-whitespace-status.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ test_expect_success 'diff-files -b -p --exit-code' '
6060
git diff-files -b -p --exit-code
6161
'
6262

63+
test_expect_success 'diff-files --diff-filter --quiet' '
64+
git reset --hard &&
65+
rm a/d &&
66+
echo x >>b/e &&
67+
test_must_fail git diff-files --diff-filter=M --quiet
68+
'
69+
6370
test_done

0 commit comments

Comments
 (0)