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

[PATCH 17/19] temporarily change add_cache_entry to create an empty cache on demand

From
BRBrad Roberts <braddr@gameboy2.puremagic.com>
Date
Apr 21, 2005, 18:38 UTC
Message-ID
<200504211838.j3LIcpuC027819@gameboy2.puremagic.com>

tree 6feaeb314fb1bea393250972b109b7d218cf37d7 parent b965055600b8bf4927ea631446cd6cde714aef95 author Brad Roberts <braddr@puremagic.com> 1114087949 -0700 committer Brad Roberts <braddr@gameboy2.puremagic.com> 1114087949 -0700

[PATCH] temporarily change add_cache_entry to create an empty cache on demand

read-tree.c expects to be able to add entries into an empty cache in the non-merging mode.

Signed-off-by: Brad Roberts <braddr@puremagic.com>
---
 read-cache.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
Index: read-cache.c
===================================================================
--- b965055600b8bf4927ea631446cd6cde714aef95:1/read-cache.c  (mode:100644 sha1:c399f8e497441147afe630ca080558a8c6c79c78)
+++ 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/read-cache.c  (mode:100644 sha1:31e293a3686622c9ec180d41aa37d85ce49325e8)
@@ -32,6 +32,18 @@
 
 static struct cache * cache = NULL;
 
+struct cache * new_cache()
+{
+	return (struct cache*)calloc(1, sizeof(struct cache));
+}
+
+void free_cache()
+{
+	munmap(cache->map.ptr, cache->map.size);
+	free(cache);
+	cache = NULL;
+}
+
 int cache_match_stat(struct cache_entry *ce, struct stat *st)
 {
 	unsigned int changed = 0;
@@ -155,6 +167,11 @@
 {
 	int pos;
 
+	/* temporary, read-tree.c expects the cache to always exist, even
+	 * without a read_cache being called */
+	if (!cache)
+		cache = new_cache();
+
 	pos = cache_name_pos(ce->name, htons(ce->ce_flags));
 
 	/* existing match? Just replace it */
@@ -230,7 +247,7 @@
 		return (errno == ENOENT) ? 0 : error("open failed");
 
 	errno = ENOMEM;
-	cache = (struct cache*)malloc(sizeof(struct cache));
+	cache = new_cache();
 	if (!cache)
 		return error("unable to allocate cache");
 
@@ -333,10 +350,3 @@
 	}
 	return ce_flush(&c, newfd);
 }
-
-void free_cache()
-{
-	munmap(cache->map.ptr, cache->map.size);
-	free(cache);
-	cache = NULL;
-}
Message 1 of 1 in “temporarily change add_cache_entry to create an empty cache on demand”
  1. 17/19 temporarily change add_cache_entry to create an empty cache on demandBrad Roberts, Apr 21, 2005

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.