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

[PATCH 2/4] diff: drop save/restore of color_moved in dry-run mode

From
Jeff King <peff@peff.net>
Date
Oct 24, 2025, 17:07 UTC
Message-ID
<20251024170753.GB2345184@coredump.intra.peff.net>
In-Reply-To
<20251024170522.GA2344972@coredump.intra.peff.net>

When running a dry-run content-level diff to check whether a "--quiet" diff has any changes, we have always unset the color_moved variable since the feature was added in 2e2d5ac184 (diff.c: color moved lines differently, 2017-06-30). The reasoning is not given explicitly there, but presumably the idea is that since color_moved requires a lot of extra computation to match lines but does not actually affect the found_changes flag, we want to skip it.

Later, in 3da4413dbc (diff: make sure the other caller of diff_flush_patch_quietly() is silent, 2025-10-22) we copied the same idea for other dry-run diffs.

But neither spot actually needs to reset this flag at all, because diff_flush_patch() will not ever compute color_moved. Nor could it, as it is only looking at a single file-pair, and we detect moves across files. So color_moved is checked only when we are actually doing real DIFF_FORMAT_PATCH output, and call diff_flush_patch_all_file_pairs().

So we can get rid of these extra lines to save and restore the color_moved flag without changing the behavior at all. (Note that there is no "restore" to drop for the second caller, as we know at that point we are not generating any output and can just leave the feature disabled).

Signed-off-by: Jeff King <peff@peff.net>
---
 diff.c | 4 ----
 1 file changed, 4 deletions(-)
diff --git a/diff.c b/diff.c
index 39029cc096..d83d898702 100644
--- a/diff.c
+++ b/diff.c
@@ -6839,11 +6839,9 @@ void diff_flush(struct diff_options *options)
 		 * make sure diff_Flush_patch_quietly() to be silent.
 		 */
 		FILE *dev_null = NULL;
-		int saved_color_moved = options->color_moved;
 
 		if (options->flags.diff_from_contents) {
 			dev_null = xfopen("/dev/null", "w");
-			options->color_moved = 0;
 		}
 		for (i = 0; i < q->nr; i++) {
 			struct diff_filepair *p = q->queue[i];
@@ -6865,7 +6863,6 @@ void diff_flush(struct diff_options *options)
 		}
 		if (options->flags.diff_from_contents) {
 			fclose(dev_null);
-			options->color_moved = saved_color_moved;
 		}
 		separator++;
 	}
@@ -6925,7 +6922,6 @@ void diff_flush(struct diff_options *options)
 		diff_free_file(options);
 		options->file = xfopen("/dev/null", "w");
 		options->close_file = 1;
-		options->color_moved = 0;
 		for (i = 0; i < q->nr; i++) {
 			struct diff_filepair *p = q->queue[i];
 			if (check_pair_status(p))
-- 
2.51.1.797.g1148beab57
Previous: Jeff KingNext: Jeff King
Message 3 of 7 in “diff dry-run cleanups”
  1. 0/4 diff dry-run cleanupsJeff King, Oct 24, 2025
  2. 1/4 diff: send external diff output to diff_options.fileJeff King, Oct 24, 2025
  3. 2/4 diff: drop save/restore of color_moved in dry-run modeJeff King, Oct 24, 2025
  4. 3/4 diff: replace diff_options.dry_run flag with NULL fileJeff King, Oct 24, 2025
  5. Junio C HamanoOct 24, 2025
  6. 4/4 diff: drop dry-run redirection to /dev/nullJeff King, Oct 24, 2025
  7. 5/4 diff: simplify run_external_diff() quiet logicJeff King, Oct 24, 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.