]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move "precomposed_unicode" into `struct repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Thu, 23 Apr 2026 16:54:29 +0000 (17:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:35:41 +0000 (19:35 +0900)
The `core.precomposeunicode` configuration is currently stored in the
global variable `precomposed_unicode`, which makes it shared across
repository instances within a single process.

Store it instead in `repo_config_values`, where eagerly‑parsed
repository configuration lives. `core.precomposeunicode` is parsed
eagerly because it controls Unicode path normalization on macOS,
a fundamental filesystem‑level behavior that many operations depend
on; a lazy parse could lead to inconsistent results and hamper
libification. This preserves the existing behavior while tying the
value to the repository from which it was read, avoiding cross‑
repository state leakage and continuing the effort to reduce reliance
on global configuration state.

Change the type of the field from `int` to `bool` since it is parsed
as a boolean value.

Update all references to use `repo_config_values()`.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/precompose_utf8.c
environment.c
environment.h
upload-pack.c

index 43b3be011439ef9921b5c6a353526ff43116164f..0e94dbd862980571c5674ab32b999f2a3c559154 100644 (file)
@@ -48,16 +48,18 @@ void probe_utf8_pathname_composition(void)
        static const char *auml_nfc = "\xc3\xa4";
        static const char *auml_nfd = "\x61\xcc\x88";
        int output_fd;
-       if (precomposed_unicode != -1)
+       struct repo_config_values *cfg = repo_config_values(the_repository);
+
+       if (cfg->precomposed_unicode != -1)
                return; /* We found it defined in the global config, respect it */
        repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
        output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
        if (output_fd >= 0) {
                close(output_fd);
                repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
-               precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
+               cfg->precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
                repo_config_set(the_repository, "core.precomposeunicode",
-                               precomposed_unicode ? "true" : "false");
+                               cfg->precomposed_unicode ? "true" : "false");
                repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
                if (unlink(path.buf))
                        die_errno(_("failed to unlink '%s'"), path.buf);
@@ -69,14 +71,16 @@ const char *precompose_string_if_needed(const char *in)
 {
        size_t inlen;
        size_t outlen;
+       struct repo_config_values *cfg = repo_config_values(the_repository);
+
        if (!in)
                return NULL;
        if (has_non_ascii(in, (size_t)-1, &inlen)) {
                iconv_t ic_prec;
                char *out;
-               if (precomposed_unicode < 0)
-                       repo_config_get_bool(the_repository, "core.precomposeunicode", &precomposed_unicode);
-               if (precomposed_unicode != 1)
+               if (cfg->precomposed_unicode < 0)
+                       repo_config_get_bool(the_repository, "core.precomposeunicode", &cfg->precomposed_unicode);
+               if (cfg->precomposed_unicode != 1)
                        return in;
                ic_prec = iconv_open(repo_encoding, path_encoding);
                if (ic_prec == (iconv_t) -1)
@@ -130,7 +134,9 @@ PREC_DIR *precompose_utf8_opendir(const char *dirname)
 
 struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
 {
+       struct repo_config_values *cfg = repo_config_values(the_repository);
        struct dirent *res;
+
        res = readdir(prec_dir->dirp);
        if (res) {
                size_t namelenz = strlen(res->d_name) + 1; /* \0 */
@@ -149,7 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
                prec_dir->dirent_nfc->d_ino  = res->d_ino;
                prec_dir->dirent_nfc->d_type = res->d_type;
 
-               if ((precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
+               if ((cfg->precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
                        if (prec_dir->ic_precompose == (iconv_t)-1) {
                                die("iconv_open(%s,%s) failed, but needed:\n"
                                                "    precomposed unicode is not supported.\n"
index d0d3a4b7d29e7ee33680af38d2fd63f2c09c9888..739b647ebe0ed120e049bce97d3d502ae89ca75e 100644 (file)
@@ -72,7 +72,6 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
 int grafts_keep_true_parents;
 int core_sparse_checkout_cone;
 int sparse_expect_files_outside_of_patterns;
-int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
 unsigned long pack_size_limit_cfg;
 
 #ifndef PROTECT_HFS_DEFAULT
@@ -532,7 +531,7 @@ int git_default_core_config(const char *var, const char *value,
        }
 
        if (!strcmp(var, "core.precomposeunicode")) {
-               precomposed_unicode = git_config_bool(var, value);
+               cfg->precomposed_unicode = git_config_bool(var, value);
                return 0;
        }
 
@@ -723,4 +722,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
        cfg->check_stat = 1;
        cfg->zlib_compression_level = Z_BEST_SPEED;
        cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
+       cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
 }
index 514576b67a2741b7e8d6b57bb06a97892c584e2a..508cb1afbc9fda96d149ea31b6c0012e8f9a466f 100644 (file)
@@ -95,6 +95,7 @@ struct repo_config_values {
        int check_stat;
        int zlib_compression_level;
        int pack_compression_level;
+       int precomposed_unicode;
 
        /* section "branch" config values */
        enum branch_track branch_track;
@@ -174,7 +175,6 @@ extern char *apply_default_whitespace;
 extern char *apply_default_ignorewhitespace;
 extern unsigned long pack_size_limit_cfg;
 
-extern int precomposed_unicode;
 extern int protect_hfs;
 extern int protect_ntfs;
 
index 9f6d6fe48c8c58070bba6c6fabeaba128473e893..3a52237134ef3b60fbf6db1326f175dee5c4397c 100644 (file)
@@ -1336,6 +1336,7 @@ static int upload_pack_config(const char *var, const char *value,
                              void *cb_data)
 {
        struct upload_pack_data *data = cb_data;
+       struct repo_config_values *cfg = repo_config_values(the_repository);
 
        if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
                if (git_config_bool(var, value))
@@ -1366,7 +1367,7 @@ static int upload_pack_config(const char *var, const char *value,
                if (value)
                        data->allow_packfile_uris = 1;
        } else if (!strcmp("core.precomposeunicode", var)) {
-               precomposed_unicode = git_config_bool(var, value);
+               cfg->precomposed_unicode = git_config_bool(var, value);
        } else if (!strcmp("transfer.advertisesid", var)) {
                data->advertise_sid = git_config_bool(var, value);
        }