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

[PATCH 2/3] Name hash fixups: export (and rename) remove_hash_entry

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 23, 2008, 04:39 UTC
Message-ID
<alpine.LFD.1.00.0802222037560.21332@woody.linux-foundation.org>
In-Reply-To
<alpine.LFD.1.00.0802222033570.21332@woody.linux-foundation.org>
From: Linus Torvalds <torvalds@linux-foundation.org>

This makes the name hash removal function (which really just sets the bit that disables lookups of it) available to external routines, and makes read_cache_unmerged() use it when it drops an unmerged entry from the index.

It's renamed to remove_index_entry(), and we drop the (unused) 'istate' argument.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
Oops, I forgot to number the previous patch. That was 1/3.
The changelog above matches what the patch obviously does.
 builtin-read-tree.c |    1 +
 cache.h             |   14 ++++++++++++++
 read-cache.c        |   18 ++----------------
 3 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 726fb0b..7bdc312 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -41,6 +41,7 @@ static int read_cache_unmerged(void)
 	for (i = 0; i < active_nr; i++) {
 		struct cache_entry *ce = active_cache[i];
 		if (ce_stage(ce)) {
+			remove_index_entry(ce);
 			if (last && !strcmp(ce->name, last->name))
 				continue;
 			cache_tree_invalidate_path(active_cache_tree, ce->name);
diff --git a/cache.h b/cache.h
index 0b69c92..88d3b92 100644
--- a/cache.h
+++ b/cache.h
@@ -137,6 +137,20 @@ struct cache_entry {
 #define CE_HASHED    (0x100000)
 #define CE_UNHASHED  (0x200000)
 
+/*
+ * 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.
+ */
+static inline void remove_index_entry(struct cache_entry *ce)
+{
+	ce->ce_flags |= CE_UNHASHED;
+}
+
 static inline unsigned create_ce_flags(size_t len, unsigned stage)
 {
 	if (len >= CE_NAMEMASK)
diff --git a/read-cache.c b/read-cache.c
index eb58b03..fee0c80 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -70,25 +70,11 @@ static void set_index_entry(struct index_state *istate, int nr, struct cache_ent
 		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.
- */
-static void remove_hash_entry(struct index_state *istate, struct cache_entry *ce)
-{
-	ce->ce_flags |= CE_UNHASHED;
-}
-
 static void replace_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
 {
 	struct cache_entry *old = istate->cache[nr];
 
-	remove_hash_entry(istate, old);
+	remove_index_entry(old);
 	set_index_entry(istate, nr, ce);
 	istate->cache_changed = 1;
 }
@@ -417,7 +403,7 @@ int remove_index_entry_at(struct index_state *istate, int pos)
 {
 	struct cache_entry *ce = istate->cache[pos];
 
-	remove_hash_entry(istate, ce);
+	remove_index_entry(ce);
 	istate->cache_changed = 1;
 	istate->cache_nr--;
 	if (pos >= istate->cache_nr)
Previous: Linus TorvaldsNext: Linus Torvalds
Message 3 of 4 in “Fix up some name hashing uglies..”
  1. 0/3 Fix up some name hashing uglies..Linus Torvalds, Feb 23, 2008
  2. Fix name re-hashing semanticsLinus Torvalds, Feb 23, 2008
  3. 2/3 Name hash fixups: export (and rename) remove_hash_entryLinus Torvalds, Feb 23, 2008
  4. 3/3 Use helper function for copying index entry informationLinus Torvalds, Feb 23, 2008

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.