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

Re: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'

From
Tian Yuchen <cat@malon.dev>
Date
Jul 20, 2026, 09:13 UTC
Message-ID
<8b9528b8-198b-489f-8f0e-fbd0c7d07b64@malon.dev>
In-Reply-To
<alvNq8rXF/jofqUc@szeder.dev>
On 7/19/26 03:02, SZEDER Gábor wrote:
Show 71 quoted lines
> On Fri, Jul 17, 2026 at 02:35:57PM +0800, Tian Yuchen wrote:
>> The ce_mode_from_stat() function is a performance-critical static
>> inline helper in 'read-cache.h'. As we migrate configuration
>> variables into the repository struct, this helper needs access
>> to the repository context.
>>
>> Update the signature of ce_mode_from_stat() to take a 'struct
>> repository *' parameter, and update all callers to pass the
>> appropriate repository instance.
>>
>> To prepare for the overhead of replacing cheap global variable
>> accesses with getter functions, the boolean expressions are
>> reordered to evaluate 'S_ISREG(mode)' first.
>>
>> While at it, add a comment for ce_mode_from_stat().
>>
>> Mentored-by: Christian Couder <christian.couder@gmail.com>
>> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
>> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com>
>> Signed-off-by: Tian Yuchen <cat@malon.dev>
>> ---
> 
>> diff --git a/read-cache.h b/read-cache.h
>> index 043da1f1aa..94b8d3e547 100644
>> --- a/read-cache.h
>> +++ b/read-cache.h
>> @@ -4,15 +4,24 @@
>>   #include "read-cache-ll.h"
>>   #include "object.h"
>>   #include "pathspec.h"
>> +#include "environment.h"
>>   
>> -static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
>> +/*
>> + * Determine the appropriate index mode for a file based on its stat()
>> + * information and the existing cache entry (if any).
>> + *
>> + * This function handles degradation for filesystems that lack
>> + * symlink support or reliable executable bits.
>> + */
>> +static inline unsigned int ce_mode_from_stat(struct repository *repo,
> 
> This new parameter is not yet used in this function, which causes
> compilation errors in all source files which include "read-cache.h"
> when trying to build this commit using DEVELOPER=1, e.g.:
> 
>        CC pathspec.o
>    In file included from pathspec.c:11:
>    read-cache.h: In function ‘ce_mode_from_stat’:
>    read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
>       16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
>          |                                              ~~~~~~~~~~~~~~~~~~~^~~~
>    cc1: all warnings being treated as errors
>    make: *** [Makefile:2921: pathspec.o] Error 1
>        CC preload-index.o
>    In file included from preload-index.c:16:
>    read-cache.h: In function ‘ce_mode_from_stat’:
>    read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
>       16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
>          |                                              ~~~~~~~~~~~~~~~~~~~^~~~
>    cc1: all warnings being treated as errors
>    make: *** [Makefile:2921: preload-index.o] Error 1
>        CC read-cache.o
>    In file included from read-cache.c:34:
>    read-cache.h: In function ‘ce_mode_from_stat’:
>    read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
>       16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
>          |                                              ~~~~~~~~~~~~~~~~~~~^~~~
>    cc1: all warnings being treated as errors
>    make: *** [Makefile:2921: read-cache.o] Error 1
> 
Nice catch.
Show 20 quoted lines
> I think the new parameter should be marked as UNUSED in this patch,
> and then the UNUSED should be dropped in the next, where you start
> using the parameter.
> 
>> +					     const struct cache_entry *ce,
>>   					     unsigned int mode)
>>   {
>>   	extern int trust_executable_bit, has_symlinks;
>> -	if (!has_symlinks && S_ISREG(mode) &&
>> +	if (S_ISREG(mode) && !has_symlinks &&
>>   	    ce && S_ISLNK(ce->ce_mode))
>>   		return ce->ce_mode;
>> -	if (!trust_executable_bit && S_ISREG(mode)) {
>> +	if (S_ISREG(mode) && !trust_executable_bit) {
>>   		if (ce && S_ISREG(ce->ce_mode))
>>   			return ce->ce_mode;
>>   		return create_ce_mode(0666);
>> -- 
>> 2.43.0
>>

But 'USUSED' cannot be used here since the corresponding header (git-compat-util.h, or more specifically compat/posix.h) is not included.

Can we write..
	(void)repo; /* TODO: use this parameter in the next patch */
..to keep it simple?
Regards, yuchen
Previous: SZEDER GáborNext: SZEDER Gábor
Message 50 of 62 in “environment.c: migrate 'trust_executable_bit' into 'repo_config_values'”
  1. 0/4 environment.c: migrate 'trust_executable_bit' into 'repo_config_values'Tian Yuchen, May 30, 2026
  2. 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, May 30, 2026
  3. Patrick SteinhardtJun 4, 2026
  4. Tian YuchenJun 10, 2026
  5. 3/4 environment: move 'trust_executable_bit' into repo_config_valuesTian Yuchen, May 30, 2026
  6. Christian CouderMay 30, 2026
  7. Junio C HamanoMay 30, 2026
  8. Tian YuchenJun 1, 2026
  9. Tian YuchenJun 1, 2026
  10. Junio C HamanoJun 9, 2026
  11. 4/4 read-cache: pass 'istate' to stat/mode helper functionsTian Yuchen, May 30, 2026
  12. Christian CouderMay 30, 2026
  13. 1/4 read-cache: remove redundant extern declarationsTian Yuchen, May 30, 2026
  14. 0/3 environment: migrate 'trust_executable_bit' into 'repo_config_values'Tian Yuchen, Jun 10, 2026
  15. 1/3 read-cache: remove redundant extern declarationsTian Yuchen, Jun 10, 2026
  16. 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, Jun 10, 2026
  17. Christian CouderJun 12, 2026
  18. 3/3 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jun 10, 2026
  19. Tian YuchenJun 11, 2026
  20. Christian CouderJun 12, 2026
  21. Junio C HamanoJun 12, 2026
  22. 0/3 environment: migrate 'trust_executable_bit' into 'repo_config_values'Tian Yuchen, Jun 12, 2026
  23. 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, Jun 12, 2026
  24. 1/3 read-cache: remove redundant extern declarationsTian Yuchen, Jun 12, 2026
  25. 3/3 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jun 12, 2026
  26. 0/3 environment: migrate 'trust_executable_bit' into 'repo_config_values'Tian Yuchen, Jun 19, 2026
  27. 1/3 read-cache: remove redundant extern declarationsTian Yuchen, Jun 19, 2026
  28. 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, Jun 19, 2026
  29. 3/3 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jun 19, 2026
  30. Junio C HamanoJun 29, 2026
  31. Tian YuchenJul 15, 2026
  32. 0/4 environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'Tian Yuchen, Jul 15, 2026
  33. 1/4 read-cache: remove redundant extern declarationsTian Yuchen, Jul 15, 2026
  34. 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, Jul 15, 2026
  35. 3/4 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jul 15, 2026
  36. 4/4 environment: move has_symlinks into repo_config_valuesTian Yuchen, Jul 15, 2026
  37. Christian CouderJul 15, 2026
  38. Junio C HamanoJul 15, 2026
  39. Junio C HamanoJul 15, 2026
  40. 0/4 environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'Tian Yuchen, Jul 16, 2026
  41. 1/4 read-cache: remove redundant extern declarationsTian Yuchen, Jul 16, 2026
  42. 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'Tian Yuchen, Jul 16, 2026
  43. Junio C HamanoJul 16, 2026
  44. 3/4 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jul 16, 2026
  45. 4/4 environment: move has_symlinks into repo_config_valuesTian Yuchen, Jul 16, 2026
  46. Junio C HamanoJul 16, 2026
  47. 0/4 environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'Tian Yuchen, Jul 17, 2026
  48. 2/4 read-cache: pass 'repo' to 'ce_mode_from_stat()'Tian Yuchen, Jul 17, 2026
  49. SZEDER GáborJul 18, 2026
  50. Tian YuchenJul 20, 2026
  51. SZEDER GáborJul 20, 2026
  52. Tian YuchenJul 20, 2026
  53. 1/4 read-cache: remove redundant extern declarationsTian Yuchen, Jul 17, 2026
  54. 3/4 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jul 17, 2026
  55. Junio C HamanoJul 17, 2026
  56. Tian YuchenJul 20, 2026
  57. 4/4 environment: move has_symlinks into repo_config_valuesTian Yuchen, Jul 17, 2026
  58. 0/4 environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'Tian Yuchen, Jul 20, 2026
  59. 1/4 read-cache: remove redundant extern declarationsTian Yuchen, Jul 20, 2026
  60. 2/4 read-cache: pass 'repo' to 'ce_mode_from_stat()'Tian Yuchen, Jul 20, 2026
  61. 3/4 environment: move trust_executable_bit into repo_config_valuesTian Yuchen, Jul 20, 2026
  62. 4/4 environment: move has_symlinks into repo_config_valuesTian Yuchen, Jul 20, 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.