git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RESEND v6 2/2] read-cache: optimize file size change when conversion is active

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 28, 2026, 03:38 UTC
Message-ID
<xmqqzeuty698.fsf@gitster.g>
In-Reply-To
<20261127194245.10104-1-tboegi@web.de>
tboegi@web.de writes:
Show 12 quoted lines
> From: Torsten Bögershausen <tboegi@web.de>
>
> Commit
> "read-cache: do not trust a size change when conversion is active"
> corrected the case when the file size in the worktree has changed.
> Input filters may convert worktree files with different sizes into the
> same blob.
>
> Optimize the new code:
> The call to would_convert_to_git() can be skipped since the same check
> is done in ce_compare_data()  for regular files, which is called from
> ce_modified_check_fs().

That is a new and unusual way to write a proposed commit log message for our project. Is this an LLM experiment gone wrong, or something?

The claim "the same check is done in ce_compare_data(), hence would_compare_to_git() is unnecessary" seems to be mistaken. Unless you meant to name a different function, that is.

Show 31 quoted lines
> @@ -456,13 +455,12 @@ 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".
> +	 * When the length field of a regular file is zero or changed,
> +	 * this does not necessarily 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().
>  	 *
>  	 * The logic does not apply to gitlinks, as ce_match_stat_basic()
>  	 * already has checked the actual HEAD from the filesystem in the
> @@ -479,10 +477,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) &&
> -	    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))
> +	    (S_ISGITLINK(ce->ce_mode)))
>  		return changed;

Doesn't this actually have the opposite effect of an optimization? I suspect that it also breaks symlink handling.

For a file without conversion active, replacing the check (ce->ce_stat_data.sd_size != 0) and the would_convert_to_git() check with S_ISGITLINK(ce->ce_mode) disables the size-mismatch fast path altogether.

Imagine a repository with 'core.autocrlf' set to false and no attributes set on a regular file that grows or shrinks on disk. Because S_ISGITLINK(ce->ce_mode) is false for regular files, ie_modified() no longer returns changed early on DATA_CHANGED. Instead, it falls through to ce_modified_check_fs(), which calls ce_compare_data() and then object-file.c:index_fd().

While ce_compare_data() opens the file and passes the file descriptor to index_fd(), which does call would_convert_to_git(), it does not use that result to skip reading from the file descriptor or hashing when no conversion applies. Rather, index_fd() either reads or maps the file in index_core() or streams every byte through hash_stream() in order to compute the object name. That is in addition to open the file descriptor for the path that we already know has changed, if we paid attention to what would_convert_to_git() says.

Wouldn't it be a serious regression to save a cheap gitattributes lookup on converted files at the cost of reading and hashing every size-modified non-converted file on disk?

Or am I misreading the code and we actually won't compare the data?

Removing !S_ISLNK(st->st_mode) and (ce->ce_stat_data.sd_size != MAX_PATH) makes the conditional false for every symlink on all platforms, since S_ISGITLINK(ce->ce_mode) is false for symlinks too. Every size-changed symlink now falls through to ce_compare_link(), which runs strbuf_readlink() and reads the blob from the object database.

Doesn't it make the GIT_WINDOWS_NATIVE MAX_PATH workaround dead for symlinks while applying the '.sd_size != MAX_PATH' check to gitlinks instead?

I think [1/2] alone was probably OK (I am not as familiar with the details on that part of the code as you are, so my review is not worth all that much), but I do not know about this step.

Thanks.
Previous: tboegi@web.deNext: tboegi@web.de
Message 31 of 37 in “utf8.c: Prepare workaround for iconv under macOS 14/15”
  1. 1/2 utf8.c: Prepare workaround for iconv under macOS 14/15tboegi@web.de, Jan 11, 2026
  2. Junio C HamanoJan 12, 2026
  3. 1/2 utf8.c: Prepare workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  4. 0/2 Workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  5. 2/2 utf8.c: Enable workaround for iconv under macOS 14/15tboegi@web.de, Jan 12, 2026
  6. 0/1 read-cache: do not trust a size change when conversiontboegi@web.de, Oct 12, 2026
  7. 1/1 read-cache: do not trust a size change when conversion is activetboegi@web.de, Oct 12, 2026
  8. Junio C HamanoOct 12, 2026
  9. Junio C HamanoOct 13, 2026
  10. Curtis SmithOct 13, 2026
  11. Johannes SixtOct 13, 2026
  12. Curtis SmithOct 13, 2026
  13. read-cache: do not trust a size change when conversion is activeCurtis Allen Smith, Oct 13, 2026
  14. Phillip WoodOct 13, 2026
  15. Curtis SmithOct 13, 2026
  16. Torsten BögershausenOct 13, 2026
  17. read-cache: do not trust a size change when conversion is activeCurtis Allen Smith, Oct 13, 2026
  18. Junio C HamanoOct 13, 2026
  19. Torsten BögershausenOct 18, 2026
  20. Junio C HamanoOct 19, 2026
  21. Torsten BögershausenOct 20, 2026
  22. 0/1 More cs/read-cache-conversion-sizetboegi@web.de, Oct 26, 2026
  23. 1/1 read-cache: optimize file size change when conversion is activetboegi@web.de, Oct 26, 2026
  24. 0/2 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 27, 2026
  25. Junio C HamanoNov 28, 2026
  26. 1/2 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 27, 2026
  27. Junio C HamanoNov 28, 2026
  28. Torsten BögershausenNov 28, 2026
  29. Junio C HamanoNov 29, 2026
  30. 2/2 read-cache: optimize file size change when conversion is activetboegi@web.de, Nov 27, 2026
  31. Junio C HamanoNov 28, 2026
  32. 1/1 read-cache: do not trust a size change when conversion is activetboegi@web.de, Nov 29, 2026
  33. Junio C HamanoNov 29, 2026
  34. Junio C HamanoNov 29, 2026
  35. Junio C HamanoNov 29, 2026
  36. Torsten BögershausenNov 29, 2026
  37. Junio C HamanoNov 29, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.