Re: [PATCH v2 2/3] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jun 12, 2026, 07:43 UTC
- Message-ID
- <CAP8UFD2Y+JO06MLcpk5tXU_MMcPeAxvuiys=ytoqY5vkB1t0xQ@mail.gmail.com>
- In-Reply-To
- <20260610093635.139719-3-cat@malon.dev>
On Wed, Jun 10, 2026 at 11:37 AM Tian Yuchen <cat@malon.dev> wrote:
Show 14 quoted lines
> > The ce_mode_from_stat() function is declared as a static inline function > in 'read-cache.h'. As we want to migrate configuration variables, this > helper function will need access to corresponding repository-specific > configuration logic. Move the implementation to 'read-cache.c' to > cleanly encapsulate its dependencies. > > Note that the 'extern int trust_executable_bit, has_symlinks;' line is > discarded because it's not necessary when the function lives in > "read-cache.c". > > At present, this change has no visible impact, but it is crucial > for our future plans to pass in the repo context. Comment > has been added whilst we are at it.
We prefer it when comments like the one below are added in front of the declaration of the function into the header file ("read-cache.h" here), rather than the *.c file.
And yeah, I know that "read-cache.h" is a bad example right now because no function has such a comment there yet.
Show 19 quoted lines
> +/*
> + * 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.
> + */
> +unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)
> +{
> + if (!has_symlinks && S_ISREG(mode) &&
> + ce && S_ISLNK(ce->ce_mode))
> + return ce->ce_mode;
> + if (!trust_executable_bit && S_ISREG(mode)) {
> + if (ce && S_ISREG(ce->ce_mode))
> + return ce->ce_mode;
> + return create_ce_mode(0666);
> + }
> + return create_ce_mode(mode);
> +}