environment: move 'protect_hfs' and 'protect_ntfs' into 'repo_config_values'
Move the global 'protect_hfs' and 'protect_ntfs' configurations
into the repository-specific 'repo_config_values' struct.
This will help with the elimination of 'the_repository'
To ensure code readability, the getter functions
'repo_protect_hfs()' and 'repo_protect_ntfs()'
have been introduced.
For now, associated functions access this configuration by
explicitly falling back to 'the_repository', which needs to
be addressed in the future.
Note: In 't/helper/test-path-utils.c', there is a function
'protect_ntfs_hfs_benchmark()' where these two global
variables are used as loop iterators. New local variables
have been created to replace them.
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tian Yuchen committedJun 10, 2026 at 20:43 UTC71386c21dfb7cea181df6707c34cd79b10fc0a2b
5 files changed+48-19
compat/mingw.c
+1-1
index aa7525f419..af87df77fd 100644--- a/compat/mingw.c+++ b/compat/mingw.c@@ -3392,7 +3392,7 @@ int is_valid_win32_path(const char *path, int allow_literal_nul) const char *p = path; int preceding_space_or_period = 0, i = 0, periods = 0;- if (!protect_ntfs)+ if (!repo_protect_ntfs(the_repository)) return 1; skip_dos_drive_prefix((char **)&path);
index 9eb97b3869..fdd9775900 100644--- a/environment.h+++ b/environment.h@@ -91,6 +91,8 @@ struct repo_config_values { /* section "core" config values */ char *attributes_file; int apply_sparse_checkout;+ int protect_hfs;+ int protect_ntfs; /* section "branch" config values */ enum branch_track branch_track;@@ -123,6 +125,14 @@ int git_default_config(const char *, const char *, int git_default_core_config(const char *var, const char *value, const struct config_context *ctx, void *cb);+/*+ * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.+ * They check `repo->gitdir` to prevent calling repo_config_values()+ * before the configuration is loaded or in bare environments.+ */+int repo_protect_hfs(struct repository *repo);+int repo_protect_ntfs(struct repository *repo);+ void repo_config_values_init(struct repo_config_values *cfg); /*@@ -173,8 +183,6 @@ extern int pack_compression_level; extern unsigned long pack_size_limit_cfg; extern int precomposed_unicode;-extern int protect_hfs;-extern int protect_ntfs; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns;
read-cache.c
+4-3
index 21829102ae..2c6a60c756 100644--- a/read-cache.c+++ b/read-cache.c@@ -1002,7 +1002,7 @@ static enum verify_path_result verify_path_internal(const char *path, return PATH_OK; if (is_dir_sep(c)) { inside:- if (protect_hfs) {+ if (repo_protect_hfs(the_repository)) { if (is_hfs_dotgit(path)) return PATH_INVALID;@@ -1011,7 +1011,7 @@ inside: return PATH_INVALID; } }- if (protect_ntfs) {+ if (repo_protect_ntfs(the_repository)) { #if defined GIT_WINDOWS_NATIVE || defined __CYGWIN__ if (c == '\\') return PATH_INVALID;@@ -1035,7 +1035,8 @@ inside: if (c == '\0') return S_ISDIR(mode) ? PATH_DIR_WITH_SEP : PATH_INVALID;- } else if (c == '\\' && protect_ntfs) {+ } else if (c == '\\' &&+ repo_protect_ntfs(the_repository)) { if (is_ntfs_dotgit(path)) return PATH_INVALID; if (S_ISLNK(mode)) {