From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.151 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795983191; b=o879tEmf95Yq3u+JJjAJzWHzaM9g07zmdGDXGs4VhS4PNMBbKfbQOgwN6p5imZ1/XgNP O2UBpGo9KKj16trY2wSvo/5dKvu17bm7wTRz1cyO1csx6bJrMZ+fdYhr91XvVg3qPwotP ouNc9qW3iPZaiWQ9TX0mYNuAzEoYjSC5dcxYYmJGpx6wQv4HFWwD22seh7Td1iFTc/tDR tLY78QI96BXE79I1J95f6usjpx3tru/A/liC8fa5KPNw6LsMLp/61d4FN0WWhRTQUwB2S Dhpf4dvBn9bhcT7aH3eB//0pBuKPF1hOnTDBU+d6gklzF7Lb7pPgseRMy/jUGsUUdDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795983191; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: User-Agent:MIME-Version:Content-Type; bh=7rIFEZgDxatbjck/Vxn6I4VA/gyh+DSQK58BXORbgRA=; b=iqzy+eHh3zQGMqoafS0UQk+JI4FZ5t9hhTolFnUSLdVdWBr7usk0OtGF1Svsxl4gSF+6 Hp5rwEfJe7WPIVfPsyrzKTT6zb5TJVNttzEnvVzZHJBeW/21MTFdwYvj/OChe6+DnWqiM CBrtR96xtK8POffFcdBGXI/9dkpYu4yj5dfNxdbQ5jutD0sZONXvycIpGub8z5pVDmOfn P75iXtntwZofeIs2a5j5rwUSbxPEy9BlDsWGzzigFfnMrl0Zmb7YfiuCLCbofj9Uh1LUW cjR1Zo919GiFenRzF5ZL9e6PEwXpXWK+JnVWOIYXoCmx7SOxsb1RjRR+KAefIjFT0KQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=Q5MjVHG3; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=JM4KvWj6; arc=none smtp.remote-ip=103.168.172.151 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1439D606A31C for ; Sun, 29 Nov 2026 20:13:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1439D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=Q5MjVHG3; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=JM4KvWj6 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 26245EC0A64 for ; Sun, 29 Nov 2026 15:13:09 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-06.internal (MEProxy); Sun, 29 Nov 2026 15:13:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1795983189; x=1796069589; bh=7rIFEZgDxa tbjck/Vxn6I4VA/gyh+DSQK58BXORbgRA=; b=Q5MjVHG31d2H+dgnTqwuF24Ahj lhi5DwrHpkjuIpGTDpfPQv6ps++7E1U4QjUD9Tj/6B8fqzJUetCR5FPl4c7mZRHe xMyJIBMrlH7QJGEaKDb72qHhPGVbGoe+xUcYKCiv62fn8y9oydItXT3vw2hkJtE5 DffewgSuvMrVDt6sMJBMJzDB4bLwqZ2AvZp9N9yIE4kSkbcnuFRZXcmeOuerKBtg bQzYsHfE9xd08jedfSrFVwZF65kecFvZO5ZGQldgPbWpLfx0aT5ztUkW3UHzOYug aWhq0r/5hCHnfUtP5jMpIdOEOaev2HH6umXFIobyd2OKTJOVEWi/Uroi/1Aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1795983189; x=1796069589; bh=7rIFEZgDxatbjck/Vxn6I4VA/gyh+DSQK58 BXORbgRA=; b=JM4KvWj6eOs23qbvDz6RB0e+O72IFZezlWlzccnlfHbA6QeBP2P DxQyXx66TSh9qUn6lIe57ANLId0R1C6r+GC/DHcg+X9T99N1ELy3tNkhRZny+7I+ llsgM3JQ0Knj7hFBTVkVvM9pEQsF+CsSfBwPNzpOIeAuFv//FnTsPaB2GryaFV0Q bm7JhOaSdGXnvf2Cdvax22TwWK2LMWbk0BtWKNkVHtEyNffc4izIukkYEBDA9+QI xNG0xdZWDjuXEN1Jx2NUDX+ujEfoNY1g4JX2WBN5+sW4Pgs8t8wjtGBnfdQEXf/V QaievYwxSqe/Bvp88H3N+nl2P2pC7mZ+hNg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pobox.com a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1795983189; d=pobox.com; mf=PGdpdHN0ZXJAcG9ib3guY29tPg==; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm2:rsa-sha256:VXCTR+Sxmy15Z6u5ztsqdwuqN+Sbr6cU6kpkl5JFPSlJ5uC 9PxABXC4OaZ2DRTnFANDWyIV8c6js7+oYKzPPj+zqKfo2ur5KXkzJE+dh8YVNE1D lFIgpO7NmBcRVp/1ahwCqceJWM0MgpSX/KzzqeP5yL1lPWv9qZizen8QpdGi7qY8 L9vz4oAk7fVHRqBR4QgH8xbfi9Qn1RO+yp0wnTU9jaVFwIC8RgkfoWrslAeQU6cs bTEKhk/xNq61yED35iwgznMPgjyAdXf82JMhjDd1QUkEAIIyMmIbn9HK1+yccwYP VgG3eS05LoPo+txbeD+XvzRTl26gZLY2rXB1tzA==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id, mime-version,references,subject,to,user-agent; Message-Instance: m=1; h=sha256:7/oa446YQ9m98Tcs9QLogLzeLQE2LnUppYogImTkQP8=:CS6SE/qJkPPaFihzqgnF1hHCbwRCYdwk3QJHyRR85Js=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFQqG3zkVxYio+jMwzfm9s7nTX5YKSPSEH4hMTesvJrcIu3vklbP/QK2zoUxWcFVz /hLV3b93sKdSkwMV47wiNYKgNMUl1ldMJypanu1gD6oTCWPrJg9pYdGbBjhp9jgcUB0Dic kqmNEUpATgBjG/048ekLBF3UpicFsBzvgQDWy5RYDXSTXE/yuVJIGSdyWdwstSdYgxC83k EQslIvCN3KouTgasRu0w+2E/xpmy1KURIUQF0nN3p3oK3uqAntoxj7hNMUpW7RZIa2UoL7 loRbMxkHmXB7eiv/r7qMMK4aHk6W70YsyiBnneT0AGKQO7MSaCYaJsWV2xltpZvaBez5P5 HwT9wQL626gjRlKcfcbsS6+CW1FjRUOtj3ncsmwyVwwKRcxoVQ0it0rwORIcuwTKJZeCd2 FecE3Yk49+6VTVZMDWnrl3kamfyjfH2oUP8geug9UWeyNm8UMQHYxa409Kjki8XkUxJvT1 D8g4w84E4qYXgI8NCN0E9ZnMOCAUMeEyVz+1HplpwxzaKpt4ffgP/04WEc0o1/xvy4GTCD PTeSC8keTpvvOHcdYukG5V06vNnl6U0Eh+tKiwEWNtxuxAFOH2/5xvW0AvBt7x5DFAqqov en1nlfp9J11e0IAyoUntCmlSSJxsTFfYCBz/VyhyiKqzBYGxcEyXJ1CXhBjQ X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Nov 2026 15:13:08 -0500 (EST) From: Junio C Hamano 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 In-Reply-To: <20261129152805.758456-1-tboegi@web.de> (tboegi@web.de's message of "Sun, 29 Nov 2026 16:28:05 +0100") References: <20261129152805.758456-1-tboegi@web.de> Date: Sun, 29 Nov 2026 12:13:07 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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.