From e05881a4577cedca4d7456b3cb1f8bbd6f480df2 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 14 Nov 2013 20:20:58 +0100 Subject: name-hash.c: use new hash map implementation for directories Signed-off-by: Karsten Blees Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 5e3fc72fd4..f9b13ecb3f 100644 --- a/cache.h +++ b/cache.h @@ -4,6 +4,7 @@ #include "git-compat-util.h" #include "strbuf.h" #include "hash.h" +#include "hashmap.h" #include "advice.h" #include "gettext.h" #include "convert.h" @@ -278,7 +279,7 @@ struct index_state { unsigned name_hash_initialized : 1, initialized : 1; struct hash_table name_hash; - struct hash_table dir_hash; + struct hashmap dir_hash; }; extern struct index_state the_index; -- cgit v1.3 From 8b013788a14b96b8d20b1f6bc76a42f9733aefad Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 14 Nov 2013 20:21:58 +0100 Subject: name-hash.c: use new hash map implementation for cache entries Note: the "ce->next = NULL;" in unpack-trees.c::do_add_entry can safely be removed, as ce->next (now ce->ent.next) is always properly initialized in name-hash.c::hash_index_entry. Signed-off-by: Karsten Blees Signed-off-by: Junio C Hamano --- cache.h | 8 +++++--- name-hash.c | 24 ++++++++---------------- unpack-trees.c | 1 - 3 files changed, 13 insertions(+), 20 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f9b13ecb3f..85210b1bd2 100644 --- a/cache.h +++ b/cache.h @@ -131,12 +131,12 @@ struct stat_data { }; struct cache_entry { + struct hashmap_entry ent; struct stat_data ce_stat_data; unsigned int ce_mode; unsigned int ce_flags; unsigned int ce_namelen; unsigned char sha1[20]; - struct cache_entry *next; char name[FLEX_ARRAY]; /* more */ }; @@ -203,7 +203,9 @@ static inline void copy_cache_entry(struct cache_entry *dst, unsigned int state = dst->ce_flags & CE_STATE_MASK; /* Don't copy hash chain and name */ - memcpy(dst, src, offsetof(struct cache_entry, next)); + memcpy(&dst->ce_stat_data, &src->ce_stat_data, + offsetof(struct cache_entry, name) - + offsetof(struct cache_entry, ce_stat_data)); /* Restore the hash state */ dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state; @@ -278,7 +280,7 @@ struct index_state { struct cache_time timestamp; unsigned name_hash_initialized : 1, initialized : 1; - struct hash_table name_hash; + struct hashmap name_hash; struct hashmap dir_hash; }; diff --git a/name-hash.c b/name-hash.c index effe96db0b..488eccf2f9 100644 --- a/name-hash.c +++ b/name-hash.c @@ -100,19 +100,11 @@ static void remove_dir_entry(struct index_state *istate, struct cache_entry *ce) static void hash_index_entry(struct index_state *istate, struct cache_entry *ce) { - void **pos; - unsigned int hash; - if (ce->ce_flags & CE_HASHED) return; ce->ce_flags |= CE_HASHED; - ce->next = NULL; - hash = memihash(ce->name, ce_namelen(ce)); - pos = insert_hash(hash, ce, &istate->name_hash); - if (pos) { - ce->next = *pos; - *pos = ce; - } + hashmap_entry_init(ce, memihash(ce->name, ce_namelen(ce))); + hashmap_add(&istate->name_hash, ce); if (ignore_case && !(ce->ce_flags & CE_UNHASHED)) add_dir_entry(istate, ce); @@ -124,8 +116,7 @@ static void lazy_init_name_hash(struct index_state *istate) if (istate->name_hash_initialized) return; - if (istate->cache_nr) - preallocate_hash(&istate->name_hash, istate->cache_nr); + hashmap_init(&istate->name_hash, NULL, istate->cache_nr); hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0); for (nr = 0; nr < istate->cache_nr; nr++) hash_index_entry(istate, istate->cache[nr]); @@ -221,18 +212,19 @@ struct cache_entry *index_dir_exists(struct index_state *istate, const char *nam struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int icase) { - unsigned int hash = memihash(name, namelen); struct cache_entry *ce; + struct hashmap_entry key; lazy_init_name_hash(istate); - ce = lookup_hash(hash, &istate->name_hash); + hashmap_entry_init(&key, memihash(name, namelen)); + ce = hashmap_get(&istate->name_hash, &key, NULL); while (ce) { if (!(ce->ce_flags & CE_UNHASHED)) { if (same_name(ce, name, namelen, icase)) return ce; } - ce = ce->next; + ce = hashmap_get_next(&istate->name_hash, ce); } return NULL; } @@ -250,6 +242,6 @@ void free_name_hash(struct index_state *istate) return; istate->name_hash_initialized = 0; - free_hash(&istate->name_hash); + hashmap_free(&istate->name_hash, 0); hashmap_free(&istate->dir_hash, 1); } diff --git a/unpack-trees.c b/unpack-trees.c index 35cb05e92b..86f5f8837e 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -110,7 +110,6 @@ static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, if (set & CE_REMOVE) set |= CE_WT_REMOVE; - ce->next = NULL; ce->ce_flags = (ce->ce_flags & ~clear) | set; add_index_entry(&o->result, ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); -- cgit v1.3 From 419a597f6408d5b5cffe3e278258f58b47d15ad3 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 14 Nov 2013 20:22:27 +0100 Subject: name-hash.c: remove cache entries instead of marking them CE_UNHASHED The new hashmap implementation supports remove, so really remove unused cache entries from the name hashmap instead of just marking them. The CE_UNHASHED flag and CE_STATE_MASK are no longer needed. Keep the CE_HASHED flag to prevent adding entries twice. Signed-off-by: Karsten Blees Signed-off-by: Junio C Hamano --- cache.h | 6 ++---- name-hash.c | 46 ++++++++++++++++++++++------------------------ read-cache.c | 2 +- unpack-trees.c | 2 +- 4 files changed, 26 insertions(+), 30 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 85210b1bd2..1f11e24cd0 100644 --- a/cache.h +++ b/cache.h @@ -160,7 +160,6 @@ struct cache_entry { #define CE_ADDED (1 << 19) #define CE_HASHED (1 << 20) -#define CE_UNHASHED (1 << 21) #define CE_WT_REMOVE (1 << 22) /* remove in work directory */ #define CE_CONFLICTED (1 << 23) @@ -196,11 +195,10 @@ struct pathspec; * Copy the sha1 and stat state of a cache entry from one to * another. But we never change the name, or the hash state! */ -#define CE_STATE_MASK (CE_HASHED | CE_UNHASHED) static inline void copy_cache_entry(struct cache_entry *dst, const struct cache_entry *src) { - unsigned int state = dst->ce_flags & CE_STATE_MASK; + unsigned int state = dst->ce_flags & CE_HASHED; /* Don't copy hash chain and name */ memcpy(&dst->ce_stat_data, &src->ce_stat_data, @@ -208,7 +206,7 @@ static inline void copy_cache_entry(struct cache_entry *dst, offsetof(struct cache_entry, ce_stat_data)); /* Restore the hash state */ - dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state; + dst->ce_flags = (dst->ce_flags & ~CE_HASHED) | state; } static inline unsigned create_ce_flags(unsigned stage) diff --git a/name-hash.c b/name-hash.c index 488eccf2f9..9a3bd3f9a6 100644 --- a/name-hash.c +++ b/name-hash.c @@ -106,17 +106,29 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce) hashmap_entry_init(ce, memihash(ce->name, ce_namelen(ce))); hashmap_add(&istate->name_hash, ce); - if (ignore_case && !(ce->ce_flags & CE_UNHASHED)) + if (ignore_case) add_dir_entry(istate, ce); } +static int cache_entry_cmp(const struct cache_entry *ce1, + const struct cache_entry *ce2, const void *remove) +{ + /* + * For remove_name_hash, find the exact entry (pointer equality); for + * index_name_exists, find all entries with matching hash code and + * decide whether the entry matches in same_name. + */ + return remove ? !(ce1 == ce2) : 0; +} + static void lazy_init_name_hash(struct index_state *istate) { int nr; if (istate->name_hash_initialized) return; - hashmap_init(&istate->name_hash, NULL, istate->cache_nr); + hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp, + istate->cache_nr); hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp, 0); for (nr = 0; nr < istate->cache_nr; nr++) hash_index_entry(istate, istate->cache[nr]); @@ -125,31 +137,19 @@ static void lazy_init_name_hash(struct index_state *istate) void add_name_hash(struct index_state *istate, struct cache_entry *ce) { - /* if already hashed, add reference to directory entries */ - if (ignore_case && (ce->ce_flags & CE_STATE_MASK) == CE_STATE_MASK) - add_dir_entry(istate, ce); - - ce->ce_flags &= ~CE_UNHASHED; if (istate->name_hash_initialized) hash_index_entry(istate, ce); } -/* - * We don't actually *remove* it, we can just mark it invalid so that - * we won't find it in lookups. - * - * Not only would we have to search the lists (simple enough), but - * we'd also have to rehash other hash buckets in case this makes the - * hash bucket empty (common). So it's much better to just mark - * it. - */ void remove_name_hash(struct index_state *istate, struct cache_entry *ce) { - /* if already hashed, release reference to directory entries */ - if (ignore_case && (ce->ce_flags & CE_STATE_MASK) == CE_HASHED) - remove_dir_entry(istate, ce); + if (!istate->name_hash_initialized || !(ce->ce_flags & CE_HASHED)) + return; + ce->ce_flags &= ~CE_HASHED; + hashmap_remove(&istate->name_hash, ce, ce); - ce->ce_flags |= CE_UNHASHED; + if (ignore_case) + remove_dir_entry(istate, ce); } static int slow_same_name(const char *name1, int len1, const char *name2, int len2) @@ -220,10 +220,8 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na hashmap_entry_init(&key, memihash(name, namelen)); ce = hashmap_get(&istate->name_hash, &key, NULL); while (ce) { - if (!(ce->ce_flags & CE_UNHASHED)) { - if (same_name(ce, name, namelen, icase)) - return ce; - } + if (same_name(ce, name, namelen, icase)) + return ce; ce = hashmap_get_next(&istate->name_hash, ce); } return NULL; diff --git a/read-cache.c b/read-cache.c index 33dd676ccb..00af9addd9 100644 --- a/read-cache.c +++ b/read-cache.c @@ -58,7 +58,7 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n new = xmalloc(cache_entry_size(namelen)); copy_cache_entry(new, old); - new->ce_flags &= ~CE_STATE_MASK; + new->ce_flags &= ~CE_HASHED; new->ce_namelen = namelen; memcpy(new->name, new_name, namelen + 1); diff --git a/unpack-trees.c b/unpack-trees.c index 86f5f8837e..36f3a7d06c 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -105,7 +105,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, unsigned int set, unsigned int clear) { - clear |= CE_HASHED | CE_UNHASHED; + clear |= CE_HASHED; if (set & CE_REMOVE) set |= CE_WT_REMOVE; -- cgit v1.3 From efc684245b81ae0fb8f0afbd06dc1c3101c4e5a0 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 14 Nov 2013 20:23:12 +0100 Subject: remove old hash.[ch] implementation Signed-off-by: Karsten Blees Signed-off-by: Junio C Hamano --- Documentation/technical/api-hash.txt | 52 ----------------- Makefile | 2 - cache.h | 1 - hash.c | 110 ----------------------------------- hash.h | 50 ---------------- test-hashmap.c | 84 -------------------------- 6 files changed, 299 deletions(-) delete mode 100644 Documentation/technical/api-hash.txt delete mode 100644 hash.c delete mode 100644 hash.h (limited to 'cache.h') diff --git a/Documentation/technical/api-hash.txt b/Documentation/technical/api-hash.txt deleted file mode 100644 index e5061e0677..0000000000 --- a/Documentation/technical/api-hash.txt +++ /dev/null @@ -1,52 +0,0 @@ -hash API -======== - -The hash API is a collection of simple hash table functions. Users are expected -to implement their own hashing. - -Data Structures ---------------- - -`struct hash_table`:: - - The hash table structure. The `array` member points to the hash table - entries. The `size` member counts the total number of valid and invalid - entries in the table. The `nr` member keeps track of the number of - valid entries. - -`struct hash_table_entry`:: - - An opaque structure representing an entry in the hash table. The `hash` - member is the entry's hash key and the `ptr` member is the entry's - value. - -Functions ---------- - -`init_hash`:: - - Initialize the hash table. - -`free_hash`:: - - Release memory associated with the hash table. - -`insert_hash`:: - - Insert a pointer into the hash table. If an entry with that hash - already exists, a pointer to the existing entry's value is returned. - Otherwise NULL is returned. This allows callers to implement - chaining, etc. - -`lookup_hash`:: - - Lookup an entry in the hash table. If an entry with that hash exists - the entry's value is returned. Otherwise NULL is returned. - -`for_each_hash`:: - - Call a function for each entry in the hash table. The function is - expected to take the entry's value as its only argument and return an - int. If the function returns a negative int the loop is aborted - immediately. Otherwise, the return value is accumulated and the sum - returned upon completion of the loop. diff --git a/Makefile b/Makefile index d8d3d6705b..f495dd4c13 100644 --- a/Makefile +++ b/Makefile @@ -677,7 +677,6 @@ LIB_H += git-compat-util.h LIB_H += gpg-interface.h LIB_H += graph.h LIB_H += grep.h -LIB_H += hash.h LIB_H += hashmap.h LIB_H += help.h LIB_H += http.h @@ -809,7 +808,6 @@ LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o LIB_OBJS += grep.o -LIB_OBJS += hash.o LIB_OBJS += hashmap.o LIB_OBJS += help.o LIB_OBJS += hex.o diff --git a/cache.h b/cache.h index 1f11e24cd0..407145c364 100644 --- a/cache.h +++ b/cache.h @@ -3,7 +3,6 @@ #include "git-compat-util.h" #include "strbuf.h" -#include "hash.h" #include "hashmap.h" #include "advice.h" #include "gettext.h" diff --git a/hash.c b/hash.c deleted file mode 100644 index 749ecfe484..0000000000 --- a/hash.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Some generic hashing helpers. - */ -#include "cache.h" -#include "hash.h" - -/* - * Look up a hash entry in the hash table. Return the pointer to - * the existing entry, or the empty slot if none existed. The caller - * can then look at the (*ptr) to see whether it existed or not. - */ -static struct hash_table_entry *lookup_hash_entry(unsigned int hash, const struct hash_table *table) -{ - unsigned int size = table->size, nr = hash % size; - struct hash_table_entry *array = table->array; - - while (array[nr].ptr) { - if (array[nr].hash == hash) - break; - nr++; - if (nr >= size) - nr = 0; - } - return array + nr; -} - - -/* - * Insert a new hash entry pointer into the table. - * - * If that hash entry already existed, return the pointer to - * the existing entry (and the caller can create a list of the - * pointers or do anything else). If it didn't exist, return - * NULL (and the caller knows the pointer has been inserted). - */ -static void **insert_hash_entry(unsigned int hash, void *ptr, struct hash_table *table) -{ - struct hash_table_entry *entry = lookup_hash_entry(hash, table); - - if (!entry->ptr) { - entry->ptr = ptr; - entry->hash = hash; - table->nr++; - return NULL; - } - return &entry->ptr; -} - -static void grow_hash_table(struct hash_table *table) -{ - unsigned int i; - unsigned int old_size = table->size, new_size; - struct hash_table_entry *old_array = table->array, *new_array; - - new_size = alloc_nr(old_size); - new_array = xcalloc(sizeof(struct hash_table_entry), new_size); - table->size = new_size; - table->array = new_array; - table->nr = 0; - for (i = 0; i < old_size; i++) { - unsigned int hash = old_array[i].hash; - void *ptr = old_array[i].ptr; - if (ptr) - insert_hash_entry(hash, ptr, table); - } - free(old_array); -} - -void *lookup_hash(unsigned int hash, const struct hash_table *table) -{ - if (!table->array) - return NULL; - return lookup_hash_entry(hash, table)->ptr; -} - -void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table) -{ - unsigned int nr = table->nr; - if (nr >= table->size/2) - grow_hash_table(table); - return insert_hash_entry(hash, ptr, table); -} - -int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data) -{ - int sum = 0; - unsigned int i; - unsigned int size = table->size; - struct hash_table_entry *array = table->array; - - for (i = 0; i < size; i++) { - void *ptr = array->ptr; - array++; - if (ptr) { - int val = fn(ptr, data); - if (val < 0) - return val; - sum += val; - } - } - return sum; -} - -void free_hash(struct hash_table *table) -{ - free(table->array); - table->array = NULL; - table->size = 0; - table->nr = 0; -} diff --git a/hash.h b/hash.h deleted file mode 100644 index 1d43ac0ba0..0000000000 --- a/hash.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef HASH_H -#define HASH_H - -/* - * These are some simple generic hash table helper functions. - * Not necessarily suitable for all users, but good for things - * where you want to just keep track of a list of things, and - * have a good hash to use on them. - * - * It keeps the hash table at roughly 50-75% free, so the memory - * cost of the hash table itself is roughly - * - * 3 * 2*sizeof(void *) * nr_of_objects - * - * bytes. - * - * FIXME: on 64-bit architectures, we waste memory. It would be - * good to have just 32-bit pointers, requiring a special allocator - * for hashed entries or something. - */ -struct hash_table_entry { - unsigned int hash; - void *ptr; -}; - -struct hash_table { - unsigned int size, nr; - struct hash_table_entry *array; -}; - -extern void *lookup_hash(unsigned int hash, const struct hash_table *table); -extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table); -extern int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data); -extern void free_hash(struct hash_table *table); - -static inline void init_hash(struct hash_table *table) -{ - table->size = 0; - table->nr = 0; - table->array = NULL; -} - -static inline void preallocate_hash(struct hash_table *table, unsigned int elts) -{ - assert(table->size == 0 && table->nr == 0 && table->array == NULL); - table->size = elts * 2; - table->array = xcalloc(sizeof(struct hash_table_entry), table->size); -} - -#endif diff --git a/test-hashmap.c b/test-hashmap.c index 581d2964e4..7e86f886d8 100644 --- a/test-hashmap.c +++ b/test-hashmap.c @@ -126,85 +126,6 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) } } -struct hash_entry -{ - struct hash_entry *next; - char key[FLEX_ARRAY]; -}; - -/* - * Test performance of hash.[ch] - * Usage: time echo "perfhash method rounds" | test-hashmap - */ -static void perf_hash(unsigned int method, unsigned int rounds) -{ - struct hash_table map; - char buf[16]; - struct hash_entry **entries, **res, *entry; - unsigned int *hashes; - unsigned int i, j; - - entries = malloc(TEST_SIZE * sizeof(struct hash_entry *)); - hashes = malloc(TEST_SIZE * sizeof(int)); - for (i = 0; i < TEST_SIZE; i++) { - snprintf(buf, sizeof(buf), "%i", i); - entries[i] = malloc(sizeof(struct hash_entry) + strlen(buf) + 1); - strcpy(entries[i]->key, buf); - hashes[i] = hash(method, i, entries[i]->key); - } - - if (method & TEST_ADD) { - /* test adding to the map */ - for (j = 0; j < rounds; j++) { - init_hash(&map); - - /* add entries */ - for (i = 0; i < TEST_SIZE; i++) { - res = (struct hash_entry **) insert_hash( - hashes[i], entries[i], &map); - if (res) { - entries[i]->next = *res; - *res = entries[i]; - } else { - entries[i]->next = NULL; - } - } - - free_hash(&map); - } - } else { - /* test map lookups */ - init_hash(&map); - - /* fill the map (sparsely if specified) */ - j = (method & TEST_SPARSE) ? TEST_SIZE / 10 : TEST_SIZE; - for (i = 0; i < j; i++) { - res = (struct hash_entry **) insert_hash(hashes[i], - entries[i], &map); - if (res) { - entries[i]->next = *res; - *res = entries[i]; - } else { - entries[i]->next = NULL; - } - } - - for (j = 0; j < rounds; j++) { - for (i = 0; i < TEST_SIZE; i++) { - entry = lookup_hash(hashes[i], &map); - while (entry) { - if (!strcmp(entries[i]->key, entry->key)) - break; - entry = entry->next; - } - } - } - - free_hash(&map); - - } -} - #define DELIM " \t\r\n" /* @@ -218,7 +139,6 @@ static void perf_hash(unsigned int method, unsigned int rounds) * size -> tablesize numentries * * perfhashmap method rounds -> test hashmap.[ch] performance - * perfhash method rounds -> test hash.[ch] performance */ int main(int argc, char *argv[]) { @@ -324,10 +244,6 @@ int main(int argc, char *argv[]) perf_hashmap(atoi(p1), atoi(p2)); - } else if (!strcmp("perfhash", cmd) && l1 && l2) { - - perf_hash(atoi(p1), atoi(p2)); - } else { printf("Unknown command %s\n", cmd); -- cgit v1.3 From 7b359ea6b3333a87fd3fa8b84913f2b75ed244ad Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Thu, 2 Jan 2014 16:57:12 -0500 Subject: name-hash: retire unused index_name_exists() db5360f3f496 (name-hash: refactor polymorphic index_name_exists(); 2013-09-17) split index_name_exists() into index_file_exists() and index_dir_exists() but retained index_name_exists() as a thin wrapper to avoid disturbing possible in-flight topics. Since this change landed in 'master' some time ago and there are no in-flight topics referencing index_name_exists(), retire it. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- cache.h | 2 -- name-hash.c | 9 +-------- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 407145c364..353c687c19 100644 --- a/cache.h +++ b/cache.h @@ -316,7 +316,6 @@ extern void free_name_hash(struct index_state *istate); #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) #define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen)) #define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase)) -#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #define resolve_undo_clear() resolve_undo_clear_index(&the_index) #define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) @@ -467,7 +466,6 @@ extern int unmerged_index(const struct index_state *); extern int verify_path(const char *path); extern struct cache_entry *index_dir_exists(struct index_state *istate, const char *name, int namelen); extern struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase); -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 */ diff --git a/name-hash.c b/name-hash.c index 9a3bd3f9a6..97444d0201 100644 --- a/name-hash.c +++ b/name-hash.c @@ -115,7 +115,7 @@ static int cache_entry_cmp(const struct cache_entry *ce1, { /* * For remove_name_hash, find the exact entry (pointer equality); for - * index_name_exists, find all entries with matching hash code and + * index_file_exists, find all entries with matching hash code and * decide whether the entry matches in same_name. */ return remove ? !(ce1 == ce2) : 0; @@ -227,13 +227,6 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na return NULL; } -struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase) -{ - if (namelen > 0 && name[namelen - 1] == '/') - return index_dir_exists(istate, name, namelen - 1); - return index_file_exists(istate, name, namelen, icase); -} - void free_name_hash(struct index_state *istate) { if (!istate->name_hash_initialized) -- cgit v1.3