Skip to content

Commit e6a79c9

Browse files
malon7782gitster
authored andcommitted
config: use repo_ignore_case() to access core.ignorecase
Replace the accesses to the global 'ignore_case' variable with calls to 'repo_ignore_case(the_repository)'. This step eliminates the 'ignore_case' global state. Note on compat/win32/path-utils.c: To eliminate the global state, several helper functions (e.g. 'win32_fspathncmp()') now read from 'repo_ignore_case(the_repository)'. While this introduces dependency on 'repository.h' into the 'compat/', it avoids massive refactoring of the signatures across the codebase. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5abac96 commit e6a79c9

14 files changed

Lines changed: 27 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
@@ -1819,7 +1819,7 @@ static void ref_transaction_rejection_handler(const char *refname,
18191819
{
18201820
struct ref_rejection_data *data = cb_data;
18211821

1822-
if (err == REF_TRANSACTION_ERROR_CASE_CONFLICT && ignore_case &&
1822+
if (err == REF_TRANSACTION_ERROR_CASE_CONFLICT && repo_ignore_case(the_repository) &&
18231823
!data->case_sensitive_msg_shown) {
18241824
error(_("You're on a case-insensitive filesystem, and the remote you are\n"
18251825
"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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ int trust_ctime = 1;
4646
int check_stat = 1;
4747
int has_symlinks = 1;
4848
int minimum_abbrev = 4, default_abbrev = -1;
49-
int ignore_case;
5049
int assume_unchanged;
5150
int is_bare_repository_cfg = -1; /* unspecified */
5251
int warn_on_object_refname_ambiguity = 1;
@@ -342,7 +341,7 @@ int git_default_core_config(const char *var, const char *value,
342341
}
343342

344343
if (!strcmp(var, "core.ignorecase")) {
345-
ignore_case = git_config_bool(var, value);
344+
cfg->ignore_case = git_config_bool(var, value);
346345
return 0;
347346
}
348347

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ extern int trust_ctime;
171171
extern int check_stat;
172172
extern int has_symlinks;
173173
extern int minimum_abbrev, default_abbrev;
174-
extern int ignore_case;
175174
extern int assume_unchanged;
176175
extern int warn_on_object_refname_ambiguity;
177176
extern char *apply_default_whitespace;

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
@@ -760,12 +760,12 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
760760
* case of the file being added to the repository matches (is folded into) the existing
761761
* entry's directory case.
762762
*/
763-
if (ignore_case) {
763+
if (repo_ignore_case(the_repository)) {
764764
adjust_dirname_case(istate, ce->name);
765765
}
766766
if (!(flags & ADD_CACHE_RENORMALIZE)) {
767767
alias = index_file_exists(istate, ce->name,
768-
ce_namelen(ce), ignore_case);
768+
ce_namelen(ce), repo_ignore_case(the_repository));
769769
if (alias &&
770770
!ce_stage(alias) &&
771771
!ie_match_stat(istate, alias, st, ce_option)) {
@@ -786,7 +786,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
786786
} else
787787
set_object_name_for_intent_to_add_entry(ce);
788788

789-
if (ignore_case && alias && different_name(ce, alias))
789+
if (repo_ignore_case(the_repository) && alias && different_name(ce, alias))
790790
ce = create_alias_ce(istate, ce, alias);
791791
ce->ce_flags |= CE_ADDED;
792792

0 commit comments

Comments
 (0)