git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Added support for core.ignorecase when excluding gitignore entries
@ 2009-07-16  5:19 Joshua Jensen
  2009-07-16  9:42 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Joshua Jensen @ 2009-07-16  5:19 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-21 15:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16  5:19 [PATCH] Added support for core.ignorecase when excluding gitignore entries Joshua Jensen
2009-07-16  9:42 ` Jeff King
2009-07-16 13:15   ` Joshua Jensen
2009-07-20 15:37     ` Jeff King
2009-07-21 15:55       ` Joshua Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).