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

[PATCH 1/7] Add string comparison functions that respect the ignore_case variable.

From
Joshua Jensen <jjensen@workspacewhiz.com>
Date
May 21, 2010, 04:50 UTC
Message-ID
<1274417435-2344-2-git-send-email-jjensen@workspacewhiz.com>
In-Reply-To
<1274417435-2344-1-git-send-email-jjensen@workspacewhiz.com>

Multiple locations within this patch series alter a case sensitive string comparison call such as strcmp() to be a call to a string comparison call that selects case comparison based on the global ignore_case variable. Behaviorally, when core.ignorecase=false, the *_icase() versions are functionally equivalent to their C runtime counterparts. When core.ignorecase=true, the *_icase() versions perform a case insensitive comparison.

Like Linus' earlier ignorecase patch, these may ignore filename conventions on certain file systems. By isolating filename comparisons to certain functions, support for those filename conventions may be more easily met.

Signed-off-by: Joshua Jensen <jjensen@workspacewhiz.com>
---
 dir.c |   35 +++++++++++++++++++++++++++++++++++
 dir.h |    5 +++++
 2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/dir.c b/dir.c
index cb83332..21d2104 100644
--- a/dir.c
+++ b/dir.c
@@ -18,6 +18,41 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, in
 	int check_only, const struct path_simplify *simplify);
 static int get_dtype(struct dirent *de, const char *path, int len);
 
+/* helper string functions with support for the ignore_case flag */
+int strcmp_icase(const char *a, const char *b)
+{
+	return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
+}
+
+int strncmp_icase(const char *a, const char *b, size_t count)
+{
+	return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
+}
+
+int fnmatch_icase(const char *pattern, const char *string, int flags)
+{
+	return fnmatch(pattern, string, flags | (ignore_case ? FNM_CASEFOLD : 0));
+}
+
+int memcmp_icase(const char *a, const char *b, size_t count)
+{
+	if (ignore_case) {
+		int lowera = 0;
+		int lowerb = 0;
+		while (--count) {
+			lowera = tolower(*a++);
+			lowerb = tolower(*b++);
+			if (lowera != lowerb)
+				break;
+		}
+		return lowera - lowerb;
+
+		return 0;
+	} else {
+		return memcmp(a, b, count);
+	}
+}
+
 static int common_prefix(const char **pathspec)
 {
 	const char *path, *slash, *next;
diff --git a/dir.h b/dir.h
index 3bead5f..aced818 100644
--- a/dir.h
+++ b/dir.h
@@ -100,4 +100,9 @@ extern int remove_dir_recursively(struct strbuf *path, int flag);
 /* tries to remove the path with empty directories along it, ignores ENOENT */
 extern int remove_path(const char *path);
 
+extern int strcmp_icase(const char *a, const char *b);
+extern int strncmp_icase(const char *a, const char *b, size_t count);
+extern int fnmatch_icase(const char *pattern, const char *string, int flags);
+extern int memcmp_icase(const char *a, const char *b, size_t count);
+
 #endif
-- 
1.7.1.1930.gca7dd4
Previous: Joshua JensenNext: Joshua Jensen
Message 2 of 9 in “Various updates to make core.ignorecase=true work better”
  1. 0/7 Various updates to make core.ignorecase=true work betterJoshua Jensen, May 21, 2010
  2. 1/7 Add string comparison functions that respect the ignore_case variable.Joshua Jensen, May 21, 2010
  3. 2/7 Case insensitivity support for .gitignore via core.ignorecaseJoshua Jensen, May 21, 2010
  4. 3/7 Add case insensitivity support for directories when using git statusJoshua Jensen, May 21, 2010
  5. 4/7 Add case insensitivity support when using git ls-filesJoshua Jensen, May 21, 2010
  6. 5/7 Add support for case insensitive directory and file lookups to git logJoshua Jensen, May 21, 2010
  7. 6/7 Support case folding for git add when core.ignorecase=trueJoshua Jensen, May 21, 2010
  8. 7/7 Support case folding in git fast-import when core.ignorecase=trueJoshua Jensen, May 21, 2010
  9. Joshua JensenMay 26, 2010

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.