Skip to content

Commit

Permalink
Case insensitivity support for .gitignore via core.ignorecase
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Joshua Jensen authored and Junio C Hamano committed Oct 6, 2010
1 parent 8cf2a84 commit 10d4b02
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ int excluded_from_list(const char *pathname,
if (x->flags & EXC_FLAG_NODIR) {
/* match basename */
if (x->flags & EXC_FLAG_NOWILDCARD) {
if (!strcmp(exclude, basename))
if (!strcmp_icase(exclude, basename))
return to_exclude;
} else if (x->flags & EXC_FLAG_ENDSWITH) {
if (x->patternlen - 1 <= pathlen &&
!strcmp(exclude + 1, pathname + pathlen - x->patternlen + 1))
!strcmp_icase(exclude + 1, pathname + pathlen - x->patternlen + 1))
return to_exclude;
} else {
if (fnmatch(exclude, basename, 0) == 0)
if (fnmatch_icase(exclude, basename, 0) == 0)
return to_exclude;
}
}
Expand All @@ -412,14 +412,14 @@ int excluded_from_list(const char *pathname,

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

if (x->flags & EXC_FLAG_NOWILDCARD) {
if (!strcmp(exclude, pathname + baselen))
if (!strcmp_icase(exclude, pathname + baselen))
return to_exclude;
} else {
if (fnmatch(exclude, pathname+baselen,
if (fnmatch_icase(exclude, pathname+baselen,
FNM_PATHNAME) == 0)
return to_exclude;
}
Expand Down

0 comments on commit 10d4b02

Please sign in to comment.