Skip to content

Commit fa05236

Browse files
rscharfegitster
authored andcommitted
diff: disable rename detection with --quiet
Detecting renames and copies improves diff's output. This effort is wasted if we don't show any. Disable detection in that case. This actually fixes the error code when using the options --cached, --find-copies-harder, --no-ext-diff and --quiet together: run_diff_index() indirectly calls diff-lib.c::show_modified(), which queues even non-modified entries using diff_change() because we need them for copy detection. diff_change() sets flags.has_changes, though, which causes diff_can_quit_early() to declare we're done after seeing only the very first entry -- way too soon. Using --cached, --find-copies-harder and --quiet together without --no-ext-diff was not affected even before, as it causes the flag flags.diff_from_contents to be set, which disables the optimization in a different way. Reported-by: D. Ben Knoble <ben.knoble@gmail.com> Suggested-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f368df4 commit fa05236

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,6 +4965,8 @@ void diff_setup_done(struct diff_options *options)
49654965
if (options->flags.quick) {
49664966
options->output_format = DIFF_FORMAT_NO_OUTPUT;
49674967
options->flags.exit_with_status = 1;
4968+
options->detect_rename = 0;
4969+
options->flags.find_copies_harder = 0;
49684970
}
49694971

49704972
/*

t/t4007-rename-3.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ test_expect_success 'copy detection, cached' '
4141
compare_diff_raw current expected
4242
'
4343

44+
test_expect_success 'exit code of quiet copy detection' '
45+
test_expect_code 1 \
46+
git diff --quiet --cached --find-copies-harder $tree
47+
'
48+
49+
test_expect_success 'exit code of quiet copy detection with --no-ext-diff' '
50+
test_expect_code 1 \
51+
git diff --quiet --cached --find-copies-harder --no-ext-diff $tree
52+
'
53+
4454
# In the tree, there is only path0/COPYING. In the cache, path0 and
4555
# path1 both have COPYING and the latter is a copy of path0/COPYING.
4656
# However when we say we care only about path1, we should just see

0 commit comments

Comments
 (0)