git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Thomas Rast <tr@thomasrast.ch>
Date
Sep 6, 2014, 17:57 UTC
Message-ID
<4d43fca586637dcb02b2b19c8d8a6dcfe368e059.1409860234.git.tr@thomasrast.ch>
In-Reply-To
<cover.1409860234.git.tr@thomasrast.ch>

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 <tr@thomasrast.ch>
---
 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);
 }
 
@@ -121,7 +121,7 @@ static int cache_entry_cmp(const struct cache_entry *ce1,
 	return remove ? !(ce1 == ce2) : 0;
 }
 
-static void lazy_init_name_hash(struct index_state *istate)
+void init_name_hash(struct index_state *istate, int force_dir_hash)
 {
 	int nr;
 
@@ -130,6 +130,9 @@ static void lazy_init_name_hash(struct index_state *istate)
 	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);
+
+	istate->has_dir_hash = force_dir_hash || ignore_case;
+
 	for (nr = 0; nr < istate->cache_nr; nr++)
 		hash_index_entry(istate, istate->cache[nr]);
 	istate->name_hash_initialized = 1;
@@ -148,7 +151,7 @@ void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
 	ce->ce_flags &= ~CE_HASHED;
 	hashmap_remove(&istate->name_hash, ce, ce);
 
-	if (ignore_case)
+	if (istate->has_dir_hash)
 		remove_dir_entry(istate, ce);
 }
 
@@ -193,7 +196,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;
@@ -214,7 +217,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
 {
 	struct cache_entry *ce;
 
-	lazy_init_name_hash(istate);
+	init_name_hash(istate, 0);
 
 	ce = hashmap_get_from_hash(&istate->name_hash,
 				   memihash(name, namelen), NULL);
-- 
2.1.0.72.g9b94086
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 of 18 in “--remerge-diff”
  1. 0/8 --remerge-diffThomas Rast, Sep 6, 2014
  2. 1/8 merge-recursive: remove dead conditional in update_stages()Thomas Rast, Sep 6, 2014
  3. 2/8 merge-recursive: internal flag to avoid touching the worktreeThomas Rast, Sep 6, 2014
  4. Junio C HamanoSep 8, 2014
  5. 3/8 merge-recursive: -Xindex-only to leave worktree unchangedThomas Rast, Sep 6, 2014
  6. 4/8 combine-diff: do not pass revs->dense_combined_merges redundantlyThomas Rast, Sep 6, 2014
  7. Junio C HamanoSep 8, 2014
  8. Jens LehmannSep 11, 2014
  9. 5/8 Fold all merge diff variants into an enumThomas Rast, Sep 6, 2014
  10. Junio C HamanoSep 8, 2014
  11. 6/8 merge-recursive: allow storing conflict hunks in indexThomas Rast, Sep 6, 2014
  12. Junio C HamanoSep 9, 2014
  13. 7/8 name-hash: allow dir hashing even when !ignore_caseThomas Rast, Sep 6, 2014
  14. Junio C HamanoSep 9, 2014
  15. 8/8 log --remerge-diff: show what the conflict resolution changedThomas Rast, Sep 6, 2014
  16. Junio C HamanoSep 8, 2014
  17. Junio C HamanoSep 9, 2014
  18. Junio C HamanoSep 9, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.