{"thread":{"id":"224","subject":"[PATCH 17/19] temporarily change add_cache_entry to create an empty cache on demand","startedAt":"2005-04-21T18:38:51Z","lastAt":"2005-04-21T18:38:51Z","messageCount":1,"participants":["Brad Roberts"],"isPatch":true,"patchVersion":1,"patchTotal":19},"messages":[{"id":"1173","messageId":"200504211838.j3LIcpuC027819@gameboy2.puremagic.com","threadId":"224","inReplyTo":null,"subject":"[PATCH 17/19] temporarily change add_cache_entry to create an empty cache on demand","fromName":"Brad Roberts","fromEmail":"braddr@gameboy2.puremagic.com","sentAt":"2005-04-21T18:38:51Z","receivedAt":"2005-04-21T18:38:51Z","isPatch":true,"sender":{"key":"braddr@gameboy2.puremagic.com","avatar":null},"body":"tree 6feaeb314fb1bea393250972b109b7d218cf37d7\nparent b965055600b8bf4927ea631446cd6cde714aef95\nauthor Brad Roberts <braddr@puremagic.com> 1114087949 -0700\ncommitter Brad Roberts <braddr@gameboy2.puremagic.com> 1114087949 -0700\n\n[PATCH] temporarily change add_cache_entry to create an empty cache on demand\n\nread-tree.c expects to be able to add entries into an empty cache in the\nnon-merging mode.\n\nSigned-off-by: Brad Roberts <braddr@puremagic.com>\n---\n\n read-cache.c |   26 ++++++++++++++++++--------\n 1 files changed, 18 insertions(+), 8 deletions(-)\n\nIndex: read-cache.c\n===================================================================\n--- b965055600b8bf4927ea631446cd6cde714aef95:1/read-cache.c  (mode:100644 sha1:c399f8e497441147afe630ca080558a8c6c79c78)\n+++ 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/read-cache.c  (mode:100644 sha1:31e293a3686622c9ec180d41aa37d85ce49325e8)\n@@ -32,6 +32,18 @@\n \n static struct cache * cache = NULL;\n \n+struct cache * new_cache()\n+{\n+\treturn (struct cache*)calloc(1, sizeof(struct cache));\n+}\n+\n+void free_cache()\n+{\n+\tmunmap(cache->map.ptr, cache->map.size);\n+\tfree(cache);\n+\tcache = NULL;\n+}\n+\n int cache_match_stat(struct cache_entry *ce, struct stat *st)\n {\n \tunsigned int changed = 0;\n@@ -155,6 +167,11 @@\n {\n \tint pos;\n \n+\t/* temporary, read-tree.c expects the cache to always exist, even\n+\t * without a read_cache being called */\n+\tif (!cache)\n+\t\tcache = new_cache();\n+\n \tpos = cache_name_pos(ce->name, htons(ce->ce_flags));\n \n \t/* existing match? Just replace it */\n@@ -230,7 +247,7 @@\n \t\treturn (errno == ENOENT) ? 0 : error(\"open failed\");\n \n \terrno = ENOMEM;\n-\tcache = (struct cache*)malloc(sizeof(struct cache));\n+\tcache = new_cache();\n \tif (!cache)\n \t\treturn error(\"unable to allocate cache\");\n \n@@ -333,10 +350,3 @@\n \t}\n \treturn ce_flush(&c, newfd);\n }\n-\n-void free_cache()\n-{\n-\tmunmap(cache->map.ptr, cache->map.size);\n-\tfree(cache);\n-\tcache = NULL;\n-}\n\n"}]}