threads / patch / 224

patch, 19 partstemporarily change add_cache_entry to create an empty cache on demand

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

## tl;dr

One message between Apr 21, 2005 and Apr 21, 2005. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Brad Roberts· Apr 21, 2005, 18:38 UTC · lore

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(-)
Show changes to diff +18 −8
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;
-}

← back to recent threads