Skip to content

environment.c: migrate 'trust_executable_bit' into 'repo_config_values'#2312

Open
malon7782 wants to merge 4 commits into
git:masterfrom
malon7782:refactor-environment
Open

environment.c: migrate 'trust_executable_bit' into 'repo_config_values'#2312
malon7782 wants to merge 4 commits into
git:masterfrom
malon7782:refactor-environment

Conversation

@malon7782
Copy link
Copy Markdown
Contributor

@malon7782 malon7782 commented May 26, 2026

The 'core.filemode' configuration, which is stored as a global variable 'trust_executable_bit', is a core filesystem capability flag.

Move it into 'repo_config_values' to tie it to the specific repository instance it was read from. Eager parsing is maintained because this flag is heavily consulted in hot paths.

To avoid falling back to 'the_repository', refactor the signatures of helper functions:

  • ce_mode_from_stat()
  • st_mode_from_ce()
  • fake_lstat()
  • check_removed()

These functions now accept a 'struct index_state *istate', ensuring the correct context is seamlessly passed down to the lowest levels.

  • Patch 1: Cleans up redundant local 'extern' declarations for 'trust_executable_bit' and 'has_symlinks' in 'read-cache.c'.

  • Patch 2: Moves 'ce_mode_from_stat()' from 'read-cache.h' to 'read-cache.c', removing its inline status.

  • Patch 3: Refactors the signatures of low-level helpers.

  • Patch 4: Performs the actual migration of 'trust_executable_bit' into 'repo_config_values'.

Previous related work: https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/

Mentored-by: Christian Couder christian.couder@gamil.com
Mentored-by: Ayush Chandekar ayu.chandekar@gmail.com
Signed-off-by: Tian Yuchen cat@malon.dev

Copy link
Copy Markdown

@Anjalo133 Anjalo133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T

Comment thread read-cache.c Outdated
return ce->ce_mode;
default:
BUG("unsupported ce_mode: %o", ce->ce_mode);
bug("unsupported ce_mode: %o", ce->ce_mode);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is BUG() changed into bug()?

Comment thread read-cache-ll.h Outdated
#define INDEX_FORMAT_UB 4

struct cache_entry {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this blank line added?

Comment thread read-cache.c Outdated
struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository;
struct repo_config_values *cfg = repo_config_values(repo);

extern int has_symlinks;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"read-cache.c" already includes "environment.h" which has extern int has_symlinks; so I am not sure this is useful here. I think it could be dropped.

Comment thread read-cache.c Outdated
static unsigned int st_mode_from_ce(struct index_state *istate, const struct cache_entry *ce)
{
extern int trust_executable_bit, has_symlinks;
extern int has_symlinks;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"read-cache.c" already includes "environment.h" which has extern int has_symlinks; so I am not sure this is useful here. I think it could be dropped.

@chriscool
Copy link
Copy Markdown
Contributor

It seems to me that the single commit in this branch is doing too many things:

  1. Moving ce_mode_from_stat() from "read-cache.h" to "read-cache.c" making it non inline.
  2. Moving trust_executable_bit from a global into struct repo_config_values.
  3. Passing a struct index_state *istate to many functions.

I think the commit could be split into three commits to help with reviews.

Also the usefulness of 3. is dubious for now because repo_config_values() still contains:

	if (repo != the_repository)
		BUG("trying to read config from wrong repository instance");

So 3. makes it look like some functions could work for a repo that isn't the_repository, but it's in fact not true. At least 3. should be explained more thoroughly in a dedicated commit message.

It looks like there could even be a small cleanup patch before the main three patches to remove the:

extern int trust_executable_bit, has_symlinks;

which was not necessary since "read-cache.c" already does #include "environment.h".

Comment thread read-cache.h Outdated
#include "object.h"
#include "pathspec.h"
#include "repository.h"
#include "environment.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that including both is necessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it seems to compile correctly without them.

@chriscool
Copy link
Copy Markdown
Contributor

Also about the commit message, maybe you can start to systematically add Mentored-by: ... trailers for both of your co-mentors. I think it will simplify things to add them systematically rather than keeping track about who helped you on which commit.

Comment thread read-cache.c Outdated

ent = (0 <= pos) ? istate->cache[pos] : NULL;
ce->ce_mode = ce_mode_from_stat(ent, st_mode);
ce->ce_mode = ce_mode_from_stat(istate->repo->index, ent, st_mode);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this could simply be:

ce->ce_mode = ce_mode_from_stat(istate, ent, st_mode);

@chriscool
Copy link
Copy Markdown
Contributor

The nice thing with a pull request (or merge request) is that its description can contain what will be in the cover letter of the patch series.

In the cover letter it's nice to talk about previous work related to the series.

About the trust_executable_bit, there was this patch before:

https://lore.kernel.org/git/20260301190017.53539-1-dronarajgyawali@gmail.com/

and it looks like you participated in the discussion.

This one is maybe relevant too:

https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/

So you might want to mention them in the cover letter/this PR's description.

Tian Yuchen added 4 commits May 27, 2026 18:33
The 'read-cache.c' file already includes 'environment.h', which provides
the extern declarations for variables like 'trust_executable_bit' and
'has_symlinks'.

Remove the redundant extern declarations inside 'st_mode_from_ce()' to
clean up the code.

Mentored-by: Christian Couder <christian.couder@gamil.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
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.

Mentored-by: Christian Couder <christian.couder@gamil.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
In preparation for moving global configuration variables into the
repository-specific 'repo_config_values' struct, low-level stat and mode
helper functions need access to repository context.

Refactor the signatures of ce_mode_from_stat(), st_mode_from_ce(),
fake_lstat(), and check_removed() to accept a 'struct index_state *istate'.
This allows these functions to retrieve the repository context via 'istate->repo'.

Mentored-by: Christian Couder <christian.couder@gamil.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
The 'core.filemode' configuration, which is stored as a global
variable 'trust_executable_bit', is a core filesystem capability flag.

Move it into 'repo_config_values' to tie it to the specific repository
instance it was read from. Eager parsing is maintained because this
flag is heavily consulted in hot paths.

For callers where 'istate->repo' might be NULL, fall back safely to
'the_repository'.

Mentored-by: Christian Couder <christian.couder@gamil.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
@malon7782 malon7782 force-pushed the refactor-environment branch from 373dfb2 to 51ca686 Compare May 27, 2026 10:39
@gitgitgadget-git
Copy link
Copy Markdown

There is an issue in commit 9ef58e0:
read-cache: pass 'istate' to stat/mode helper functions

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

Comment thread read-cache.c
static unsigned int st_mode_from_ce(const struct cache_entry *ce)
{
extern int trust_executable_bit, has_symlinks;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the blank line following the extern int ... line could be removed too.

@malon7782 malon7782 force-pushed the refactor-environment branch 2 times, most recently from 7207106 to 51ca686 Compare May 28, 2026 13:04
@gitgitgadget-git
Copy link
Copy Markdown

There is an issue in commit 9ef58e0:
read-cache: pass 'istate' to stat/mode helper functions

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

@gitgitgadget-git
Copy link
Copy Markdown

There is an issue in commit 9ef58e0:
read-cache: pass 'istate' to stat/mode helper functions

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants