@matheusbsbs / matheus-bagliano / commits / 21444f1805
Fork 0

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>

Joshua Jensen committed Oct 3, 2010 at 09:56 UTC 21444f1805d2ea3c7b297101e9470048cdcf58d2
1 file changed +26 -12
dir.c
+26 -12
@@ -107,16 +107,30 @@ static int match_one(const char *match, const char *name, int namelen)
107 if (!*match)
108 return MATCHED_RECURSIVELY;
109
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 + }
134 }
135
136
@@ -125,8 +139,8 @@ static int match_one(const char *match, const char *name, int namelen)
139 * we need to match by fnmatch
140 */
141 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;
144
145 if (namelen == matchlen)
146 return MATCHED_EXACTLY;