diff options
author | Joshua Jensen <jjensen@workspacewhiz.com> | 2010-10-03 09:56:43 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-10-06 11:19:58 -0700 |
commit | 5102c6173c5a1c683dfdd8ccd07528adddd51745 (patch) | |
tree | c36145dd9e065bb9d2011566088044f1d50ff2ae /name-hash.c | |
parent | 10d4b02b9962170e15d1d65b03581ef8bef66e2e (diff) | |
download | git-5102c6173c5a1c683dfdd8ccd07528adddd51745.tar.gz |
Add case insensitivity support for directories when using git status
When using a case preserving but case insensitive file system, directory
case can differ but still refer to the same physical directory. git
status reports the directory with the alternate case as an Untracked
file. (That is, when mydir/filea.txt is added to the repository and
then the directory on disk is renamed from mydir/ to MyDir/, git status
shows MyDir/ as being untracked.)
Support has been added in name-hash.c for hashing directories with a
terminating slash into the name hash. When index_name_exists() is called
with a directory (a name with a terminating slash), the name is not
found via the normal cache_name_compare() call, but it is found in the
slow_same_name() function.
Additionally, in dir.c, directory_exists_in_index_icase() allows newly
added directories deeper in the directory chain to be identified.
Ultimately, it would be better if the file list was read in case
insensitive alphabetical order from disk, but this change seems to
suffice for now.
The end result is the directory is looked up in a case insensitive
manner and does not show in the Untracked files list.
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>
Diffstat (limited to 'name-hash.c')
-rw-r--r-- | name-hash.c | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/name-hash.c b/name-hash.c index 0031d78e8c..c6b6a3fe4c 100644 --- a/name-hash.c +++ b/name-hash.c @@ -32,6 +32,42 @@ static unsigned int hash_name(const char *name, int namelen) return hash; } +static void hash_index_entry_directories(struct index_state *istate, struct cache_entry *ce) +{ + /* + * Throw each directory component in the hash for quick lookup + * during a git status. Directory components are stored with their + * closing slash. Despite submodules being a directory, they never + * reach this point, because they are stored without a closing slash + * in the cache. + * + * Note that the cache_entry stored with the directory does not + * represent the directory itself. It is a pointer to an existing + * filename, and its only purpose is to represent existence of the + * directory in the cache. It is very possible multiple directory + * hash entries may point to the same cache_entry. + */ + unsigned int hash; + void **pos; + + const char *ptr = ce->name; + while (*ptr) { + while (*ptr && *ptr != '/') + ++ptr; + if (*ptr == '/') { + ++ptr; + hash = hash_name(ce->name, ptr - ce->name); + if (!lookup_hash(hash, &istate->name_hash)) { + pos = insert_hash(hash, ce, &istate->name_hash); + if (pos) { + ce->next = *pos; + *pos = ce; + } + } + } + } +} + static void hash_index_entry(struct index_state *istate, struct cache_entry *ce) { void **pos; @@ -47,6 +83,9 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce) ce->next = *pos; *pos = ce; } + + if (ignore_case) + hash_index_entry_directories(istate, ce); } static void lazy_init_name_hash(struct index_state *istate) @@ -97,7 +136,21 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen if (len == namelen && !cache_name_compare(name, namelen, ce->name, len)) return 1; - return icase && slow_same_name(name, namelen, ce->name, len); + if (!icase) + return 0; + + /* + * If the entry we're comparing is a filename (no trailing slash), then compare + * the lengths exactly. + */ + if (name[namelen - 1] != '/') + return slow_same_name(name, namelen, ce->name, len); + + /* + * For a directory, we point to an arbitrary cache_entry filename. Just + * make sure the directory portion matches. + */ + return slow_same_name(name, namelen, ce->name, namelen < len ? namelen : len); } struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase) @@ -115,5 +168,22 @@ struct cache_entry *index_name_exists(struct index_state *istate, const char *na } ce = ce->next; } + + /* + * Might be a submodule. Despite submodules being directories, + * they are stored in the name hash without a closing slash. + * When ignore_case is 1, directories are stored in the name hash + * with their closing slash. + * + * The side effect of this storage technique is we have need to + * remove the slash from name and perform the lookup again without + * the slash. If a match is made, S_ISGITLINK(ce->mode) will be + * true. + */ + if (icase && name[namelen - 1] == '/') { + ce = index_name_exists(istate, name, namelen - 1, icase); + if (ce && S_ISGITLINK(ce->ce_mode)) + return ce; + } return NULL; } |