Skip to content

Commit 0781465

Browse files
committed
environment: move "precomposed_unicode" into struct repo_config_values
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` so the value is associated with the repository from which it was read. This preserves existing behavior while avoiding cross-repository state leakage and is another step toward eliminating repository-dependent global state. 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>
1 parent 1b6036c commit 0781465

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

compat/precompose_utf8.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ void probe_utf8_pathname_composition(void)
4848
static const char *auml_nfc = "\xc3\xa4";
4949
static const char *auml_nfd = "\x61\xcc\x88";
5050
int output_fd;
51-
if (precomposed_unicode != -1)
51+
struct repo_config_values *cfg = repo_config_values(the_repository);
52+
53+
if (cfg->precomposed_unicode != -1)
5254
return; /* We found it defined in the global config, respect it */
5355
repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
5456
output_fd = open(path.buf, O_CREAT|O_EXCL|O_RDWR, 0600);
5557
if (output_fd >= 0) {
5658
close(output_fd);
5759
repo_git_path_replace(the_repository, &path, "%s", auml_nfd);
58-
precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
60+
cfg->precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
5961
repo_config_set(the_repository, "core.precomposeunicode",
60-
precomposed_unicode ? "true" : "false");
62+
cfg->precomposed_unicode ? "true" : "false");
6163
repo_git_path_replace(the_repository, &path, "%s", auml_nfc);
6264
if (unlink(path.buf))
6365
die_errno(_("failed to unlink '%s'"), path.buf);
@@ -69,14 +71,16 @@ const char *precompose_string_if_needed(const char *in)
6971
{
7072
size_t inlen;
7173
size_t outlen;
74+
struct repo_config_values *cfg = repo_config_values(the_repository);
75+
7276
if (!in)
7377
return NULL;
7478
if (has_non_ascii(in, (size_t)-1, &inlen)) {
7579
iconv_t ic_prec;
7680
char *out;
77-
if (precomposed_unicode < 0)
78-
repo_config_get_bool(the_repository, "core.precomposeunicode", &precomposed_unicode);
79-
if (precomposed_unicode != 1)
81+
if (cfg->precomposed_unicode < 0)
82+
repo_config_get_bool(the_repository, "core.precomposeunicode", &cfg->precomposed_unicode);
83+
if (cfg->precomposed_unicode != 1)
8084
return in;
8185
ic_prec = iconv_open(repo_encoding, path_encoding);
8286
if (ic_prec == (iconv_t) -1)
@@ -130,7 +134,9 @@ PREC_DIR *precompose_utf8_opendir(const char *dirname)
130134

131135
struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
132136
{
137+
struct repo_config_values *cfg = repo_config_values(the_repository);
133138
struct dirent *res;
139+
134140
res = readdir(prec_dir->dirp);
135141
if (res) {
136142
size_t namelenz = strlen(res->d_name) + 1; /* \0 */
@@ -149,7 +155,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
149155
prec_dir->dirent_nfc->d_ino = res->d_ino;
150156
prec_dir->dirent_nfc->d_type = res->d_type;
151157

152-
if ((precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
158+
if ((cfg->precomposed_unicode == 1) && has_non_ascii(res->d_name, (size_t)-1, NULL)) {
153159
if (prec_dir->ic_precompose == (iconv_t)-1) {
154160
die("iconv_open(%s,%s) failed, but needed:\n"
155161
" precomposed unicode is not supported.\n"

environment.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
7272
int grafts_keep_true_parents;
7373
int core_sparse_checkout_cone;
7474
int sparse_expect_files_outside_of_patterns;
75-
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7675
unsigned long pack_size_limit_cfg;
7776

7877
#ifndef PROTECT_HFS_DEFAULT
@@ -532,7 +531,7 @@ int git_default_core_config(const char *var, const char *value,
532531
}
533532

534533
if (!strcmp(var, "core.precomposeunicode")) {
535-
precomposed_unicode = git_config_bool(var, value);
534+
cfg->precomposed_unicode = git_config_bool(var, value);
536535
return 0;
537536
}
538537

@@ -741,5 +740,6 @@ void repo_config_values_init(struct repo_config_values *cfg)
741740
cfg->trust_ctime = 1;
742741
cfg->check_stat = 1;
743742
cfg->zlib_compression_level = Z_BEST_SPEED;
744-
cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
743+
cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
744+
cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
745745
}

environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct repo_config_values {
9494
int check_stat;
9595
int zlib_compression_level;
9696
int pack_compression_level;
97+
int precomposed_unicode;
9798

9899
/* section "branch" config values */
99100
enum branch_track branch_track;
@@ -173,7 +174,6 @@ extern char *apply_default_whitespace;
173174
extern char *apply_default_ignorewhitespace;
174175
extern unsigned long pack_size_limit_cfg;
175176

176-
extern int precomposed_unicode;
177177
extern int protect_hfs;
178178
extern int protect_ntfs;
179179

upload-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ static int upload_pack_config(const char *var, const char *value,
13561356
void *cb_data)
13571357
{
13581358
struct upload_pack_data *data = cb_data;
1359+
struct repo_config_values *cfg = repo_config_values(the_repository);
13591360

13601361
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
13611362
if (git_config_bool(var, value))
@@ -1386,7 +1387,7 @@ static int upload_pack_config(const char *var, const char *value,
13861387
if (value)
13871388
data->allow_packfile_uris = 1;
13881389
} else if (!strcmp("core.precomposeunicode", var)) {
1389-
precomposed_unicode = git_config_bool(var, value);
1390+
cfg->precomposed_unicode = git_config_bool(var, value);
13901391
} else if (!strcmp("transfer.advertisesid", var)) {
13911392
data->advertise_sid = git_config_bool(var, value);
13921393
}

0 commit comments

Comments
 (0)