Skip to content

Commit 8cf2a84

Browse files
jjensengitster
authored andcommitted
Add string comparison functions that respect the ignore_case variable.
Multiple locations within this patch series alter a case sensitive string comparison call such as strcmp() to be a call to a string comparison call that selects case comparison based on the global ignore_case variable. Behaviorally, when core.ignorecase=false, the *_icase() versions are functionally equivalent to their C runtime counterparts. When core.ignorecase=true, the *_icase() versions perform a case insensitive comparison. Like Linus' earlier ignorecase patch, these may ignore filename conventions on certain file systems. By isolating filename comparisons to certain functions, support for those filename conventions may be more easily met. Signed-off-by: Joshua Jensen <jjensen@workspacewhiz.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4de066b commit 8cf2a84

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

dir.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, in
1818
int check_only, const struct path_simplify *simplify);
1919
static int get_dtype(struct dirent *de, const char *path, int len);
2020

21+
/* helper string functions with support for the ignore_case flag */
22+
int strcmp_icase(const char *a, const char *b)
23+
{
24+
return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
25+
}
26+
27+
int strncmp_icase(const char *a, const char *b, size_t count)
28+
{
29+
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
30+
}
31+
32+
int fnmatch_icase(const char *pattern, const char *string, int flags)
33+
{
34+
return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
35+
}
36+
2137
static int common_prefix(const char **pathspec)
2238
{
2339
const char *path, *slash, *next;

dir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ extern int remove_dir_recursively(struct strbuf *path, int flag);
101101
/* tries to remove the path with empty directories along it, ignores ENOENT */
102102
extern int remove_path(const char *path);
103103

104+
extern int strcmp_icase(const char *a, const char *b);
105+
extern int strncmp_icase(const char *a, const char *b, size_t count);
106+
extern int fnmatch_icase(const char *pattern, const char *string, int flags);
107+
104108
#endif

0 commit comments

Comments
 (0)