From: Christian Couder Date: Tue, 09 Jun 2026 10:54:26 GMT Subject: Re: [PATCH v1 0/1] environment: move protect_hfs and protect_ntfs Message-ID: In-Reply-To: <20260606143412.15443-2-cat@malon.dev> On Sat, Jun 6, 2026 at 4:35 PM Tian Yuchen wrote: > > Hi everyone, > > This series continues the ongoing libification effort by moving the > global **filesystem** variables, protect_hfs and protect_ntfs, into > struct repo_config_values. > > Place them within the **per-repository** configuration structure > aligns with our goal of removing global states. > > RFC Questions: > > 1. Should we keep PROTECT_HFS_DEFAULT and PROTECT_NTFS_DEFAULT > in repo_config_values_init()? > > void repo_config_values_init(struct repo_config_values *cfg) > { > cfg->attributes_file = NULL; > cfg->apply_sparse_checkout = 0; > cfg->protect_hfs = PROTECT_HFS_DEFAULT; > cfg->protect_ntfs = PROTECT_NTFS_DEFAULT; > cfg->branch_track = BRANCH_TRACK_REMOTE; > } > > Or is it better if they are used anywhere other than in environment.c? I think it's better to keep them in "environment.c". The repo_protect_ntfs() and repo_protect_hfs() function I suggest adding to "environment.c" in my reply to the patch should help with keeping the macros in "environment.c". > If so... > 2. Is it worth introducing a Macro or Getter for safe access? > > ((the_repository->gitdir ? repo_config_values(the_repository)->protect_hfs : 0)) Yes, it seems to me that a getter is enough. > The current approach looks verbose and lacks readability, and > hard-coded 0 and 1 are used as fallback values. I wonder if a macro or a > getter could be introduced, for example... > > #define SAFE_PROTECT_HFS(repo) \ > (((repo) && (repo)->gitdir && (repo) == the_repository) ? \ > repo_config_values(repo)->protect_hfs : PROTECT_HFS_DEFAULT) > > ...to improve the coding style a bit. Although I am aware that introducing > new macros is generally frowned upon, I would still like to know which > parts this might make difficult to maintain. Unless there are features that we really want which a function can't provide, a function is better as it provides type safety and is usually easier to maintain. > 3. Note that Derrick attempted to use get_int_config_global to wrap > this kind of Filesystem Level global variables. This approach bypassed > struct repository, did not actually eliminate global state, and the > reviewer politely rejected it. Nevertheless, I am still curious as > to whether this approach might still be inspiring today. > > https://lore.kernel.org/git/a42dd9397d07b2dc4a0d7e75bfe1af2e46cad262.1685716420.git.gitgitgadget@gmail.com/ To help your reviewers, it might be interesting if you could already tell why this was rejected by Glen Choo (who reviewed Derrick Stolee's work then). It seems to me that Glen said that using plain fields in a struct should be better as long as the fields are always initialized during the setup process. And it seems to me that our patch follows the direction that Glen suggested. Thanks.