Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Aniket Gupta <aniketgupta3001@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Matt Hunter <m@lfurio.us>, Mike Beaton <mjsbeaton@gmail.com>,
	Phillip Wood <phillip.wood123@gmail.com>
Subject: Re: [PATCH v3] dir: ignore CRLF-empty and space-only lines in pattern files
Date: Tue, 1 Dec 2026 15:54:37 +0100	[thread overview]
Message-ID: <aw7frcoTfryxeIPX@pks.im> (raw)
In-Reply-To: <20261201080040.47247-1-aniketgupta3001@gmail.com>

On Tue, Dec 01, 2026 at 01:30:40PM +0530, Aniket Gupta wrote:
> add_patterns_from_buffer() skips an empty line which starts right at the
> '\n', before it strips the '\r' or any trailing spaces. A two byte
> "\r\n" line in a CRLF file, or a line that holds only spaces (with or
> without the '\r') is not empty at that point. Stripping the '\r' and
> calling trim_trailing_spaces() reduces it to an empty string, which is
> then passed to add_pattern().
> 
> parse_path_pattern() turns that empty string into a 0 length pattern
> with PATTERN_FLAG_NODIR. The directory walk checks a directory before it
> appends the trailing slash. Thus, status and a plain add are not
> affected.

Huh, affected by what? At this point I have no idea what the issue even
is, the only thing I know is that we have an empty pattern now.

> A path argument that ends in a slash is a different scenario.
> For eg, with "git check-ignore foo/", the basename is empty and
> match_basename() matches the 0 length pattern and "check-ignore -v"
> names that line as the reason foo/ is ignored.

Okay. With git-check-ignore(1) we can append that slash ourselves, and
thus it may trigger the bug. And this is in contrast to git-status(1)
and git-add(1) seemingly, which never have that trailing slash.

Sorry for repeating all of that, but I'm trying to deciper this AI
message and am having a hard time doing so.

> Cone-mode sparse-checkout is affected as well. For such a line,
> add_pattern_to_hashsets() sees a pattern shorter than 2 characters,
> warns "unrecognized pattern: ''" and disables cone pattern matching.

Okay. Is this a cosmetic issue, or is it something that results in wrong
behaviour?

> Skip calling add_pattern() when the trimmed line is empty. This follows
> gitignore(5) which says that trailing spaces are ignored unless quoted
> with backslash. A file name made of spaces can still be matched by
> quoting the spaces.

Okay. I think overall this depends a bit on how you're reading that
manpage and how you interpret "A blank line". When reading it I wouldn't
necessarily think that the "Trailing spaces are ignored" rule also
applies to "A blank line", but I think it's a sensible interpretation
regardless of that.

Would it make sense to maybe clarify the rule to say "A blank line or a
line that consists of spaces, only, matches no files"?

> diff --git a/dir.c b/dir.c
> index d896e7be4b..5a8a28afef 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1249,7 +1249,8 @@ int add_patterns_from_buffer(char *buf, size_t size,
>  			if (entry != buf + i && entry[0] != '#') {
>  				buf[i - (i && buf[i-1] == '\r')] = 0;
>  				trim_trailing_spaces(entry);
> -				add_pattern(entry, base, baselen, pl, lineno);
> +				if (*entry)
> +					add_pattern(entry, base, baselen, pl, lineno);
>  			}
>  			lineno++;
>  			entry = buf + i + 1;

The change looks obviously good to me.

Thanks!

Patrick

  reply	other threads:[~2026-12-01 14:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 12:49 [BUG] check-ignore matches trailing-slash paths against CRLF blank lines Mike Beaton
2026-11-06 18:29 ` [PATCH] dir: do not turn blank ignore-file lines into patterns Aniket Gupta
2026-11-19 17:19   ` Aniket Gupta
     [not found]     ` <CAHzAAWQo89ox+S_jtPX9DOtzfr-+3uMbWHN+HXdi9Aw2q57+Ng@mail.gmail.com>
2026-11-21  9:45       ` Aniket Gupta
2026-11-27 16:21   ` Aniket Gupta
2026-11-28  5:24   ` Matt Hunter
2026-11-28  7:28     ` Aniket Gupta
2026-11-28 10:47     ` Aniket Gupta
2026-11-29  3:21       ` Junio C Hamano
2026-11-28  6:54   ` Junio C Hamano
2026-11-28  7:28     ` Aniket Gupta
2026-11-29  4:01       ` Junio C Hamano
2026-11-28  9:38   ` Matt Hunter
2026-11-28 10:12     ` Aniket Gupta
2026-11-29  6:00   ` [PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files Aniket Gupta
2026-11-29 11:14     ` Matt Hunter
2026-11-29 11:42       ` Aniket Gupta
2026-12-01  8:00     ` [PATCH v3] " Aniket Gupta
2026-12-01 14:54       ` Patrick Steinhardt [this message]
2026-12-01 19:11         ` Aniket Gupta

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=aw7frcoTfryxeIPX@pks.im \
    --to=ps@pks.im \
    --cc=aniketgupta3001@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=m@lfurio.us \
    --cc=mjsbeaton@gmail.com \
    --cc=phillip.wood123@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