From: Lidong Yan <yldhome2d2@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, hi@arnes.space, michal@isc.org, peff@peff.net
Subject: Re: [PATCH v4] diff: ensure consistent diff behavior with ignore options
Date: Fri, 8 Aug 2025 09:46:13 +0800 [thread overview]
Message-ID: <AC10362A-5B05-47D0-98CF-DE6AD468F01D@gmail.com> (raw)
In-Reply-To: <xmqqldnult4w.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
>
> Lidong Yan <yldhome2d2@gmail.com> writes:
>
>> In git-diff, options like `-w` and `-I<regex>` require comparing
>> file contents to determine whether two files are the same, even when
>> their SHA values differ.
>
> Let's see if we can do something to clarify "the same" here.
> Perhaps
>
> ... two files are considered equivalent under the specified
> "ignore" rules, even when they are not bit-for-bit identical.
>
> Following the above, perhaps replace "identical" with "equivalent".
Equivalent seems to be a good definition, will replace.
>
> Also, ", Add helper" should be ", add a helper", as that comma is
> not finishing a sentence, hence the word that follows it is not at
> the beginning of the next sentence.
>
> Also the implementation details like the name of the .diff_options
> member and the name of the helper function have changed, and the
> proposed log message should be updated to match.
Will fix grammar errors and update log message.
>
> As the "dry_run" variable is used only once in this block, we
> probably do not want to add it.
Sure, will fix.
>
> We may want to leave a comment to explain why we ignore the error
> return from xdi_diff_outf()? Perhaps like below?
>
> if (o->dry_run)
> /*
> * Unlike the !dry_run case, we need to ignore the
> * return value from xdi_diff_outf() here, because
> * xdi_diff_outf() takes non-zero return from its
> * callback function as a sign of error and returns
> * early (which is why we return non-zer from our
> * callback, quick_consume()). Unfortunately,
> * xdi_diff_outf() signals an error by returning
> * non-zero.
> */
> xdi_diff_outf(&mf1, &mf2, NULL, quick_consume,
> &ecbdata, &xpp, &xecfg);
>
I think your comment is good enough so I will just copy it.
>
> In this codebase, these "original value of the variable X was this, we
> tentatively save that original value away, tweak the variable X to do
> something, and restore the saved value to variable X" variables are often
> called "saved_X".
Will rename.
>
> Perhaps use test_grep helper shell function, i.e.
>
> test_grep ! "file1" actual &&
I guess this is because test_grep has more useful debugging information.
Will replace.
>
>> + git rm -f file1
>
> Is this because later tests will break if you leave "file1" in the working
> tree and/or in the index? If so, we should use test_when_finished to make
> such a clean-up. If you insert
Yes, exactly.
>
> test_when_finished "git rm file1; rm -f file1" &&
>
> at the very beginning, before you create file1 with 1..50, when this test
> piece finishes executing (whether it completed successfully, or failed in
> the middle of the &&-chain), the specified command will run.
Early on Patrict suggested the same thing, I will read test_when_finish
to see how it works.
>
> On the other hand, if the later tests won't mind whether "file1" does or
> does not exist in the working tree and/or in the index, it is common to
> leave it behind without cleaning it. When running the test script with the
> "-i" option, i.e.
>
> $ sh t4013-diff-various.sh -i -v
Good thing to know. Just curious, I also found that running ./txxx -v causes
failed results and successful results to be mixed together. Do you usually
solve this by using awk to extract the error messages?
>
>> diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
>> index 52e3e476ff..e7be8c5a8f 100755
>> --- a/t/t4015-diff-whitespace.sh
>> +++ b/t/t4015-diff-whitespace.sh
>> @@ -11,7 +11,7 @@ test_description='Test special whitespace in diff engine.
>> . "$TEST_DIRECTORY"/lib-diff.sh
>>
>> for opt_res in --patch --quiet -s --stat --shortstat --dirstat=lines \
>> - --raw! --name-only! --name-status!
>> + --raw --name-only --name-status
>> do
>
> Wouldn't this make the "if the option is marked with !, tweak the test that
> notices these two equivalent paths are not-identical" extra code, whose
> beginning part we see below, unnecessary? The $expect_failure variable
> would always be an empty string, so "different but equivalent" test should
> see "git diff --exit-code" exit with status 0, right?
Yes, I will remove the optionally set expect_failure part.
Thank you very much for your review,
Lidong
next prev parent reply other threads:[~2025-08-08 2:47 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
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 [this message]
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=AC10362A-5B05-47D0-98CF-DE6AD468F01D@gmail.com \
--to=yldhome2d2@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hi@arnes.space \
--cc=michal@isc.org \
--cc=peff@peff.net \
/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).