From: Tian Yuchen <cat@malon.dev>
To: git@vger.kernel.org
Cc: ps@pks.im, Tian Yuchen <cat@malon.dev>,
Christian Couder <christian.couder@gmail.com>,
Ayush Chandekar <ayu.chandekar@gmail.com>,
Olamide Caleb Bello <belkid98@gmail.com>
Subject: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'
Date: Fri, 17 Jul 2026 14:35:57 +0800 [thread overview]
Message-ID: <20260717063559.1633567-3-cat@malon.dev> (raw)
In-Reply-To: <20260717063559.1633567-1-cat@malon.dev>
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>
---
apply.c | 2 +-
builtin/update-index.c | 2 +-
diff-lib.c | 10 +++++-----
read-cache.c | 2 +-
read-cache.h | 15 ++++++++++++---
5 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/apply.c b/apply.c
index 249248d4f2..26286eb57b 100644
--- a/apply.c
+++ b/apply.c
@@ -3894,7 +3894,7 @@ static int check_preimage(struct apply_state *state,
BUG("ce_mode == 0 for path '%s'", old_name);
if (trust_executable_bit || !S_ISREG(st->st_mode))
- st_mode = ce_mode_from_stat(*ce, st->st_mode);
+ st_mode = ce_mode_from_stat(state->repo, *ce, st->st_mode);
else if (*ce)
st_mode = (*ce)->ce_mode;
else
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 8a5907767b..7917bd286f 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -293,7 +293,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len;
fill_stat_cache_info(the_repository->index, ce, st);
- ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
+ ce->ce_mode = ce_mode_from_stat(the_repository, old, st->st_mode);
if (index_path(the_repository->index, &ce->oid, path, st,
info_only ? 0 : INDEX_WRITE_OBJECT)) {
diff --git a/diff-lib.c b/diff-lib.c
index ae91027a02..46cae637ec 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
changed = check_removed(ce, &st);
if (!changed)
- wt_mode = ce_mode_from_stat(ce, st.st_mode);
+ wt_mode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
else {
if (changed < 0) {
perror(ce->name);
@@ -193,7 +193,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
num_compare_stages++;
oidcpy(&dpath->parent[stage - 2].oid,
&nce->oid);
- dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
+ dpath->parent[stage-2].mode = ce_mode_from_stat(revs->repo, nce, mode);
dpath->parent[stage-2].status =
DIFF_STATUS_MODIFIED;
}
@@ -262,7 +262,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
continue;
} else if (revs->diffopt.ita_invisible_in_index &&
ce_intent_to_add(ce)) {
- newmode = ce_mode_from_stat(ce, st.st_mode);
+ newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
diff_addremove(&revs->diffopt, '+', newmode,
null_oid(the_hash_algo), 0, ce->name, 0);
continue;
@@ -270,7 +270,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
ce_option, &dirty_submodule);
- newmode = ce_mode_from_stat(ce, st.st_mode);
+ newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
}
if (!changed && !dirty_submodule) {
@@ -338,7 +338,7 @@ static int get_stat_data(const struct cache_entry *ce,
changed = match_stat_with_submodule(diffopt, ce, &st,
0, dirty_submodule);
if (changed) {
- mode = ce_mode_from_stat(ce, st.st_mode);
+ mode = ce_mode_from_stat(diffopt->repo, ce, st.st_mode);
oid = null_oid(the_hash_algo);
}
}
diff --git a/read-cache.c b/read-cache.c
index c44e4d128f..b37bf688ec 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -749,7 +749,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
int pos = index_name_pos_also_unmerged(istate, path, namelen);
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, ent, st_mode);
}
/* When core.ignorecase=true, determine if a directory of the same name but differing
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,
+ 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
next prev parent reply other threads:[~2026-07-17 6:36 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 16:05 [PATCH v1 0/4] environment.c: migrate 'trust_executable_bit' into 'repo_config_values' Tian Yuchen
2026-05-30 16:05 ` [PATCH v1 1/4] read-cache: remove redundant extern declarations Tian Yuchen
2026-05-30 16:05 ` [PATCH v1 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-06-04 6:47 ` Patrick Steinhardt
2026-06-10 8:30 ` Tian Yuchen
2026-05-30 16:05 ` [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values Tian Yuchen
2026-05-30 18:02 ` Christian Couder
2026-05-30 23:17 ` Junio C Hamano
2026-06-01 10:10 ` Tian Yuchen
2026-06-01 18:03 ` Tian Yuchen
2026-06-09 13:45 ` Junio C Hamano
2026-05-30 16:05 ` [PATCH v1 4/4] read-cache: pass 'istate' to stat/mode helper functions Tian Yuchen
2026-05-30 18:14 ` Christian Couder
2026-06-10 9:36 ` [PATCH v2 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values' Tian Yuchen
2026-06-10 9:36 ` [PATCH v2 1/3] read-cache: remove redundant extern declarations Tian Yuchen
2026-06-10 9:36 ` [PATCH v2 2/3] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-06-12 7:43 ` Christian Couder
2026-06-10 9:36 ` [PATCH v2 3/3] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-06-11 2:58 ` Tian Yuchen
2026-06-12 7:48 ` Christian Couder
2026-06-12 15:21 ` Junio C Hamano
2026-06-12 16:05 ` [PATCH v3 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values' Tian Yuchen
2026-06-12 16:05 ` [PATCH v3 1/3] read-cache: remove redundant extern declarations Tian Yuchen
2026-06-12 16:05 ` [PATCH v3 2/3] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-06-12 16:05 ` [PATCH v3 3/3] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-06-19 16:21 ` [PATCH v4 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values' Tian Yuchen
2026-06-19 16:21 ` [PATCH v4 1/3] read-cache: remove redundant extern declarations Tian Yuchen
2026-06-19 16:21 ` [PATCH v4 2/3] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-06-19 16:21 ` [PATCH v4 3/3] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-06-29 20:55 ` [PATCH v4 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values' Junio C Hamano
2026-07-15 3:28 ` Tian Yuchen
2026-07-15 3:54 ` [PATCH v5 0/4] environment: migrate 'trust_executable_bit' and 'has_symlinks' " Tian Yuchen
2026-07-15 3:54 ` [PATCH v5 1/4] read-cache: remove redundant extern declarations Tian Yuchen
2026-07-15 3:54 ` [PATCH v5 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-07-15 3:55 ` [PATCH v5 3/4] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-07-15 3:55 ` [PATCH v5 4/4] environment: move has_symlinks " Tian Yuchen
2026-07-15 6:21 ` Christian Couder
2026-07-15 17:18 ` Junio C Hamano
2026-07-15 18:23 ` Junio C Hamano
2026-07-16 8:49 ` [PATCH v6 0/4] environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values' Tian Yuchen
2026-07-16 8:49 ` [PATCH v6 1/4] read-cache: remove redundant extern declarations Tian Yuchen
2026-07-16 8:49 ` [PATCH v6 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c' Tian Yuchen
2026-07-16 20:20 ` Junio C Hamano
2026-07-16 8:49 ` [PATCH v6 3/4] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-07-16 8:49 ` [PATCH v6 4/4] environment: move has_symlinks " Tian Yuchen
2026-07-16 20:27 ` Junio C Hamano
2026-07-17 6:35 ` [PATCH v7 0/4] environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values' Tian Yuchen
2026-07-17 6:35 ` [PATCH v7 1/4] read-cache: remove redundant extern declarations Tian Yuchen
2026-07-17 6:35 ` Tian Yuchen [this message]
2026-07-17 6:35 ` [PATCH v7 3/4] environment: move trust_executable_bit into repo_config_values Tian Yuchen
2026-07-17 16:01 ` Junio C Hamano
2026-07-17 6:35 ` [PATCH v7 4/4] environment: move has_symlinks " Tian Yuchen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260717063559.1633567-3-cat@malon.dev \
--to=cat@malon.dev \
--cc=ayu.chandekar@gmail.com \
--cc=belkid98@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox