]> git.ipfire.org Git - thirdparty/git.git/commit
diff: ensure consistent diff behavior with ignore options
authorLidong Yan <yldhome2d2@gmail.com>
Fri, 8 Aug 2025 03:30:19 +0000 (11:30 +0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Aug 2025 14:54:44 +0000 (07:54 -0700)
commitb55e6d36ebce69136559add8fffd1a65df231518
treeae8577be728c9ff7734cab37588b2434139b6958
parent866e6a391f466baeeb98bc585845ea638322c04b
diff: ensure consistent diff behavior with ignore options

In git-diff, options like `-w` and `-I<regex>`, two files are considered
equivalent under the specified "ignore" rules, even when they are not
bit-for-bit identical. For options like `--raw`, `--name-status`,
and `--name-only`, git-diff deliberately compares only the SHA values
to determine whether two files are equivalent, for performance reasons.
As a result, a file shown in `git diff --name-status` may not appear
in `git diff --patch`.

To quickly determine whether two files are equivalent, add a helper
function diff_flush_patch_quietly() in diff.c. Add `.dry_run` field in
`struct diff_options`. When `.dry_run` is true, builtin_diff() returns
immediately upon finding any change. Call diff_flush_patch_quietly()
to determine if we should flush `--raw`, `--name-only` or `--name-status`
output.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Lidong Yan <yldhome2d2@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
diff.h
t/t4013-diff-various.sh
t/t4015-diff-whitespace.sh
xdiff-interface.h