Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: tboegi@web.de
Cc: git@vger.kernel.org,  curtis.allen.smith@gmail.com
Subject: Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active
Date: Sun, 29 Nov 2026 12:13:07 -0800	[thread overview]
Message-ID: <xmqq1p83flbg.fsf@gitster.g> (raw)
In-Reply-To: <20261129152805.758456-1-tboegi@web.de> (tboegi@web.de's message of "Sun, 29 Nov 2026 16:28:05 +0100")

tboegi@web.de writes:

>   git status --short      # ->  M file.txt
>   git ls-files --debug file.txt | grep size # size: 14 (*)
>
>   git diff                # -> empty
>   git add file.txt        # -> nothing to commit

As pointed out earlier, 'git add' does not say "nothing to commit".
Running 'git commit file.txt' after 'git add file.txt' (or 'git
status' after 'git add file.txt') is what reports "nothing to
commit".

> Today different different file contents and/or file length may result
> in the same content in the index using `git add`, when all input
> conversions are run.
> (*) With this change: size: 17

There is a doubled word ("different different"), and this log
message uses markdown backticks around commands, which we tend to
avoid in plain-text commit logs.  Also, placing the "(*)" note
between prose paragraphs breaks the flow; folding that note right
below the transcript (or showing the refreshed size directly in a
short post-patch snippet) would read more smoothly.

> This change removes the 'shortcut' in read-cache/ie_modified():
> when a regular file has a different size compared to what is
> recorded in the index then the file is modified.
> When the path is subject to conversion
> (the "text" and "eol" attributes, core.autocrlf, a clean filter),
> different bytes can convert to the same blob, as the CRLF rewrite
> above does.

This paragraph describes checking only paths subject to conversion,
but the diff itself removes the shortcut unconditionally for all
regular files and symlinks, which may be a serious regression I
already pointed out in the review of [2/2] in an earlier round.

In style, the log message also uses reporting prose ("This change
removes...", "Now ...") instead of ending with an imperative command
telling the codebase what to change.

> read-cache.c    | 26 ++++++++++++--------------
>  t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 14 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 595497d14c..2757bbb6ff 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -593,20 +593,18 @@ int ie_modified(struct index_state *istate,
>  		return changed;
>  
>  	/*
> -	 * Immediately after read-tree or update-index --cacheinfo,
> -	 * the length field is zero, as we have never even read the
> -	 * lstat(2) information once, and we cannot trust DATA_CHANGED
> -	 * returned by ie_match_stat() which in turn was returned by
> -	 * ce_match_stat_basic() to signal that the filesize of the
> -	 * blob changed.  We have to actually go to the filesystem to
> -	 * see if the contents match, and if so, should answer "unchanged".
> +	 * gitlinks do not go through any conversion, see below.
> +	 * When the size if different, the content is different.

"if" -> "is".

I do not think gitlinks compare file sizes at all.

In ce_match_stat_basic(), gitlinks enter a dedicated S_IFGITLINK
branch that ignores '.st_size' and sets DATA_CHANGED only when
ce_compare_gitlink() detects that the subproject's HEAD differs from
the recorded object ID.  Keeping the original explanation for
gitlinks and symlinks alongside the new note for converted regular
files would be much clearer.

> +	 *
> +	 * When the length field of a regular file is zero or changed,
> +	 * this does not always mean a changed blob in the index.
> +	 * All input filters (CRLF line endings, clean filter..)
> +	 * need to be applied followed by a hash and oideq().
> +	 * This is done in ce_modified_check_fs() below,
> +	 * which calls ce_compare_data().
>  	 *

This becomes a stray empty comment line.

> -	 * The logic does not apply to gitlinks, as ce_match_stat_basic()
> -	 * already has checked the actual HEAD from the filesystem in the
> -	 * subproject.  If ie_match_stat() already said it is different,
> -	 * then we know it is.
>  	 */


> -	if ((changed & DATA_CHANGED) &&
> +	if ((S_ISGITLINK(ce->ce_mode) &&
>  #ifdef GIT_WINDOWS_NATIVE
>  	    /*
>  	     * Work around Git for Windows v2.27.0 fixing a bug where symlinks'
> @@ -616,9 +614,9 @@ int ie_modified(struct index_state *istate,
>  	     * So let's just special-case symlinks with a target path length
>  	     * (i.e. `sd_size`) of 4096 and force them to be re-checked.
>  	     */
> -	    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&
> +	    (ce->ce_stat_data.sd_size != MAX_PATH) &&
>  #endif
> -	    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))
> +	    (changed & DATA_CHANGED)))
>  		return changed;

Squashing v6 1/2 and 2/2 into one commit carried forward the two bugs
that was already flagged against v6 [PATCH 2/2], doesn't it?

Keeping the check in ie_modified() rather than ie_match_stat() is
the right design so that preload_index() worker threads never run
attribute lookups, I think.

By dropping would_convert_to_git() and the non-zero check on
'.sd_size', you remove the size-change fast path even when no
conversion is active.  Imagine a repository has 'core.autocrlf' set
to false (or marks a large binary file with '-text' in
.gitattributes).  The user modifies that file so its size changes.

When 'git status' runs refresh_index(), ie_modified() now sees that
S_ISGITLINK() is false and unconditionally falls through to
ce_modified_check_fs(), which calls ce_compare_data() and
index_fd().  Although index_fd() calls would_convert_to_git() and
notices that there is no need for conversion, it is too late.  It
does not know that it is only called to see if there is a change,
and the fact that the caller knows that the last-known size is
different from what is on the disk, and it does not know its work to
read (or mmap), stream, and hash the entire file is wasted.

Removing "!S_ISLNK(st->st_mode) ||" and using the remaining
'.sd_size != MAX_PATH' check on S_ISGITLINK() breaks both symlinks
and the GIT_WINDOWS_NATIVE workaround.  Because S_ISGITLINK() is
always false for symlinks, the Windows MAX_PATH workaround is dead
for symlinks and instead applies a symlink length check to gitlinks.
Meanwhile, every size-changed symlink on all platforms now falls
through to ce_compare_link(), reading the symlink target and the
object database blob even though symlinks never undergo input
conversion.



> diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh
> index fd1cae09ed..9c8d07cfc4 100755
> --- a/t/t0020-crlf.sh
> +++ b/t/t0020-crlf.sh
> @@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '
>  	test_cmp alllf alllf2
>  '
>  
> +test_expect_success 'status does not report a CRLF-only rewrite as modified' '
> +	test_when_finished "git reset --hard autocrlf-checkpoint" &&
> +	echo "eol.txt text eol=lf" >.gitattributes &&
> +	printf "one\ntwo\nthree\n" >eol.txt &&
> +	git add .gitattributes eol.txt &&
> +	git commit -m "eol.txt" &&
> +
> +	# a generator rewrites the file with CRLF, same content
> +	printf "one\r\ntwo\r\nthree\r\n" >eol.txt &&
> +	git status --porcelain -uno >actual &&
> +	test_must_be_empty actual &&
> +	git diff --exit-code &&
> +
> +	# a real change is still reported
> +	printf "one\r\ntwo\r\nfour\r\n" >eol.txt &&
> +	git status --porcelain -uno >actual &&
> +	echo " M eol.txt" >expect &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '
> +	test_when_finished "git reset --hard autocrlf-checkpoint" &&
> +	echo "cr.txt text eol=lf" >.gitattributes &&
> +	printf "one\rtwo\nthree\n" >cr.txt &&
> +	git add .gitattributes cr.txt &&
> +	git commit -m "cr.txt" &&
> +
> +	# "git add" keeps the lone CR and drops the others
> +	printf "one\rtwo\r\nthree\r\n" >cr.txt &&
> +	git status --porcelain -uno >actual &&
> +	test_must_be_empty actual &&
> +
> +	# the converted length matches the blob, the content does not
> +	printf "one\rtwo\nthrEE\r\n" >cr.txt &&
> +	git status --porcelain -uno >actual &&
> +	echo " M cr.txt" >expect &&
> +	test_cmp expect actual
> +'

Both new tests in t/t0020-crlf.sh are nicely scoped to their own
paths and clean up cleanly against autocrlf-checkpoint, covering
both the plain CRLF rewrite and the lone-CR case where converted
size equals the original blob size.

  reply	other threads:[~2026-11-29 20:13 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 19:51 [PATCH v2 1/2] utf8.c: Prepare workaround for iconv under macOS 14/15 tboegi
2026-01-12  4:58 ` Junio C Hamano
2026-01-12 16:25   ` [PATCH v3 0/2] Workaround " tboegi
2026-01-12 16:25   ` [PATCH v3 1/2] utf8.c: Prepare workaround " tboegi
2026-01-12 16:25   ` [PATCH v3 2/2] utf8.c: Enable " tboegi
2026-10-12 17:56   ` [PATCH v3/RFC 0/1] read-cache: do not trust a size change when conversion tboegi
2026-10-12 17:56   ` [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active tboegi
2026-10-12 19:11     ` Junio C Hamano
2026-10-13  1:29       ` Junio C Hamano
2026-10-13  6:45         ` Curtis Smith
2026-10-13  5:34     ` Johannes Sixt
2026-10-13  6:48       ` Curtis Smith
2026-10-13  6:58     ` [PATCH v4] " Curtis Allen Smith
2026-10-13  9:44       ` Phillip Wood
2026-10-13 17:57         ` Curtis Smith
2026-10-13 18:01       ` Torsten Bögershausen
2026-10-13 18:02       ` [PATCH v5] " Curtis Allen Smith
2026-10-13 20:29         ` Junio C Hamano
2026-10-18 11:18           ` Torsten Bögershausen
2026-10-19  5:57             ` Junio C Hamano
2026-10-20 20:56         ` Torsten Bögershausen
2026-10-26 19:25   ` [PATCH/RFC 0/1] More cs/read-cache-conversion-size tboegi
2026-10-26 19:25   ` [PATCH/RFC 1/1] read-cache: optimize file size change when conversion is active tboegi
2026-11-27 19:42   ` [PATCH/RESEND v6 0/2] read-cache: do not trust a " tboegi
2026-11-28  4:09     ` Junio C Hamano
2026-11-27 19:42   ` [PATCH/RESEND v6 1/2] " tboegi
2026-11-28  3:28     ` Junio C Hamano
2026-11-28  7:38       ` Torsten Bögershausen
2026-11-29 17:44         ` Junio C Hamano
2026-11-27 19:42   ` [PATCH/RESEND v6 2/2] read-cache: optimize file " tboegi
2026-11-28  3:38     ` Junio C Hamano
2026-11-29 15:28   ` [PATCH v7 1/1] read-cache: do not trust a " tboegi
2026-11-29 20:13     ` Junio C Hamano [this message]
2026-11-29 21:53       ` Junio C Hamano
2026-11-29 20:18     ` Junio C Hamano
2026-11-29 22:05       ` Torsten Bögershausen
2026-11-29 22:10         ` 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=xmqq1p83flbg.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=curtis.allen.smith@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=tboegi@web.de \
    /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