summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: df292c7)
raw | patch | inline | side by side (parent: df292c7)
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | |
Fri, 21 Mar 2008 22:55:19 +0000 (15:55 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 9 Apr 2008 08:22:25 +0000 (01:22 -0700) |
Right now nobody uses it, but "index_name_exists()" gets a flag so
you can enable it on a case-by-case basis.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
you can enable it on a case-by-case basis.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
dir.c | patch | blob | history | |
name-hash.c | patch | blob | history | |
unpack-trees.c | patch | blob | history |
index 76d95d2c813c4072ff1a8a52976a0893fc22365b..a9ddaa12400bffce84bfd56674dee97b9fe810fc 100644 (file)
--- a/cache.h
+++ b/cache.h
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL)
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
-#define cache_name_exists(name, namelen) index_name_exists(&the_index, (name), (namelen))
+#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
#endif
enum object_type {
extern int discard_index(struct index_state *);
extern int unmerged_index(const struct index_state *);
extern int verify_path(const char *path);
-extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen);
+extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int igncase);
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
#define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
index edc458e020772a7ab704e9cf69786d3aa641bcd4..7362e8328290eb22e8bed0e6c1782863bc4c1d0d 100644 (file)
--- a/dir.c
+++ b/dir.c
struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
{
- if (cache_name_exists(pathname, len))
+ if (cache_name_exists(pathname, len, 0))
return NULL;
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
diff --git a/name-hash.c b/name-hash.c
index 2678148937cc3614fbb003ae3826830ed2097b52..0031d78e8c98a32d61cd0dc0f939a033e24ed890 100644 (file)
--- a/name-hash.c
+++ b/name-hash.c
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+/*
+ * This removes bit 5 if bit 6 is set.
+ *
+ * That will make US-ASCII characters hash to their upper-case
+ * equivalent. We could easily do this one whole word at a time,
+ * but that's for future worries.
+ */
+static inline unsigned char icase_hash(unsigned char c)
+{
+ return c & ~((c & 0x40) >> 1);
+}
+
static unsigned int hash_name(const char *name, int namelen)
{
unsigned int hash = 0x123;
do {
unsigned char c = *name++;
+ c = icase_hash(c);
hash = hash*101 + c;
} while (--namelen);
return hash;
hash_index_entry(istate, ce);
}
-struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen)
+static int slow_same_name(const char *name1, int len1, const char *name2, int len2)
+{
+ if (len1 != len2)
+ return 0;
+
+ while (len1) {
+ unsigned char c1 = *name1++;
+ unsigned char c2 = *name2++;
+ len1--;
+ if (c1 != c2) {
+ c1 = toupper(c1);
+ c2 = toupper(c2);
+ if (c1 != c2)
+ return 0;
+ }
+ }
+ return 1;
+}
+
+static int same_name(const struct cache_entry *ce, const char *name, int namelen, int icase)
+{
+ int len = ce_namelen(ce);
+
+ /*
+ * Always do exact compare, even if we want a case-ignoring comparison;
+ * we do the quick exact one first, because it will be the common case.
+ */
+ if (len == namelen && !cache_name_compare(name, namelen, ce->name, len))
+ return 1;
+
+ return icase && slow_same_name(name, namelen, ce->name, len);
+}
+
+struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase)
{
unsigned int hash = hash_name(name, namelen);
struct cache_entry *ce;
while (ce) {
if (!(ce->ce_flags & CE_UNHASHED)) {
- if (!cache_name_compare(name, namelen, ce->name, ce->ce_flags))
+ if (same_name(ce, name, namelen, icase))
return ce;
}
ce = ce->next;
diff --git a/unpack-trees.c b/unpack-trees.c
index ca4c845beb3d9cd61c60ce9592e264bc9d53f592..bf7d8f6c5c8962f1f0e872a4f9b79f28dd0cc876 100644 (file)
--- a/unpack-trees.c
+++ b/unpack-trees.c
* delete this path, which is in a subdirectory that
* is being replaced with a blob.
*/
- result = index_name_exists(&o->result, ce->name, ce_namelen(ce));
+ result = index_name_exists(&o->result, ce->name, ce_namelen(ce), 0);
if (result) {
if (result->ce_flags & CE_REMOVE)
return 0;