git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Added support for core.ignorecase when excluding gitignore entries

From
Joshua Jensen <jjensen@workspacewhiz.com>
Date
Jul 16, 2009, 05:19 UTC
Message-ID
<4A5EB849.1000803@workspacewhiz.com>

This patch allows core.ignorecase=true to work properly with gitignore exclusions.

This is especially beneficial when using Windows and Perforce and the git-p4 bridge. Perforce preserves a given file's full path including case. When syncing a file down, 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/.

Trying to catch all case combinations for a set of gitignore entries is 
very difficult.  Having the exclusions honor the core.ignorecase=true 
makes the process less error prone.
---
 dir.c |   49 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/dir.c b/dir.c
index 0e6b752..c63e0a0 100644
--- a/dir.c
+++ b/dir.c
@@ -315,14 +315,25 @@ static int excluded_1(const char *pathname,
             if (x->flags & EXC_FLAG_NODIR) {
                 /* match basename */
                 if (x->flags & EXC_FLAG_NOWILDCARD) {
-                    if (!strcmp(exclude, basename))
-                        return to_exclude;
+                    if (ignore_case) {
+                        if (!strcasecmp(exclude, basename))
+                            return to_exclude;
+                    } else {
+                        if (!strcmp(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))
-                        return to_exclude;
+                    if (ignore_case) {
+                        if (x->patternlen - 1 <= pathlen &&
+                            !strcasecmp(exclude + 1, pathname + pathlen 
- x->patternlen + 1))
+                            return to_exclude;
+                    } else {
+                        if (x->patternlen - 1 <= pathlen &&
+                            !strcmp(exclude + 1, pathname + pathlen - 
x->patternlen + 1))
+                            return to_exclude;
+                    }
                 } else {
-                    if (fnmatch(exclude, basename, 0) == 0)
+                    if (fnmatch(exclude, basename, ignore_case ? 
FNM_CASEFOLD : 0) == 0)
                         return to_exclude;
                 }
             }
@@ -335,17 +346,29 @@ static int excluded_1(const char *pathname,
                 if (*exclude == '/')
                     exclude++;
 
-                if (pathlen < baselen ||
-                    (baselen && pathname[baselen-1] != '/') ||
-                    strncmp(pathname, x->base, baselen))
-                    continue;
+                if (ignore_case) {
+                    if (pathlen < baselen ||
+                        (baselen && pathname[baselen-1] != '/') ||
+                        strncasecmp(pathname, x->base, baselen))
+                        continue;
+                } else {
+                    if (pathlen < baselen ||
+                        (baselen && pathname[baselen-1] != '/') ||
+                        strncmp(pathname, x->base, baselen))
+                        continue;
+                }
 
                 if (x->flags & EXC_FLAG_NOWILDCARD) {
-                    if (!strcmp(exclude, pathname + baselen))
-                        return to_exclude;
+                    if (ignore_case) {
+                        if (!strcasecmp(exclude, pathname + baselen))
+                            return to_exclude;
+                    } else {
+                        if (!strcmp(exclude, pathname + baselen))
+                            return to_exclude;
+                    }
                 } else {
                     if (fnmatch(exclude, pathname+baselen,
-                            FNM_PATHNAME) == 0)
+                            FNM_PATHNAME | (ignore_case ? FNM_CASEFOLD 
: 0)) == 0)
                         return to_exclude;
                 }
             }
-- 
1.6.3.2.1299.gee46c.dirty
Next: Jeff King
Message 1 of 5 in “Added support for core.ignorecase when excluding gitignore entries”
  1. Added support for core.ignorecase when excluding gitignore entriesJoshua Jensen, Jul 16, 2009
  2. Jeff KingJul 16, 2009
  3. Joshua JensenJul 16, 2009
  4. Jeff KingJul 20, 2009
  5. Joshua JensenJul 21, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.