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

[PATCH] diff: disabled quick optimization with --find-copies-harder

From
René Scharfe <l.s.r@web.de>
Date
Nov 9, 2025, 12:11 UTC
Message-ID
<bbd1a371-b0a4-4412-b329-cb4d654a0ca8@web.de>
In-Reply-To
<CALnO6CBsj+aMvHJoUQ+LHAtXhcFhQeH8AuHyrX+rumur6MQQog@mail.gmail.com>

If --find-copies-harder is given, diff-lib.c::show_modified() queues even non-modified entries using diff_change() because we need them for copy detection. diff_change() sets flags.has_changes, though. If --quiet is also given this causes diff_can_quit_early() to declare we're done after seeing only the very first entry, which is way too soon. Disable this optimization in that case.

This issue is hidden without --no-ext-diff because then we set flags.diff_from_contents, which disables the optimization in a different way.

Reported-by: D. Ben Knoble <ben.knoble@gmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 diff.c              |  1 +
 t/t4007-rename-3.sh | 10 ++++++++++
 2 files changed, 11 insertions(+)
diff --git a/diff.c b/diff.c
index a1961526c0..84ac148c37 100644
--- a/diff.c
+++ b/diff.c
@@ -7188,6 +7188,7 @@ int diff_can_quit_early(struct diff_options *opt)
 {
 	return (opt->flags.quick &&
 		!opt->filter &&
+		!opt->flags.find_copies_harder &&
 		opt->flags.has_changes);
 }
 
diff --git a/t/t4007-rename-3.sh b/t/t4007-rename-3.sh
index e8faf0dd2e..3fc81bcd76 100755
--- a/t/t4007-rename-3.sh
+++ b/t/t4007-rename-3.sh
@@ -41,6 +41,16 @@ test_expect_success 'copy detection, cached' '
 	compare_diff_raw current expected
 '
 
+test_expect_success 'exit code of quiet copy detection' '
+	test_expect_code 1 \
+	git diff --quiet --cached --find-copies-harder $tree
+'
+
+test_expect_success 'exit code of quiet copy detection with --no-ext-diff' '
+	test_expect_code 1 \
+	git diff --quiet --cached --find-copies-harder --no-ext-diff $tree
+'
+
 # In the tree, there is only path0/COPYING.  In the cache, path0 and
 # path1 both have COPYING and the latter is a copy of path0/COPYING.
 # However when we say we care only about path1, we should just see
-- 
2.51.2
Previous: D. Ben KnobleNext: Phillip Wood
Message 4 of 15 in “diff --cached --no-ext-diff --find-copies-harder --quiet exits with wrong status code”
  1. D. Ben KnobleNov 8, 2025
  2. D. Ben KnobleNov 8, 2025
  3. D. Ben KnobleNov 8, 2025
  4. diff: disabled quick optimization with --find-copies-harderRené Scharfe, Nov 9, 2025
  5. Phillip WoodNov 9, 2025
  6. René ScharfeNov 9, 2025
  7. diff: disable rename detection with --quietRené Scharfe, Nov 9, 2025
  8. D. Ben KnobleNov 9, 2025
  9. René ScharfeNov 9, 2025
  10. D. Ben KnobleNov 10, 2025
  11. Phillip WoodNov 10, 2025
  12. Jeff KingNov 10, 2025
  13. Junio C HamanoNov 10, 2025
  14. René ScharfeNov 22, 2025
  15. Junio C HamanoNov 23, 2025

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.