Skip to content

Commit 21444f1

Browse files
jjensengitster
authored andcommitted
Add case insensitivity support when using git ls-files
When mydir/filea.txt is added, mydir/ is renamed to MyDir/, and MyDir/fileb.txt is added, running git ls-files mydir only shows mydir/filea.txt. Running git ls-files MyDir shows MyDir/fileb.txt. Running git ls-files mYdIR shows nothing. With this patch running git ls-files for mydir, MyDir, and mYdIR shows mydir/filea.txt and MyDir/fileb.txt. Wildcards are not handled case insensitively in this patch. Example: MyDir/aBc/file.txt is added. git ls-files MyDir/a* works fine, but git ls-files mydir/a* does not. 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 5102c61 commit 21444f1

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

dir.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,30 @@ static int match_one(const char *match, const char *name, int namelen)
107107
if (!*match)
108108
return MATCHED_RECURSIVELY;
109109

110-
for (;;) {
111-
unsigned char c1 = *match;
112-
unsigned char c2 = *name;
113-
if (c1 == '\0' || is_glob_special(c1))
114-
break;
115-
if (c1 != c2)
116-
return 0;
117-
match++;
118-
name++;
119-
namelen--;
110+
if (ignore_case) {
111+
for (;;) {
112+
unsigned char c1 = tolower(*match);
113+
unsigned char c2 = tolower(*name);
114+
if (c1 == '\0' || is_glob_special(c1))
115+
break;
116+
if (c1 != c2)
117+
return 0;
118+
match++;
119+
name++;
120+
namelen--;
121+
}
122+
} else {
123+
for (;;) {
124+
unsigned char c1 = *match;
125+
unsigned char c2 = *name;
126+
if (c1 == '\0' || is_glob_special(c1))
127+
break;
128+
if (c1 != c2)
129+
return 0;
130+
match++;
131+
name++;
132+
namelen--;
133+
}
120134
}
121135

122136

@@ -125,8 +139,8 @@ static int match_one(const char *match, const char *name, int namelen)
125139
* we need to match by fnmatch
126140
*/
127141
matchlen = strlen(match);
128-
if (strncmp(match, name, matchlen))
129-
return !fnmatch(match, name, 0) ? MATCHED_FNMATCH : 0;
142+
if (strncmp_icase(match, name, matchlen))
143+
return !fnmatch_icase(match, name, 0) ? MATCHED_FNMATCH : 0;
130144

131145
if (namelen == matchlen)
132146
return MATCHED_EXACTLY;

0 commit comments

Comments
 (0)