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

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

From
Thomas Rast <tr@thomasrast.ch>
Date
Feb 22, 2014, 09:17 UTC
Message-ID
<38527c9f6ae31ad39d8f3dddfe5252a3527629ed.1393059605.git.tr@thomasrast.ch>
In-Reply-To
<cover.1393059605.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 | 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
Previous: Thomas RastNext: Eric Sunshine
Message 11 of 16 in “log --remerge-diff”
  1. 0/8 log --remerge-diffThomas Rast, Feb 22, 2014
  2. 1/8 merge-recursive: remove dead conditional in update_stages()Thomas Rast, Feb 22, 2014
  3. 2/8 merge-recursive: internal flag to avoid touching the worktreeThomas Rast, Feb 22, 2014
  4. 3/8 merge-recursive: -Xindex-only to leave worktree unchangedThomas Rast, Feb 22, 2014
  5. Eric SunshineFeb 23, 2014
  6. Thomas RastFeb 23, 2014
  7. Eric SunshineFeb 23, 2014
  8. 4/8 combine-diff: do not pass revs->dense_combined_merges redundantlyThomas Rast, Feb 22, 2014
  9. 5/8 Fold all merge diff variants into an enumThomas Rast, Feb 22, 2014
  10. 6/8 merge-recursive: allow storing conflict hunks in indexThomas Rast, Feb 22, 2014
  11. 7/8 name-hash: allow dir hashing even when !ignore_caseThomas Rast, Feb 22, 2014
  12. Eric SunshineFeb 23, 2014
  13. Thomas RastSep 6, 2014
  14. Junio C HamanoFeb 27, 2014
  15. 8/8 log --remerge-diff: show what the conflict resolution changedThomas Rast, Feb 22, 2014
  16. Junio C HamanoFeb 27, 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.