git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shejialuo <shejialuo@gmail.com>
To: Bob Ruiken <bob@synergi.so>
Cc: git@vger.kernel.org
Subject: Re: [bug] Using --ignore-space-at-eol with --name-only does not apply the filtering
Date: Tue, 21 Jan 2025 00:28:22 +0800	[thread overview]
Message-ID: <Z455pim1i2u_1odm@ArchLinux> (raw)
In-Reply-To: <CAK_bMgeW6ACsWKDbLk0fvm7DuOo5BYhN2OpA-EyOTCSWrkEXSw@mail.gmail.com>

On Mon, Jan 20, 2025 at 03:15:54PM +0200, Bob Ruiken wrote:
> Hi,
> 
> While doing some diffing work today I found a small issue combining a
> filtering and formatting flag. Let me know if anything is missing in
> this email, this is my first time reporting a bug here.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> I'm using "git diff --name-only" to analyse the difference between the
> current branch and a target branch.
> Then I wanted to expand the preciseness, I don't actually care about
> spacing differences at the end of lines, for which I use the
> "--ignore-space-at-eol" flag.
> The problem comes in when combining the two flags: when I do "git diff
> --name-only --ignore-space-at-eol" the names of the files where only
> space changes at EOL are happening still appear.
> 

Thanks for your report, this problem could be reproduced in the master
branch with the following shell commands:

```sh
git init repo && cd repo
printf "foo\n" > foo
git add foo && git commit -mx && git branch test
printf "foo    \n" > foo
git add foo && git commit -mx
git diff master test --name-only --ignore-space-at-eol
```

> What did you expect to happen? (Expected behavior)
> I expect the two flags "--name-only" and "--ignore-space-at-eol" to
> work together such that files not matching the latter filter are not
> shown in the output.
> 
> What happened instead? (Actual behavior)
> The files that the "--ignore-space-at-eol" flag is supposed to filter
> are still shown when "--name-only" is used.
> 

This logic is in the "diff.c::diff_flush" function, when specifying the
"--name-only" option, it will set the "DIFF_FORMAT_NAME" bit which will
let the code goes to the following control flow and then exit the
function.

```c
	if (output_format & (DIFF_FORMAT_RAW |
			     DIFF_FORMAT_NAME |
			     DIFF_FORMAT_NAME_STATUS |
			     DIFF_FORMAT_CHECKDIFF)) {
		for (i = 0; i < q->nr; i++) {
			struct diff_filepair *p = q->queue[i];
			if (check_pair_status(p))
				flush_one_pair(p, options);
		}
		separator++;
	}
```

So as long as you specify "--name-only", from my understanding (maybe
not correct here), there is no real diff here. We have just stored the
information about which file is added, modified or deleted by comparing
two trees.

Although you have specified "--ignore-space-at-eol", the code path does
not care about this option at all. Because it simply uses the
information described above to print the difference between the two
trees without checking their real contents.

I am not familiar with the code in the diff part, it would cause too
much effort for me to solve this problem. From my perspective, we need to
explain more about "--name-only" option or we need to make sure that we
cannot use both "--name-only" and "--ignore-space-at-eol" options.

Thanks,
Jialuo

      reply	other threads:[~2025-01-20 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 13:15 [bug] Using --ignore-space-at-eol with --name-only does not apply the filtering Bob Ruiken
2025-01-20 16:28 ` shejialuo [this message]

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=Z455pim1i2u_1odm@ArchLinux \
    --to=shejialuo@gmail.com \
    --cc=bob@synergi.so \
    --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).