{"thread":{"id":"65843","subject":"[PATCH v4 0/1] environment: move protect_hfs and protect_ntfs into repo_config_values","startedAt":"2026-06-19T16:38:38Z","lastAt":"2026-06-20T15:18:04Z","messageCount":7,"participants":["Tian Yuchen","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":1},"messages":[{"id":"545998","messageId":"20260619163823.652091-1-cat@malon.dev","threadId":"65843","inReplyTo":null,"subject":"[PATCH v4 0/1] environment: move protect_hfs and protect_ntfs into repo_config_values","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-06-19T16:38:22Z","receivedAt":"2026-06-19T16:38:38Z","isPatch":true,"body":"Hi everyone,\n\nThis series continues the ongoing libification effort by moving the\nglobal filesystem variables, 'protect_hfs' and 'protect_ntfs', into\n'struct repo_config_values'.\n\nPlace them within the per-repository configuration structure\naligns with our goal of removing global states.\n\nFor reviewers familiar with previous libification efforts, Derrick Stolee\nattempted to wrap this kind of filesystem-level variable using a\nlazy-loaded global accessor get_int_config_global() [1].\n\nHowever, as Glen Choo pointed out in his review of that series [2],\nit is strongly preferred to use plain fields in a repository-scoped\nstruct over global lazy-loaders, provided those fields are properly\ninitialized during the setup process.\n\nBy moving these variables into repo_config_values and parsing\nthem eagerly, we successfully tie the filesystem security flags\nto the specific repository instance without altering the timing\nof configuration warnings or introducing new global states.\n\nThanks!\n\nChange since V3:\n\n - In repo_protect_hfs() and repo_protect_ntfs(), change repo->gitdir to\n using (repo && repo->initialized).\n\n[1] https://lore.kernel.org/git/a42dd9397d07b2dc4a0d7e75bfe1af2e46cad262.1685716420.git.gitgitgadget@gmail.com/\n[2] https://lore.kernel.org/git/kl6lbkhpzujf.fsf@chooglen-macbookpro.roam.corp.google.com/\n[3] https://lore.kernel.org/git/20260612160527.167203-1-cat@malon.dev/\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>\nMentored-by: Olamide Caleb Bello <belkid98@gmail.com>\nSigned-off-by: Tian Yuchen <cat@malon.dev>\n\nTian Yuchen (1):\n  environment: move 'protect_hfs' and 'protect_ntfs' into\n    'repo_config_values'\n\n compat/mingw.c             |  2 +-\n environment.c              | 22 ++++++++++++++++++----\n environment.h              | 12 ++++++++++--\n read-cache.c               |  7 ++++---\n t/helper/test-path-utils.c | 24 +++++++++++++++---------\n 5 files changed, 48 insertions(+), 19 deletions(-)\n\n-- \n2.43.0\n\n"},{"id":"545999","messageId":"20260619163823.652091-2-cat@malon.dev","threadId":"65843","inReplyTo":"20260619163823.652091-1-cat@malon.dev","subject":"[PATCH v4 1/1] environment: move 'protect_hfs' and 'protect_ntfs' into 'repo_config_values'","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-06-19T16:38:23Z","receivedAt":"2026-06-19T16:38:41Z","isPatch":true,"body":"Move the global 'protect_hfs' and 'protect_ntfs' configurations\ninto the repository-specific 'repo_config_values' struct.\nThis will help with the elimination of 'the_repository'\n\nTo ensure code readability, the getter functions\n'repo_protect_hfs()' and 'repo_protect_ntfs()'\nhave been introduced.\n\nFor now, associated functions access this configuration by\nexplicitly falling back to 'the_repository', which needs to\nbe addressed in the future.\n\nNote: In 't/helper/test-path-utils.c', there is a function\n'protect_ntfs_hfs_benchmark()' where these two global\nvariables are used as loop iterators. New local variables\nhave been created to replace them.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>\nMentored-by: Olamide Caleb Bello <belkid98@gmail.com>\nSigned-off-by: Tian Yuchen <cat@malon.dev>\n---\n compat/mingw.c             |  2 +-\n environment.c              | 22 ++++++++++++++++++----\n environment.h              | 12 ++++++++++--\n read-cache.c               |  7 ++++---\n t/helper/test-path-utils.c | 24 +++++++++++++++---------\n 5 files changed, 48 insertions(+), 19 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex aa7525f419..af87df77fd 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -3392,7 +3392,7 @@ int is_valid_win32_path(const char *path, int allow_literal_nul)\n \tconst char *p = path;\n \tint preceding_space_or_period = 0, i = 0, periods = 0;\n \n-\tif (!protect_ntfs)\n+\tif (!repo_protect_ntfs(the_repository))\n \t\treturn 1;\n \n \tskip_dos_drive_prefix((char **)&path);\ndiff --git a/environment.c b/environment.c\nindex fc3ed8bb1c..f34f6fc750 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -82,12 +82,10 @@ unsigned long pack_size_limit_cfg;\n #ifndef PROTECT_HFS_DEFAULT\n #define PROTECT_HFS_DEFAULT 0\n #endif\n-int protect_hfs = PROTECT_HFS_DEFAULT;\n \n #ifndef PROTECT_NTFS_DEFAULT\n #define PROTECT_NTFS_DEFAULT 1\n #endif\n-int protect_ntfs = PROTECT_NTFS_DEFAULT;\n \n /*\n  * The character that begins a commented line in user-editable file\n@@ -142,6 +140,20 @@ int is_bare_repository(void)\n \treturn is_bare_repository_cfg && !repo_get_work_tree(the_repository);\n }\n \n+int repo_protect_ntfs(struct repository *repo)\n+{\n+\treturn (repo && repo->initialized) ?\n+\t\trepo_config_values(repo)->protect_ntfs :\n+\t\tPROTECT_NTFS_DEFAULT;\n+}\n+\n+int repo_protect_hfs(struct repository *repo)\n+{\n+\treturn (repo && repo->initialized) ?\n+\t\trepo_config_values(repo)->protect_hfs :\n+\t\tPROTECT_HFS_DEFAULT;\n+}\n+\n int have_git_dir(void)\n {\n \treturn startup_info->have_repository\n@@ -541,12 +553,12 @@ int git_default_core_config(const char *var, const char *value,\n \t}\n \n \tif (!strcmp(var, \"core.protecthfs\")) {\n-\t\tprotect_hfs = git_config_bool(var, value);\n+\t\tcfg->protect_hfs = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n \n \tif (!strcmp(var, \"core.protectntfs\")) {\n-\t\tprotect_ntfs = git_config_bool(var, value);\n+\t\tcfg->protect_ntfs = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n \n@@ -720,5 +732,7 @@ void repo_config_values_init(struct repo_config_values *cfg)\n {\n \tcfg->attributes_file = NULL;\n \tcfg->apply_sparse_checkout = 0;\n+\tcfg->protect_hfs = PROTECT_HFS_DEFAULT;\n+\tcfg->protect_ntfs = PROTECT_NTFS_DEFAULT;\n \tcfg->branch_track = BRANCH_TRACK_REMOTE;\n }\ndiff --git a/environment.h b/environment.h\nindex 9eb97b3869..b1ae4a70de 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -91,6 +91,8 @@ struct repo_config_values {\n \t/* section \"core\" config values */\n \tchar *attributes_file;\n \tint apply_sparse_checkout;\n+\tint protect_hfs;\n+\tint protect_ntfs;\n \n \t/* section \"branch\" config values */\n \tenum branch_track branch_track;\n@@ -123,6 +125,14 @@ int git_default_config(const char *, const char *,\n int git_default_core_config(const char *var, const char *value,\n \t\t\t    const struct config_context *ctx, void *cb);\n \n+/*\n+ * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n+ * They check `repo->initialized` to prevent calling `repo_config_values()`\n+ * before the repository setup is fully complete or in non-git environments.\n+ */\n+int repo_protect_hfs(struct repository *repo);\n+int repo_protect_ntfs(struct repository *repo);\n+\n void repo_config_values_init(struct repo_config_values *cfg);\n \n /*\n@@ -173,8 +183,6 @@ extern int pack_compression_level;\n extern unsigned long pack_size_limit_cfg;\n \n extern int precomposed_unicode;\n-extern int protect_hfs;\n-extern int protect_ntfs;\n \n extern int core_sparse_checkout_cone;\n extern int sparse_expect_files_outside_of_patterns;\ndiff --git a/read-cache.c b/read-cache.c\nindex 21829102ae..2c6a60c756 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1002,7 +1002,7 @@ static enum verify_path_result verify_path_internal(const char *path,\n \t\t\treturn PATH_OK;\n \t\tif (is_dir_sep(c)) {\n inside:\n-\t\t\tif (protect_hfs) {\n+\t\t\tif (repo_protect_hfs(the_repository)) {\n \n \t\t\t\tif (is_hfs_dotgit(path))\n \t\t\t\t\treturn PATH_INVALID;\n@@ -1011,7 +1011,7 @@ static enum verify_path_result verify_path_internal(const char *path,\n \t\t\t\t\t\treturn PATH_INVALID;\n \t\t\t\t}\n \t\t\t}\n-\t\t\tif (protect_ntfs) {\n+\t\t\tif (repo_protect_ntfs(the_repository)) {\n #if defined GIT_WINDOWS_NATIVE || defined __CYGWIN__\n \t\t\t\tif (c == '\\\\')\n \t\t\t\t\treturn PATH_INVALID;\n@@ -1035,7 +1035,8 @@ static enum verify_path_result verify_path_internal(const char *path,\n \t\t\tif (c == '\\0')\n \t\t\t\treturn S_ISDIR(mode) ? PATH_DIR_WITH_SEP :\n \t\t\t\t\t\t       PATH_INVALID;\n-\t\t} else if (c == '\\\\' && protect_ntfs) {\n+\t\t} else if (c == '\\\\' &&\n+\t\t\t   repo_protect_ntfs(the_repository)) {\n \t\t\tif (is_ntfs_dotgit(path))\n \t\t\t\treturn PATH_INVALID;\n \t\t\tif (S_ISLNK(mode)) {\ndiff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c\nindex 15eb44485c..f77b3f9d70 100644\n--- a/t/helper/test-path-utils.c\n+++ b/t/helper/test-path-utils.c\n@@ -250,6 +250,7 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)\n \tdouble m[3][2], v[3][2];\n \tuint64_t cumul;\n \tdouble cumul2;\n+\tint ntfs, hfs;\n \n \tif (argc > 1 && !strcmp(argv[1], \"--with-symlink-mode\")) {\n \t\tfile_mode = 0120000;\n@@ -276,8 +277,13 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)\n \t\t\tnames[i][--len] = (char)(' ' + (my_random() % ('\\x7f' - ' ')));\n \t}\n \n-\tfor (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)\n-\t\tfor (protect_hfs = 0; protect_hfs < 2; protect_hfs++) {\n+\tif (!the_repository->gitdir)\n+\t\tthe_repository->gitdir = xstrdup(\".git\");\n+\n+\tfor (ntfs = 0; ntfs < 2; ntfs++)\n+\t\tfor (hfs = 0; hfs < 2; hfs++) {\n+\t\t\trepo_config_values(the_repository)->protect_ntfs = ntfs;\n+\t\t\trepo_config_values(the_repository)->protect_hfs = hfs;\n \t\t\tcumul = 0;\n \t\t\tcumul2 = 0;\n \t\t\tfor (i = 0; i < repetitions; i++) {\n@@ -285,18 +291,18 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)\n \t\t\t\tfor (j = 0; j < nr; j++)\n \t\t\t\t\tverify_path(names[j], file_mode);\n \t\t\t\tend = getnanotime();\n-\t\t\t\tprintf(\"protect_ntfs = %d, protect_hfs = %d: %lfms\\n\", protect_ntfs, protect_hfs, (end-begin) / (double)1e6);\n+\t\t\t\tprintf(\"protect_ntfs = %d, protect_hfs = %d: %lfms\\n\", ntfs, hfs, (end-begin) / (double)1e6);\n \t\t\t\tcumul += end - begin;\n \t\t\t\tcumul2 += (end - begin) * (end - begin);\n \t\t\t}\n-\t\t\tm[protect_ntfs][protect_hfs] = cumul / (double)repetitions;\n-\t\t\tv[protect_ntfs][protect_hfs] = my_sqrt(cumul2 / (double)repetitions - m[protect_ntfs][protect_hfs] * m[protect_ntfs][protect_hfs]);\n-\t\t\tprintf(\"mean: %lfms, stddev: %lfms\\n\", m[protect_ntfs][protect_hfs] / (double)1e6, v[protect_ntfs][protect_hfs] / (double)1e6);\n+\t\t\tm[ntfs][hfs] = cumul / (double)repetitions;\n+\t\t\tv[ntfs][hfs] = my_sqrt(cumul2 / (double)repetitions - m[ntfs][hfs] * m[ntfs][hfs]);\n+\t\t\tprintf(\"mean: %lfms, stddev: %lfms\\n\", m[ntfs][hfs] / (double)1e6, v[ntfs][hfs] / (double)1e6);\n \t\t}\n \n-\tfor (protect_ntfs = 0; protect_ntfs < 2; protect_ntfs++)\n-\t\tfor (protect_hfs = 0; protect_hfs < 2; protect_hfs++)\n-\t\t\tprintf(\"ntfs=%d/hfs=%d: %lf%% slower\\n\", protect_ntfs, protect_hfs, (m[protect_ntfs][protect_hfs] - m[0][0]) * 100 / m[0][0]);\n+\tfor (ntfs = 0; ntfs < 2; ntfs++)\n+\t\tfor (hfs = 0; hfs < 2; hfs++)\n+\t\t\tprintf(\"ntfs=%d/hfs=%d: %lf%% slower\\n\", ntfs, hfs, (m[ntfs][hfs] - m[0][0]) * 100 / m[0][0]);\n \n \treturn 0;\n }\n-- \n2.43.0\n\n"},{"id":"546003","messageId":"xmqqo6h6jvuk.fsf@gitster.g","threadId":"65843","inReplyTo":"20260619163823.652091-1-cat@malon.dev","subject":"Re: [PATCH v4 0/1] environment: move protect_hfs and protect_ntfs into repo_config_values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-06-19T17:14:43Z","receivedAt":"2026-06-19T17:14:46Z","isPatch":true,"body":"Tian Yuchen <cat@malon.dev> writes:\n\n> This series continues the ongoing libification effort by moving the\n> global filesystem variables, 'protect_hfs' and 'protect_ntfs', into\n> 'struct repo_config_values'.\n> ...\n> Change since V3:\n>\n>  - In repo_protect_hfs() and repo_protect_ntfs(), change repo->gitdir to\n>  using (repo && repo->initialized).\n\nWhile I think that it is a good change for consistency with other\ntwo topics, the hfs/ntfs topic is already in 'next', so it needs to\nbe handled differently.  Namely, a topic in 'next' should not be\nreplaced, but be improved by additional patches on top.\n\nIn this particular case case, I think it would be good to have \"to\nmatch how we refrain from calling repo_config_values() on an\nuninitialized instance of a repository object in other two topics\nthat deal with X bit and Y bit, check the repo->initialized bit\ninstead of the repo->gitdir member\" or something like that in the\nlog message to explain why we are making the change, perhaps.\n\nThe patch text may look like this.\n\n environment.c | 4 ++--\n environment.h | 4 ++--\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git c/environment.c w/environment.c\nindex 683fe1b4d3..f34f6fc750 100644\n--- c/environment.c\n+++ w/environment.c\n@@ -142,14 +142,14 @@ int is_bare_repository(void)\n \n int repo_protect_ntfs(struct repository *repo)\n {\n-\treturn repo->gitdir ?\n+\treturn (repo && repo->initialized) ?\n \t\trepo_config_values(repo)->protect_ntfs :\n \t\tPROTECT_NTFS_DEFAULT;\n }\n \n int repo_protect_hfs(struct repository *repo)\n {\n-\treturn repo->gitdir ?\n+\treturn (repo && repo->initialized) ?\n \t\trepo_config_values(repo)->protect_hfs :\n \t\tPROTECT_HFS_DEFAULT;\n }\ndiff --git c/environment.h w/environment.h\nindex fdd9775900..b1ae4a70de 100644\n--- c/environment.h\n+++ w/environment.h\n@@ -127,8 +127,8 @@ int git_default_core_config(const char *var, const char *value,\n \n /*\n  * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n- * They check `repo->gitdir` to prevent calling repo_config_values()\n- * before the configuration is loaded or in bare environments.\n+ * They check `repo->initialized` to prevent calling `repo_config_values()`\n+ * before the repository setup is fully complete or in non-git environments.\n  */\n int repo_protect_hfs(struct repository *repo);\n int repo_protect_ntfs(struct repository *repo);\n\n"},{"id":"546004","messageId":"xmqqjyrujvco.fsf@gitster.g","threadId":"65843","inReplyTo":"xmqqo6h6jvuk.fsf@gitster.g","subject":"Re: [PATCH v4 0/1] environment: move protect_hfs and protect_ntfs into repo_config_values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-06-19T17:25:27Z","receivedAt":"2026-06-19T17:25:30Z","isPatch":true,"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> diff --git c/environment.h w/environment.h\n> index fdd9775900..b1ae4a70de 100644\n> --- c/environment.h\n> +++ w/environment.h\n> @@ -127,8 +127,8 @@ int git_default_core_config(const char *var, const char *value,\n>  \n>  /*\n>   * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n> - * They check `repo->gitdir` to prevent calling repo_config_values()\n> - * before the configuration is loaded or in bare environments.\n> + * They check `repo->initialized` to prevent calling `repo_config_values()`\n> + * before the repository setup is fully complete or in non-git environments.\n>   */\n>  int repo_protect_hfs(struct repository *repo);\n>  int repo_protect_ntfs(struct repository *repo);\n\nAnother thing we should remember (but should *NOT* do while these\ntopics are still in flight) to do is to consolidate these comments\ninto one.  The hfs and htfs getters are covered by the same single\ncomment, but ignorecase and trustexecutable bit getters have their\nown comments, only because they came in different topics.  We should\nconslidate them into a single comment block once all of these have\nlanded in 'master', which may happen soon after 2.55 final gets\ntagged.\n\n"},{"id":"546028","messageId":"2dc522ee-30cb-4ea8-997b-406aef85f749@malon.dev","threadId":"65843","inReplyTo":"xmqqjyrujvco.fsf@gitster.g","subject":"Re: [PATCH v4 0/1] environment: move protect_hfs and protect_ntfs into repo_config_values","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-06-20T13:38:42Z","receivedAt":"2026-06-20T13:38:58Z","isPatch":true,"body":"On 6/20/26 01:25, Junio C Hamano wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> diff --git c/environment.h w/environment.h\n>> index fdd9775900..b1ae4a70de 100644\n>> --- c/environment.h\n>> +++ w/environment.h\n>> @@ -127,8 +127,8 @@ int git_default_core_config(const char *var, const char *value,\n>>   \n>>   /*\n>>    * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n>> - * They check `repo->gitdir` to prevent calling repo_config_values()\n>> - * before the configuration is loaded or in bare environments.\n>> + * They check `repo->initialized` to prevent calling `repo_config_values()`\n>> + * before the repository setup is fully complete or in non-git environments.\n>>    */\n>>   int repo_protect_hfs(struct repository *repo);\n>>   int repo_protect_ntfs(struct repository *repo);\n> \n> Another thing we should remember (but should *NOT* do while these\n> topics are still in flight) to do is to consolidate these comments\n> into one.  The hfs and htfs getters are covered by the same single\n> comment, but ignorecase and trustexecutable bit getters have their\n> own comments, only because they came in different topics.  We should\n> conslidate them into a single comment block once all of these have\n> landed in 'master', which may happen soon after 2.55 final gets\n> tagged.\n> \n\nI understand. I’ll send the hfs/ntfs fix patch right away, and will \nclean up the comments once all of the associated patches (there will be \nmore in the next few weeks) have been merged into master. ;)\n\nThanks, yuchen\n"},{"id":"546030","messageId":"20260620140957.667820-1-cat@malon.dev","threadId":"65843","inReplyTo":"xmqqo6h6jvuk.fsf@gitster.g","subject":"[PATCH] environment: use 'repo->initialized' for repo_protect_hfs() and repo_protect_ntfs()","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-06-20T14:09:57Z","receivedAt":"2026-06-20T14:10:18Z","isPatch":true,"body":"To match how we refrain from calling repo_config_values() on an\nuninitialized instance of a repository object in other two topics\nthat deal with ignore_case and trust_executable_bit, check the\nrepo->initialized bit instead of the repo->gitdir member.\n\nBase commit: 43192e7977f5f05138abcdb3212a3f87ab513bef\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>\nMentored-by: Olamide Caleb Bello <belkid98@gmail.com>\nSigned-off-by: Tian Yuchen <cat@malon.dev>\n---\n environment.c | 4 ++--\n environment.h | 4 ++--\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/environment.c b/environment.c\nindex 6ee11e9fc8..8f0c1c4f25 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -130,14 +130,14 @@ int is_bare_repository(struct repository *repo)\n \n int repo_protect_ntfs(struct repository *repo)\n {\n-\treturn repo->gitdir ?\n+\treturn (repo && repo->initialized) ?\n \t\trepo_config_values(repo)->protect_ntfs :\n \t\tPROTECT_NTFS_DEFAULT;\n }\n \n int repo_protect_hfs(struct repository *repo)\n {\n-\treturn repo->gitdir ?\n+\treturn (repo && repo->initialized) ?\n \t\trepo_config_values(repo)->protect_hfs :\n \t\tPROTECT_HFS_DEFAULT;\n }\ndiff --git a/environment.h b/environment.h\nindex d188955f5b..8aaedcfea3 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -137,8 +137,8 @@ int git_default_core_config(const char *var, const char *value,\n \n /*\n  * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n- * They check `repo->gitdir` to prevent calling repo_config_values()\n- * before the configuration is loaded or in bare environments.\n+ * They check `repo->initialized` to prevent calling `repo_config_values()`\n+ * before the repository setup is fully complete or in non-git environments.\n  */\n int repo_protect_hfs(struct repository *repo);\n int repo_protect_ntfs(struct repository *repo);\n-- \n2.43.0\n\n"},{"id":"546034","messageId":"xmqqpl1lfdg6.fsf@gitster.g","threadId":"65843","inReplyTo":"20260620140957.667820-1-cat@malon.dev","subject":"Re: [PATCH] environment: use 'repo->initialized' for repo_protect_hfs() and repo_protect_ntfs()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-06-20T15:18:01Z","receivedAt":"2026-06-20T15:18:04Z","isPatch":true,"body":"Tian Yuchen <cat@malon.dev> writes:\n\n> To match how we refrain from calling repo_config_values() on an\n> uninitialized instance of a repository object in other two topics\n> that deal with ignore_case and trust_executable_bit, check the\n> repo->initialized bit instead of the repo->gitdir member.\n\nOK.\n\n> Base commit: 43192e7977f5f05138abcdb3212a3f87ab513bef\n\nThis line does not belong here.  Besides, you do not build directly\non top of 'next', ever.\n\n> Mentored-by: Christian Couder <christian.couder@gmail.com>\n> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com>\n> Signed-off-by: Tian Yuchen <cat@malon.dev>\n> ---\n>  environment.c | 4 ++--\n>  environment.h | 4 ++--\n>  2 files changed, 4 insertions(+), 4 deletions(-)\n\nI'll queue the change directly on top of ty/move-protect-hfs-ntfs\ntopic, which will be merged to 'next'.\n\nThanks.\n\n> diff --git a/environment.c b/environment.c\n> index 6ee11e9fc8..8f0c1c4f25 100644\n> --- a/environment.c\n> +++ b/environment.c\n> @@ -130,14 +130,14 @@ int is_bare_repository(struct repository *repo)\n>  \n>  int repo_protect_ntfs(struct repository *repo)\n>  {\n> -\treturn repo->gitdir ?\n> +\treturn (repo && repo->initialized) ?\n>  \t\trepo_config_values(repo)->protect_ntfs :\n>  \t\tPROTECT_NTFS_DEFAULT;\n>  }\n>  \n>  int repo_protect_hfs(struct repository *repo)\n>  {\n> -\treturn repo->gitdir ?\n> +\treturn (repo && repo->initialized) ?\n>  \t\trepo_config_values(repo)->protect_hfs :\n>  \t\tPROTECT_HFS_DEFAULT;\n>  }\n> diff --git a/environment.h b/environment.h\n> index d188955f5b..8aaedcfea3 100644\n> --- a/environment.h\n> +++ b/environment.h\n> @@ -137,8 +137,8 @@ int git_default_core_config(const char *var, const char *value,\n>  \n>  /*\n>   * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`.\n> - * They check `repo->gitdir` to prevent calling repo_config_values()\n> - * before the configuration is loaded or in bare environments.\n> + * They check `repo->initialized` to prevent calling `repo_config_values()`\n> + * before the repository setup is fully complete or in non-git environments.\n>   */\n>  int repo_protect_hfs(struct repository *repo);\n>  int repo_protect_ntfs(struct repository *repo);\n"}]}