From: Thomas Rast
Date: Sat, 22 Feb 2014 09:17:55 GMT
Subject: [PATCH v2 7/8] name-hash: allow dir hashing even when !ignore_case
Message-ID: <38527c9f6ae31ad39d8f3dddfe5252a3527629ed.1393059605.git.tr@thomasrast.ch>
In-Reply-To:
The directory hash (for fast checks if the index already has a
directory) was only used in ignore_case mode and so depended on that
flag.
Make it generally available on request.
Signed-off-by: Thomas Rast
---
cache.h | 2 ++
name-hash.c | 19 ++++++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/cache.h b/cache.h
index dc040fb..e162021 100644
--- a/cache.h
+++ b/cache.h
@@ -276,6 +276,7 @@ struct index_state {
struct cache_tree *cache_tree;
struct cache_time timestamp;
unsigned name_hash_initialized : 1,
+ has_dir_hash : 1,
initialized : 1;
struct hash_table name_hash;
struct hash_table dir_hash;
@@ -284,6 +285,7 @@ struct index_state {
extern struct index_state the_index;
/* Name hashing */
+extern void init_name_hash(struct index_state *istate, int force_dir_hash);
extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);
extern void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
extern void free_name_hash(struct index_state *istate);
diff --git a/name-hash.c b/name-hash.c
index e5b6e1a..c8953be 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -141,16 +141,19 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
*pos = ce;
}
- if (ignore_case && !(ce->ce_flags & CE_UNHASHED))
+ if (istate->has_dir_hash && !(ce->ce_flags & CE_UNHASHED))
add_dir_entry(istate, ce);
}
-static void lazy_init_name_hash(struct index_state *istate)
+void init_name_hash(struct index_state *istate, int force_dir_hash)
{
int nr;
if (istate->name_hash_initialized)
return;
+
+ istate->has_dir_hash = force_dir_hash || ignore_case;
+
if (istate->cache_nr)
preallocate_hash(&istate->name_hash, istate->cache_nr);
for (nr = 0; nr < istate->cache_nr; nr++)
@@ -161,7 +164,7 @@ 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)
+ if (istate->has_dir_hash && (ce->ce_flags & CE_STATE_MASK) == CE_STATE_MASK)
add_dir_entry(istate, ce);
ce->ce_flags &= ~CE_UNHASHED;
@@ -181,7 +184,7 @@ void add_name_hash(struct index_state *istate, struct cache_entry *ce)
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)
+ if (istate->has_dir_hash && (ce->ce_flags & CE_STATE_MASK) == CE_HASHED)
remove_dir_entry(istate, ce);
ce->ce_flags |= CE_UNHASHED;
@@ -228,7 +231,7 @@ struct cache_entry *index_dir_exists(struct index_state *istate, const char *nam
struct cache_entry *ce;
struct dir_entry *dir;
- lazy_init_name_hash(istate);
+ init_name_hash(istate, 0);
dir = find_dir_entry(istate, name, namelen);
if (dir && dir->nr)
return dir->ce;
@@ -250,7 +253,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
unsigned int hash = hash_name(name, namelen);
struct cache_entry *ce;
- lazy_init_name_hash(istate);
+ init_name_hash(istate, 0);
ce = lookup_hash(hash, &istate->name_hash);
while (ce) {
@@ -286,9 +289,11 @@ void free_name_hash(struct index_state *istate)
if (!istate->name_hash_initialized)
return;
istate->name_hash_initialized = 0;
- if (ignore_case)
+ if (istate->has_dir_hash) {
/* free directory entries */
for_each_hash(&istate->dir_hash, free_dir_entry, NULL);
+ istate->has_dir_hash = 0;
+ }
free_hash(&istate->name_hash);
free_hash(&istate->dir_hash);
--
1.9.0.313.g3d0a325