From: Junio C Hamano <gitster@pobox.com>
To: Johannes Altmanninger <aclopte@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Unexpected behavior on diff -I<regex> --name-only
Date: Mon, 14 Dec 2020 11:49:06 -0800 [thread overview]
Message-ID: <xmqqeejsdv7x.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201214190054.lrdllbpf6jfrz573@gmail.com> (Johannes Altmanninger's message of "Mon, 14 Dec 2020 20:00:54 +0100")
Johannes Altmanninger <aclopte@gmail.com> writes:
> Since v2.28.0-2-g296d4a94e7 (diff: add -I<regex> that ignores matching changes)
> diff -I<regex> can be used to suppress hunks of only matching lines.
> This interacts in a surprising way with --name-only, which lists
> all changed files, regardless of whether they are filtered out by -I<regex>:
>
> git diff HEAD~ -I '' # always empty
> git diff HEAD~ -I '' --name-only # not empty, "-I" does nothing
>
> It could be nice to only show names of files with matching hunks
> (or reject this combination of options?).
Interesting.
This is not a new issue limited to -I at all. If you did this:
$ echo "hello" >world
$ git add world ; git commit -m 'add world'
$ echo " hello" >world ; git add world
$ git diff -w --cached
$ git diff --name-only --cached
world
$ git diff --name-only -w --cached
world
I think "--name-only", and perhaps other options, has too aggressive
an optimization that takes advantage of the fact that we can tell if
a path has changed or not without looking at the contents at all by
looking at the object name recorded. That optimization may have
been valid until many newer and more expensive features came around,
but not anymore.
I think diff.c::flush_one_pair() needs to learn to pay attention to
opt->diff_from_contents in its third branch where DIFF_FORMAT_NAME
is handled. I do not offhand remember if -I flips diff_from_contents
bit, but I wouldn't be surprised if the recent change added the
support for -I forgot to do so.
Thanks.
next prev parent reply other threads:[~2020-12-14 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 19:00 Unexpected behavior on diff -I<regex> --name-only Johannes Altmanninger
2020-12-14 19:49 ` Junio C Hamano [this message]
2020-12-16 23:18 ` Johannes Altmanninger
2020-12-16 23:18 ` [PATCH] diff: suppress --name-only paths where all hunks are ignored Johannes Altmanninger
2020-12-17 1:27 ` Re* " Junio C Hamano
2020-12-20 22:34 ` Johannes Altmanninger
2020-12-21 19:29 ` Junio C Hamano
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=xmqqeejsdv7x.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=aclopte@gmail.com \
--cc=git@vger.kernel.org \
/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).