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

[PATCH 6/7] Support case folding for git add when core.ignorecase=true

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

When MyDir/ABC/filea.txt is added to Git, the disk directory MyDir/ABC/ is renamed to mydir/aBc/, and then mydir/aBc/fileb.txt is added, the index will contain MyDir/ABC/filea.txt and mydir/aBc/fileb.txt. Although the earlier portions of this patch series account for those differences in case, this patch makes the pathing consistent by folding the case of newly added files against the first file added with that path.

In read-cache.c's add_to_index(), the index_name_exists() support used for git status's case insensitive directory lookups is used to find the proper directory case according to what the user already checked in. That is, MyDir/ABC/'s case is used to alter the stored path for fileb.txt to MyDir/ABC/fileb.txt (instead of mydir/aBc/fileb.txt).

This is especially important when cloning a repository to a case sensitive file system. MyDir/ABC/ and mydir/aBc/ exist in the same directory on a Windows machine, but on Linux, the files exist in two separate directories. The update to add_to_index(), in effect, treats a Windows file system as case sensitive by making path case consistent.

Signed-off-by: Joshua Jensen <jjensen@workspacewhiz.com>
---
 read-cache.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index f1f789b..b3954d5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -608,6 +608,22 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
 		ce->ce_mode = ce_mode_from_stat(ent, st_mode);
 	}
 
+	if (ignore_case) {
+		const char *startPtr = ce->name;
+		const char *ptr = startPtr;
+		while (*ptr) {
+			while (*ptr && *ptr != '/')
+				++ptr;
+			if (*ptr == '/') {
+				struct cache_entry *foundce;
+				++ptr;
+				foundce = index_name_exists(&the_index, ce->name, ptr - ce->name, ignore_case);
+				if (foundce)
+					memcpy((void*)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
+			}
+		}
+	}
+
 	alias = index_name_exists(istate, ce->name, ce_namelen(ce), ignore_case);
 	if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
 		/* Nothing changed, really */
-- 
1.7.1.1930.gca7dd4
Previous: Joshua JensenNext: Joshua Jensen
Message 7 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.