Subject: Re: [PATCH v3 7/8] name-hash: allow dir hashing even when !ignore_case

From: Junio C Hamano <[email-masked]>
Date: Tue, 09 Sep 2014 10:49:44 -0700

Thomas Rast <[email-masked]> writes:

> 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 <[email-masked]>
> ---
>  cache.h     |  2 ++
>  name-hash.c | 13 ++++++++-----
>  2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index 4d5b76c..c54b2e1 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -306,6 +306,7 @@ struct index_state {
>  	struct split_index *split_index;
>  	struct cache_time timestamp;
>  	unsigned name_hash_initialized : 1,
> +		 has_dir_hash : 1,
>  		 initialized : 1;
>  	struct hashmap name_hash;
>  	struct hashmap dir_hash;
> @@ -315,6 +316,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 702cd05..22e3ec6 100644
> --- a/name-hash.c
> +++ b/name-hash.c
> @@ -106,7 +106,7 @@ 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)
> +	if (istate->has_dir_hash)
>  		add_dir_entry(istate, ce);

This smells more like needs_dir_hash than has_dir_hash to me.  For
ignore-case, we need dir_hash to make sure we do not end up adding
two entries that cannot be represented on the filesystem.