check-attr: the name of the character is NUL, not NULL
[gitweb.git] / name-hash.c
index c6b6a3fe4cd94e48893b172c17b6e7df3bfa36f8..942c45962252eba4c6f88b4f4f7593c9247749ae 100644 (file)
@@ -24,11 +24,11 @@ static unsigned int hash_name(const char *name, int namelen)
 {
        unsigned int hash = 0x123;
 
-       do {
+       while (namelen--) {
                unsigned char c = *name++;
                c = icase_hash(c);
                hash = hash*101 + c;
-       } while (--namelen);
+       }
        return hash;
 }
 
@@ -57,12 +57,10 @@ static void hash_index_entry_directories(struct index_state *istate, struct cach
                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;
-                               }
+                       pos = insert_hash(hash, ce, &istate->name_hash);
+                       if (pos) {
+                               ce->dir_next = *pos;
+                               *pos = ce;
                        }
                }
        }
@@ -76,7 +74,7 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
        if (ce->ce_flags & CE_HASHED)
                return;
        ce->ce_flags |= CE_HASHED;
-       ce->next = NULL;
+       ce->next = ce->dir_next = NULL;
        hash = hash_name(ce->name, ce_namelen(ce));
        pos = insert_hash(hash, ce, &istate->name_hash);
        if (pos) {
@@ -166,7 +164,10 @@ struct cache_entry *index_name_exists(struct index_state *istate, const char *na
                        if (same_name(ce, name, namelen, icase))
                                return ce;
                }
-               ce = ce->next;
+               if (icase && name[namelen - 1] == '/')
+                       ce = ce->dir_next;
+               else
+                       ce = ce->next;
        }
 
        /*