From: Junio C Hamano <gitster@pobox.com>
To: Lidong Yan <yldhome2d2@gmail.com>
Cc: git@vger.kernel.org, hi@arnes.space, michal@isc.org, peff@peff.net
Subject: Re: [PATCH v3] diff: ensure consistent diff behavior with ignore options
Date: Wed, 06 Aug 2025 13:56:28 -0700 [thread overview]
Message-ID: <xmqqpld8tbib.fsf@gitster.g> (raw)
In-Reply-To: <20250806123306.25532-1-yldhome2d2@gmail.com> (Lidong Yan's message of "Wed, 6 Aug 2025 20:33:06 +0800")
Lidong Yan <yldhome2d2@gmail.com> writes:
> +static int quick_consume(void *priv, char *line, unsigned long len)
> +{
> + struct emit_callback *ecbdata = priv;
> + struct diff_options *o = ecbdata->opt;
> +
> + o->found_changes = 1;
> + return 1;
> +}
"make DEVELOPER=YesPlease" would not be very happy, without
-static int quick_consume(void *priv, char *line, unsigned long len)
+static int quick_consume(void *priv, char *line UNUSED, unsigned long len UNUSED)
> +/* return 1 if any change is found; otherwise, return 0 */
> +static int diff_flush_patch_quiet(struct diff_filepair *p, struct diff_options *o)
> +{
> + int diff_opt = o->diff_optimize;
> + int found_changes = o->found_changes;
> + int ret;
> +
> + o->diff_optimize = DIFF_OPT_DRY_RUN;
> + o->found_changes = 0;
> + diff_flush_patch(p, o);
> + ret = o->found_changes;
> + o->diff_optimize = diff_opt;
> + o->found_changes |= found_changes;
> + return ret;
> +}
> static void diff_flush_stat(struct diff_filepair *p, struct diff_options *o,
> struct diffstat_t *diffstat)
> {
> @@ -6778,7 +6810,19 @@ void diff_flush(struct diff_options *options)
> DIFF_FORMAT_CHECKDIFF)) {
> for (i = 0; i < q->nr; i++) {
> struct diff_filepair *p = q->queue[i];
> - if (check_pair_status(p))
> + int need_flush = 1;
> +
> + if (!check_pair_status(p))
> + continue;
> +
> + if (options->flags.diff_from_contents) {
> + if (diff_flush_patch_quiet(p, options))
> + need_flush = 1;
> + else
> + need_flush = 0;
> + }
> +
> + if (need_flush)
> flush_one_pair(p, options);
> }
I am having a hard time understanding the logic in this loop. Is it
equivalent to the following loop, and ...
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (!check_pair_status(p))
continue;
if (options->flags.diff_from_contents &&
!diff_flush_patch_quietly(p, options))
continue; /* no changes */
flush_one_pair(p, options);
}
... if so, isn't the above rewrite easier to follow?
The idea is that we cannot do anything with DIFF_STATUS_UNKNOWN
pairs (hence we continue), and when we are filtering output by the
"has the pair changed in a way that the user cares about?" criteria,
we check with flush_patch_quietly, and if there is no change worth
talking about, we do not do anything with such a pair, either.
Only when these conditions are not met, we call flush_one_pair() to
show the name or name status or whatever.
> separator++;
> @@ -6831,19 +6875,10 @@ void diff_flush(struct diff_options *options)
> if (output_format & DIFF_FORMAT_NO_OUTPUT &&
> options->flags.exit_with_status &&
> options->flags.diff_from_contents) {
> - /*
> - * run diff_flush_patch for the exit status. setting
> - * options->file to /dev/null should be safe, because we
> - * aren't supposed to produce any output anyway.
> - */
> - 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))
> - diff_flush_patch(p, options);
> + diff_flush_patch_quiet(p, options);
> if (options->found_changes)
> break;
> }
It is a natural consequence of having a helper that does the "quiet"
thing that we can now lose the /dev/null hack, which is very nice.
Overall, the changes are easy to follow and look good.
Thanks.
next prev parent reply other threads:[~2025-08-06 20:56 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 5:47 git-diff: --ignore-matching-lines has no effect on the output when --name-only is used hi
2025-07-23 8:00 ` Lidong Yan
2025-07-23 17:09 ` Junio C Hamano
2025-07-24 1:56 ` Lidong Yan
2025-07-24 2:16 ` Eric Sunshine
2025-07-24 3:38 ` Lidong Yan
2025-07-25 6:00 ` hi
2025-07-25 6:06 ` hi
2025-07-25 6:46 ` Lidong Yan
2025-07-25 8:08 ` hi
2025-07-25 11:11 ` Jeff King
2025-07-25 15:20 ` Junio C Hamano
2025-07-29 8:18 ` [PATCH] diff: ensure consistent diff behavior with -I<regex> across output formats Lidong Yan
2025-07-30 0:28 ` Junio C Hamano
2025-08-02 10:22 ` Jeff King
2025-08-03 8:42 ` Lidong Yan
2025-08-03 15:43 ` Junio C Hamano
2025-08-04 4:39 ` Junio C Hamano
2025-08-04 12:42 ` Jeff King
2025-08-03 14:51 ` [PATCH v2] " Lidong Yan
2025-08-04 0:39 ` Junio C Hamano
2025-08-04 1:56 ` Lidong Yan
2025-08-04 4:36 ` Junio C Hamano
2025-08-05 9:23 ` Lidong Yan
2025-08-05 16:11 ` Junio C Hamano
2025-08-06 12:33 ` [PATCH v3] diff: ensure consistent diff behavior with ignore options Lidong Yan
2025-08-06 17:35 ` Junio C Hamano
2025-08-07 1:23 ` Lidong Yan
2025-08-06 20:56 ` Junio C Hamano [this message]
2025-08-07 1:39 ` Lidong Yan
2025-08-07 2:06 ` [PATCH v4] " Lidong Yan
2025-08-07 21:27 ` Junio C Hamano
2025-08-08 1:46 ` Lidong Yan
2025-08-08 3:30 ` [PATCH v5] " Lidong Yan
2025-10-16 14:55 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqpld8tbib.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=hi@arnes.space \
--cc=michal@isc.org \
--cc=peff@peff.net \
--cc=yldhome2d2@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).