Skip to content

Commit eec15b7

Browse files
committed
Merge branch 'ty/migrate-ignorecase' into seen
The global configuration variable ignore_case (representing the core.ignorecase configuration) has been migrated into struct repo_config_values to tie it to a specific repository instance. * ty/migrate-ignorecase: config: use repo_ignore_case() to access core.ignorecase environment: move ignore_case into repo_config_values
2 parents 4ef90ab + 573cb8d commit eec15b7

14 files changed

Lines changed: 43 additions & 28 deletions

File tree

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4008,7 +4008,7 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
40084008
struct cache_entry *ce;
40094009

40104010
ce = index_file_exists(state->repo->index, name->buf,
4011-
name->len, ignore_case);
4011+
name->len, repo_ignore_case(the_repository));
40124012
if (ce && S_ISLNK(ce->ce_mode))
40134013
return 1;
40144014
} else {

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ static void ref_transaction_rejection_handler(const char *refname,
18351835
{
18361836
struct ref_rejection_data *data = cb_data;
18371837

1838-
if (err == REF_TRANSACTION_ERROR_CASE_CONFLICT && ignore_case &&
1838+
if (err == REF_TRANSACTION_ERROR_CASE_CONFLICT && repo_ignore_case(the_repository) &&
18391839
!data->case_sensitive_msg_shown) {
18401840
error(_("You're on a case-insensitive filesystem, and the remote you are\n"
18411841
"trying to fetch from has references that only differ in casing. It\n"

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ int cmd_mv(int argc,
419419
goto act_on_entry;
420420
}
421421
if (lstat(dst, &st) == 0 &&
422-
(!ignore_case || strcasecmp(src, dst))) {
422+
(!repo_ignore_case(the_repository) || strcasecmp(src, dst))) {
423423
bad = _("destination exists");
424424
if (force) {
425425
/*

compat/win32/path-utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../../git-compat-util.h"
44
#include "../../environment.h"
5+
#include "../../repository.h"
56

67
int win32_has_dos_drive_prefix(const char *path)
78
{
@@ -75,7 +76,7 @@ int win32_fspathncmp(const char *a, const char *b, size_t count)
7576
} else if (is_dir_sep(*b))
7677
return +1;
7778

78-
diff = ignore_case ?
79+
diff = repo_ignore_case(the_repository) ?
7980
(unsigned char)tolower(*a) - (int)(unsigned char)tolower(*b) :
8081
(unsigned char)*a - (int)(unsigned char)*b;
8182
if (diff)

dir.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int count_slashes(const char *s)
126126

127127
int git_fspathcmp(const char *a, const char *b)
128128
{
129-
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
129+
return repo_ignore_case(the_repository) ? strcasecmp(a, b) : strcmp(a, b);
130130
}
131131

132132
int fspatheq(const char *a, const char *b)
@@ -136,7 +136,7 @@ int fspatheq(const char *a, const char *b)
136136

137137
int git_fspathncmp(const char *a, const char *b, size_t count)
138138
{
139-
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
139+
return repo_ignore_case(the_repository) ? strncasecmp(a, b, count) : strncmp(a, b, count);
140140
}
141141

142142
int paths_collide(const char *a, const char *b)
@@ -153,7 +153,7 @@ int paths_collide(const char *a, const char *b)
153153

154154
unsigned int fspathhash(const char *str)
155155
{
156-
return ignore_case ? strihash(str) : strhash(str);
156+
return repo_ignore_case(the_repository) ? strihash(str) : strhash(str);
157157
}
158158

159159
int git_fnmatch(const struct pathspec_item *item,
@@ -202,7 +202,7 @@ static int fnmatch_icase_mem(const char *pattern, int patternlen,
202202
use_str = str_buf.buf;
203203
}
204204

205-
if (ignore_case)
205+
if (repo_ignore_case(the_repository))
206206
flags |= WM_CASEFOLD;
207207
match_status = wildmatch(use_pat, use_str, flags);
208208

@@ -1851,7 +1851,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir,
18511851
struct index_state *istate,
18521852
const char *pathname, int len)
18531853
{
1854-
if (index_file_exists(istate, pathname, len, ignore_case))
1854+
if (index_file_exists(istate, pathname, len, repo_ignore_case(the_repository)))
18551855
return NULL;
18561856

18571857
ALLOC_GROW(dir->entries, dir->nr+1, dir->internal.alloc);
@@ -1888,7 +1888,7 @@ static enum exist_status directory_exists_in_index_icase(struct index_state *ist
18881888
if (index_dir_exists(istate, dirname, len))
18891889
return index_directory;
18901890

1891-
ce = index_file_exists(istate, dirname, len, ignore_case);
1891+
ce = index_file_exists(istate, dirname, len, repo_ignore_case(the_repository));
18921892
if (ce && S_ISGITLINK(ce->ce_mode))
18931893
return index_gitdir;
18941894

@@ -1907,7 +1907,7 @@ static enum exist_status directory_exists_in_index(struct index_state *istate,
19071907
{
19081908
int pos;
19091909

1910-
if (ignore_case)
1910+
if (repo_ignore_case(the_repository))
19111911
return directory_exists_in_index_icase(istate, dirname, len);
19121912

19131913
pos = index_name_pos(istate, dirname, len);
@@ -2447,7 +2447,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
24472447

24482448
/* Always exclude indexed files */
24492449
has_path_in_index = !!index_file_exists(istate, path->buf, path->len,
2450-
ignore_case);
2450+
repo_ignore_case(the_repository));
24512451
if (dtype != DT_DIR && has_path_in_index)
24522452
return path_none;
24532453

@@ -3201,7 +3201,7 @@ static int cmp_icase(char a, char b)
32013201
{
32023202
if (a == b)
32033203
return 0;
3204-
if (ignore_case)
3204+
if (repo_ignore_case(the_repository))
32053205
return toupper(a) - toupper(b);
32063206
return a - b;
32073207
}

environment.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ static int zlib_compression_seen;
4343

4444
int has_symlinks = 1;
4545
int minimum_abbrev = 4, default_abbrev = -1;
46-
int ignore_case;
4746
int assume_unchanged;
4847
char *git_commit_encoding;
4948
char *git_log_output_encoding;
@@ -148,6 +147,13 @@ int repo_trust_executable_bit(struct repository *repo)
148147
1;
149148
}
150149

150+
int repo_ignore_case(struct repository *repo)
151+
{
152+
return (repo && repo->initialized) ?
153+
repo_config_values(repo)->ignore_case :
154+
0;
155+
}
156+
151157
int have_git_dir(void)
152158
{
153159
return startup_info->have_repository
@@ -341,7 +347,7 @@ int git_default_core_config(const char *var, const char *value,
341347
}
342348

343349
if (!strcmp(var, "core.ignorecase")) {
344-
ignore_case = git_config_bool(var, value);
350+
cfg->ignore_case = git_config_bool(var, value);
345351
return 0;
346352
}
347353

@@ -733,6 +739,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
733739
cfg->protect_hfs = PROTECT_HFS_DEFAULT;
734740
cfg->protect_ntfs = PROTECT_NTFS_DEFAULT;
735741
cfg->trust_executable_bit = 1;
742+
cfg->ignore_case = 0;
736743
cfg->branch_track = BRANCH_TRACK_REMOTE;
737744
cfg->trust_ctime = 1;
738745
cfg->check_stat = 1;

environment.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct repo_config_values {
101101
int protect_hfs;
102102
int protect_ntfs;
103103
int trust_executable_bit;
104+
int ignore_case;
104105

105106
/* section "sparse" config values */
106107
int sparse_expect_files_outside_of_patterns;
@@ -151,6 +152,13 @@ int repo_protect_ntfs(struct repository *repo);
151152
*/
152153
int repo_trust_executable_bit(struct repository *repo);
153154

155+
/*
156+
* Getter for the `ignore_case` field of `struct repo_config_values`.
157+
* It checks `repo->initialized` to prevent calling repo_config_values()`
158+
* before the repository setup is fully complete or in non-git environments.
159+
*/
160+
int repo_ignore_case(struct repository *repo);
161+
154162
void repo_config_values_init(struct repo_config_values *cfg);
155163

156164
int is_bare_repository(struct repository *repo);
@@ -180,7 +188,6 @@ int have_git_dir(void);
180188
/* Environment bits from configuration mechanism */
181189
extern int has_symlinks;
182190
extern int minimum_abbrev, default_abbrev;
183-
extern int ignore_case;
184191
extern int assume_unchanged;
185192
extern char *apply_default_whitespace;
186193
extern char *apply_default_ignorewhitespace;

fsmonitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
453453
* case-insensitive file system, try again using the name-hash
454454
* and dir-name-hash.
455455
*/
456-
if (!nr_in_cone && ignore_case) {
456+
if (!nr_in_cone && repo_ignore_case(the_repository)) {
457457
nr_in_cone = handle_using_name_hash_icase(istate, name);
458458
if (!nr_in_cone)
459459
nr_in_cone = handle_using_dir_name_hash_icase(

name-hash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
126126
hashmap_add(&istate->name_hash, &ce->ent);
127127
}
128128

129-
if (ignore_case)
129+
if (repo_ignore_case(the_repository))
130130
add_dir_entry(istate, ce);
131131
}
132132

@@ -207,7 +207,7 @@ static int lookup_lazy_params(struct index_state *istate)
207207
* code to build the "istate->name_hash". We don't
208208
* need the complexity here.
209209
*/
210-
if (!ignore_case)
210+
if (!repo_ignore_case(the_repository))
211211
return 0;
212212

213213
nr_cpus = online_cpus();
@@ -651,7 +651,7 @@ void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
651651
ce->ce_flags &= ~CE_HASHED;
652652
hashmap_remove(&istate->name_hash, &ce->ent, ce);
653653

654-
if (ignore_case)
654+
if (repo_ignore_case(the_repository))
655655
remove_dir_entry(istate, ce);
656656
}
657657

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
771771
* case of the file being added to the repository matches (is folded into) the existing
772772
* entry's directory case.
773773
*/
774-
if (ignore_case) {
774+
if (repo_ignore_case(the_repository)) {
775775
adjust_dirname_case(istate, ce->name);
776776
}
777777
if (!(flags & ADD_CACHE_RENORMALIZE)) {
778778
alias = index_file_exists(istate, ce->name,
779-
ce_namelen(ce), ignore_case);
779+
ce_namelen(ce), repo_ignore_case(the_repository));
780780
if (alias &&
781781
!ce_stage(alias) &&
782782
!ie_match_stat(istate, alias, st, ce_option)) {
@@ -797,7 +797,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
797797
} else
798798
set_object_name_for_intent_to_add_entry(ce);
799799

800-
if (ignore_case && alias && different_name(ce, alias))
800+
if (repo_ignore_case(the_repository) && alias && different_name(ce, alias))
801801
ce = create_alias_ce(istate, ce, alias);
802802
ce->ce_flags |= CE_ADDED;
803803

0 commit comments

Comments
 (0)