Re: [PATCH v2] diff: ensure consistent diff behavior with -I<regex> across output formats
- From
Lidong Yan <yldhome2d2@gmail.com>
- Date
- Aug 4, 2025, 01:56 UTC
- Message-ID
- <B1F1EBB7-1824-4776-B8B0-B557114546DB@gmail.com>
- In-Reply-To
- <xmqqfre7ex8x.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> > Lidong Yan <yldhome2d2@gmail.com> writes: > >> `git diff -I<regex>` option is inconsistently applied across various >> output formats. In some cases, files would appear in the `--name-only` >> output but not in the accompanying `--stat` or `-p` outputs, despite >> the user explicitly requesting to ignore certain changes using >> `-I<regex>`. Not only for `-I<regex>`, but this inconsistency also >> exists for other output formats that have `.diff_from_content` set >> (e.g. `-w`, `--ignore-space-at-eol` and `--ignore-space-change`). > > Perhaps the above (and code, like the name of the helper functions > and possibly the name of the new file) should be updated to place > much stress on -I<regex>, as "ignore-regex" is not any more special > than other things that flips .diff_from_content bit in this new > iteration of the patch.
I will replace ‘-I<regex>’ to ‘options that set .diff_from_content’.
Show 5 quoted lines
> > I do not quite get why ignore_match() has to know so much about how > the real code in diff.c that implements -I<regex> works, compared to > the illustration of "here is how to do it" Peff posted, though. It > somehow feels too much duplicated code.
I did copy some code from diffcore-pickaxe.c. I will use Peff's code in the next patch and try to refactor diff_flush() to make the code simpler. Though the reason I match the regular expression in ignore_match() is that I want to return early as soon as an unmatched change is found. And indeed, it's not worth writing the duplicated code for this unknown performance benefit.
Thanks, Lidong