git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Joshua Jensen <jjensen@workspacewhiz.com>,
	Johannes Sixt <j6t@kdbg.org>, Brandon Casey <drafnel@gmail.com>
Subject: [PATCH/RFC v3 7/8] Support case folding for git add when core.ignorecase=true
Date: Sun,  3 Oct 2010 09:56:45 +0000	[thread overview]
Message-ID: <1286099806-25774-8-git-send-email-avarab@gmail.com> (raw)
In-Reply-To: <4CA847D5.4000903@workspacewhiz.com>

From: Joshua Jensen <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>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 read-cache.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 1f42473..379862c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -608,6 +608,29 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
 		ce->ce_mode = ce_mode_from_stat(ent, st_mode);
 	}
 
+	/* When core.ignorecase=true, determine if a directory of the same name but differing
+	 * case already exists within the Git repository.  If it does, ensure the directory
+	 * case of the file being added to the repository matches (is folded into) the existing
+	 * entry's directory case.
+	 */
+	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);
+					startPtr = ptr;
+				}
+			}
+		}
+	}
+
 	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.3.159.g610493

  parent reply	other threads:[~2010-10-03  9:58 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-03  4:32 [PATCH v2 0/6] Extensions of core.ignorecase=true support Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 1/6] Add string comparison functions that respect the ignore_case variable Joshua Jensen
2010-10-03  8:30   ` Ævar Arnfjörð Bjarmason
2010-10-03  9:07     ` Joshua Jensen
2010-10-03  9:56       ` [PATCH/RFC v3 0/8] ab/icase-directory: jj/icase-directory with Makefile + configure checks Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 1/8] Makefile & configure: add a NO_FNMATCH flag Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 2/8] Makefile & configure: add a NO_FNMATCH_CASEFOLD flag Ævar Arnfjörð Bjarmason
2010-10-03 17:58         ` Johannes Sixt
2010-10-04  2:48           ` [PATCH/RFC v4 " Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 3/8] Add string comparison functions that respect the ignore_case variable Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 4/8] Case insensitivity support for .gitignore via core.ignorecase Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 5/8] Add case insensitivity support for directories when using git status Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` [PATCH/RFC v3 6/8] Add case insensitivity support when using git ls-files Ævar Arnfjörð Bjarmason
2010-10-03 11:54         ` Thomas Adam
2010-10-03 18:19           ` Johannes Sixt
2010-10-03 21:59             ` Thomas Adam
2010-10-04  7:49             ` Jonathan Nieder
2010-10-04  8:02               ` Ævar Arnfjörð Bjarmason
2010-10-04 14:03               ` Erik Faye-Lund
2010-10-04 14:58                 ` Joshua Jensen
2010-10-04 17:03                   ` Jonathan Nieder
2010-10-04 16:02         ` Robin Rosenberg
2010-10-04 16:41           ` Ævar Arnfjörð Bjarmason
2010-10-04 16:48           ` Erik Faye-Lund
2010-10-04 16:49           ` Joshua Jensen
2010-10-04 17:08             ` Jonathan Nieder
2010-10-04 17:53             ` Ævar Arnfjörð Bjarmason
2010-10-04 19:02           ` Johannes Sixt
2010-10-04 19:17             ` Ævar Arnfjörð Bjarmason
2010-10-03  9:56       ` Ævar Arnfjörð Bjarmason [this message]
2010-10-03  9:56       ` [PATCH/RFC v3 8/8] Support case folding in git fast-import when core.ignorecase=true Ævar Arnfjörð Bjarmason
2010-10-07  4:13       ` [PATCH v2 1/6] Add string comparison functions that respect the ignore_case variable Junio C Hamano
2010-10-07  5:48         ` Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 2/6] Case insensitivity support for .gitignore via core.ignorecase Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 3/6] Add case insensitivity support for directories when using git status Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 4/6] Add case insensitivity support when using git ls-files Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 5/6] Support case folding for git add when core.ignorecase=true Joshua Jensen
2010-10-03  4:32 ` [PATCH v2 6/6] Support case folding in git fast-import " Joshua Jensen
2010-10-03 13:00   ` Sverre Rabbelier
2010-10-03  8:17 ` [PATCH v2 0/6] Extensions of core.ignorecase=true support Johannes Sixt
2010-10-03 23:34   ` Junio C Hamano
2010-10-03 11:48 ` Robert Buck
2010-10-03 18:12   ` Johannes Sixt
2010-10-06 22:04     ` Robert Buck
2010-10-06 22:46       ` Joshua Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286099806-25774-8-git-send-email-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=drafnel@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jjensen@workspacewhiz.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).