Skip to content

Commit 0152831

Browse files
peffgitster
authored andcommitted
diff: drop save/restore of color_moved in dry-run mode
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 2e2d5ac (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 3da4413 (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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 57c2b6c commit 0152831

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

diff.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6839,11 +6839,9 @@ void diff_flush(struct diff_options *options)
68396839
* make sure diff_Flush_patch_quietly() to be silent.
68406840
*/
68416841
FILE *dev_null = NULL;
6842-
int saved_color_moved = options->color_moved;
68436842

68446843
if (options->flags.diff_from_contents) {
68456844
dev_null = xfopen("/dev/null", "w");
6846-
options->color_moved = 0;
68476845
}
68486846
for (i = 0; i < q->nr; i++) {
68496847
struct diff_filepair *p = q->queue[i];
@@ -6865,7 +6863,6 @@ void diff_flush(struct diff_options *options)
68656863
}
68666864
if (options->flags.diff_from_contents) {
68676865
fclose(dev_null);
6868-
options->color_moved = saved_color_moved;
68696866
}
68706867
separator++;
68716868
}
@@ -6925,7 +6922,6 @@ void diff_flush(struct diff_options *options)
69256922
diff_free_file(options);
69266923
options->file = xfopen("/dev/null", "w");
69276924
options->close_file = 1;
6928-
options->color_moved = 0;
69296925
for (i = 0; i < q->nr; i++) {
69306926
struct diff_filepair *p = q->queue[i];
69316927
if (check_pair_status(p))

0 commit comments

Comments
 (0)