Merge branch 'ty/move-protect-hfs-ntfs' into seen

The global configuration variables protect_hfs and protect_ntfs have
been migrated into struct repo_config_values to tie them to
per-repository configuration state.

* ty/move-protect-hfs-ntfs:
  environment: move 'protect_hfs' and 'protect_ntfs' into 'repo_config_values'
This commit is contained in:
Junio C Hamano
2026-06-12 15:58:17 -07:00
5 changed files with 48 additions and 20 deletions

View File

@@ -3405,7 +3405,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);

View File

@@ -73,12 +73,10 @@ unsigned long pack_size_limit_cfg;
#ifndef PROTECT_HFS_DEFAULT
#define PROTECT_HFS_DEFAULT 0
#endif
int protect_hfs = PROTECT_HFS_DEFAULT;
#ifndef PROTECT_NTFS_DEFAULT
#define PROTECT_NTFS_DEFAULT 1
#endif
int protect_ntfs = PROTECT_NTFS_DEFAULT;
/*
* The character that begins a commented line in user-editable file
@@ -140,6 +138,20 @@ int repo_trust_executable_bit(struct repository *repo)
1;
}
int repo_protect_ntfs(struct repository *repo)
{
return repo->gitdir ?
repo_config_values(repo)->protect_ntfs :
PROTECT_NTFS_DEFAULT;
}
int repo_protect_hfs(struct repository *repo)
{
return repo->gitdir ?
repo_config_values(repo)->protect_hfs :
PROTECT_HFS_DEFAULT;
}
int have_git_dir(void)
{
return startup_info->have_repository
@@ -539,12 +551,12 @@ int git_default_core_config(const char *var, const char *value,
}
if (!strcmp(var, "core.protecthfs")) {
protect_hfs = git_config_bool(var, value);
cfg->protect_hfs = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.protectntfs")) {
protect_ntfs = git_config_bool(var, value);
cfg->protect_ntfs = git_config_bool(var, value);
return 0;
}
@@ -723,6 +735,8 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->attributes_file = NULL;
cfg->apply_sparse_checkout = 0;
cfg->trust_executable_bit = 1;
cfg->protect_hfs = PROTECT_HFS_DEFAULT;
cfg->protect_ntfs = PROTECT_NTFS_DEFAULT;
cfg->branch_track = BRANCH_TRACK_REMOTE;
cfg->trust_ctime = 1;
cfg->check_stat = 1;

View File

@@ -99,6 +99,8 @@ struct repo_config_values {
int core_sparse_checkout_cone;
int warn_on_object_refname_ambiguity;
int trust_executable_bit;
int protect_hfs;
int protect_ntfs;
/* section "sparse" config values */
int sparse_expect_files_outside_of_patterns;
@@ -141,6 +143,14 @@ int git_default_core_config(const char *var, const char *value,
*/
int repo_trust_executable_bit(struct repository *repo);
/*
* 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);
/*
@@ -178,9 +188,6 @@ extern char *apply_default_whitespace;
extern char *apply_default_ignorewhitespace;
extern unsigned long pack_size_limit_cfg;
extern int protect_hfs;
extern int protect_ntfs;
enum rebase_setup_type {
AUTOREBASE_NEVER = 0,
AUTOREBASE_LOCAL,

View File

@@ -1013,7 +1013,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;
@@ -1022,7 +1022,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;
@@ -1046,7 +1046,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)) {

View File

@@ -250,6 +250,7 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
double m[3][2], v[3][2];
uint64_t cumul;
double cumul2;
int ntfs, hfs;
if (argc > 1 && !strcmp(argv[1], "--with-symlink-mode")) {
file_mode = 0120000;
@@ -276,8 +277,13 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
names[i][--len] = (char)(' ' + (my_random() % ('\x7f' - ' ')));
}
for (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)
for (protect_hfs = 0; protect_hfs < 2; protect_hfs++) {
if (!the_repository->gitdir)
the_repository->gitdir = xstrdup(".git");
for (ntfs = 0; ntfs < 2; ntfs++)
for (hfs = 0; hfs < 2; hfs++) {
repo_config_values(the_repository)->protect_ntfs = ntfs;
repo_config_values(the_repository)->protect_hfs = hfs;
cumul = 0;
cumul2 = 0;
for (i = 0; i < repetitions; i++) {
@@ -285,18 +291,18 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
for (j = 0; j < nr; j++)
verify_path(names[j], file_mode);
end = getnanotime();
printf("protect_ntfs = %d, protect_hfs = %d: %lfms\n", protect_ntfs, protect_hfs, (end-begin) / (double)1e6);
printf("protect_ntfs = %d, protect_hfs = %d: %lfms\n", ntfs, hfs, (end-begin) / (double)1e6);
cumul += end - begin;
cumul2 += (end - begin) * (end - begin);
}
m[protect_ntfs][protect_hfs] = cumul / (double)repetitions;
v[protect_ntfs][protect_hfs] = my_sqrt(cumul2 / (double)repetitions - m[protect_ntfs][protect_hfs] * m[protect_ntfs][protect_hfs]);
printf("mean: %lfms, stddev: %lfms\n", m[protect_ntfs][protect_hfs] / (double)1e6, v[protect_ntfs][protect_hfs] / (double)1e6);
m[ntfs][hfs] = cumul / (double)repetitions;
v[ntfs][hfs] = my_sqrt(cumul2 / (double)repetitions - m[ntfs][hfs] * m[ntfs][hfs]);
printf("mean: %lfms, stddev: %lfms\n", m[ntfs][hfs] / (double)1e6, v[ntfs][hfs] / (double)1e6);
}
for (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)
for (protect_hfs = 0; protect_hfs < 2; protect_hfs++)
printf("ntfs=%d/hfs=%d: %lf%% slower\n", protect_ntfs, protect_hfs, (m[protect_ntfs][protect_hfs] - m[0][0]) * 100 / m[0][0]);
for (ntfs = 0; ntfs < 2; ntfs++)
for (hfs = 0; hfs < 2; hfs++)
printf("ntfs=%d/hfs=%d: %lf%% slower\n", ntfs, hfs, (m[ntfs][hfs] - m[0][0]) * 100 / m[0][0]);
return 0;
}