Skip to content

Commit 10d4b02

Browse files
jjensengitster
authored andcommitted
Case insensitivity support for .gitignore via core.ignorecase
This is especially beneficial when using Windows and Perforce and the git-p4 bridge. Internally, Perforce preserves a given file's full path including its case at the time it was added to the Perforce repository. When syncing a file down via Perforce, missing directories are created, if necessary, using the case as stored with the filename. Unfortunately, two files in the same directory can have differing cases for their respective paths, such as /diRa/file1.c and /DirA/file2.c. Depending on sync order, DirA/ may get created instead of diRa/. It is possible to handle directory names in a case insensitive manner without this patch, but it is highly inconvenient, requiring each character to be specified like so: [Bb][Uu][Ii][Ll][Dd]. With this patch, the gitignore exclusions honor the core.ignorecase=true configuration setting and make the process less error prone. The above is specified like so: Build 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 8cf2a84 commit 10d4b02

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dir.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,14 @@ int excluded_from_list(const char *pathname,
390390
if (x->flags & EXC_FLAG_NODIR) {
391391
/* match basename */
392392
if (x->flags & EXC_FLAG_NOWILDCARD) {
393-
if (!strcmp(exclude, basename))
393+
if (!strcmp_icase(exclude, basename))
394394
return to_exclude;
395395
} else if (x->flags & EXC_FLAG_ENDSWITH) {
396396
if (x->patternlen - 1 <= pathlen &&
397-
!strcmp(exclude + 1, pathname + pathlen - x->patternlen + 1))
397+
!strcmp_icase(exclude + 1, pathname + pathlen - x->patternlen + 1))
398398
return to_exclude;
399399
} else {
400-
if (fnmatch(exclude, basename, 0) == 0)
400+
if (fnmatch_icase(exclude, basename, 0) == 0)
401401
return to_exclude;
402402
}
403403
}
@@ -412,14 +412,14 @@ int excluded_from_list(const char *pathname,
412412

413413
if (pathlen < baselen ||
414414
(baselen && pathname[baselen-1] != '/') ||
415-
strncmp(pathname, x->base, baselen))
415+
strncmp_icase(pathname, x->base, baselen))
416416
continue;
417417

418418
if (x->flags & EXC_FLAG_NOWILDCARD) {
419-
if (!strcmp(exclude, pathname + baselen))
419+
if (!strcmp_icase(exclude, pathname + baselen))
420420
return to_exclude;
421421
} else {
422-
if (fnmatch(exclude, pathname+baselen,
422+
if (fnmatch_icase(exclude, pathname+baselen,
423423
FNM_PATHNAME) == 0)
424424
return to_exclude;
425425
}

0 commit comments

Comments
 (0)