{"thread":{"id":"26419","subject":"[PATCH 1/2] sha1_file.c: move find_cached_object up so sha1_object_info can use it","startedAt":"2011-02-05T14:03:01Z","lastAt":"2011-02-05T14:03:02Z","messageCount":2,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"160440","messageId":"1296914582-619-1-git-send-email-pclouds@gmail.com","threadId":"26419","inReplyTo":null,"subject":"[PATCH 1/2] sha1_file.c: move find_cached_object up so sha1_object_info can use it","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-02-05T14:03:01Z","receivedAt":"2011-02-05T14:03:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1_file.c |   70 +++++++++++++++++++++++++++++-----------------------------\n 1 files changed, 35 insertions(+), 35 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex d86a8db..9fd7e16 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -37,6 +37,41 @@ const unsigned char null_sha1[20];\n \n static int git_open_noatime(const char *name, struct packed_git *p);\n \n+/*\n+ * This is meant to hold a *small* number of objects that you would\n+ * want read_sha1_file() to be able to return, but yet you do not want\n+ * to write them into the object store (e.g. a browse-only\n+ * application).\n+ */\n+static struct cached_object {\n+\tunsigned char sha1[20];\n+\tenum object_type type;\n+\tvoid *buf;\n+\tunsigned long size;\n+} *cached_objects;\n+static int cached_object_nr, cached_object_alloc;\n+\n+static struct cached_object empty_tree = {\n+\tEMPTY_TREE_SHA1_BIN,\n+\tOBJ_TREE,\n+\t\"\",\n+\t0\n+};\n+\n+static struct cached_object *find_cached_object(const unsigned char *sha1)\n+{\n+\tint i;\n+\tstruct cached_object *co = cached_objects;\n+\n+\tfor (i = 0; i < cached_object_nr; i++, co++) {\n+\t\tif (!hashcmp(co->sha1, sha1))\n+\t\t\treturn co;\n+\t}\n+\tif (!hashcmp(sha1, empty_tree.sha1))\n+\t\treturn &empty_tree;\n+\treturn NULL;\n+}\n+\n int safe_create_leading_directories(char *path)\n {\n \tchar *pos = path + offset_1st_component(path);\n@@ -2033,41 +2068,6 @@ static void *read_packed_sha1(const unsigned char *sha1,\n \treturn data;\n }\n \n-/*\n- * This is meant to hold a *small* number of objects that you would\n- * want read_sha1_file() to be able to return, but yet you do not want\n- * to write them into the object store (e.g. a browse-only\n- * application).\n- */\n-static struct cached_object {\n-\tunsigned char sha1[20];\n-\tenum object_type type;\n-\tvoid *buf;\n-\tunsigned long size;\n-} *cached_objects;\n-static int cached_object_nr, cached_object_alloc;\n-\n-static struct cached_object empty_tree = {\n-\tEMPTY_TREE_SHA1_BIN,\n-\tOBJ_TREE,\n-\t\"\",\n-\t0\n-};\n-\n-static struct cached_object *find_cached_object(const unsigned char *sha1)\n-{\n-\tint i;\n-\tstruct cached_object *co = cached_objects;\n-\n-\tfor (i = 0; i < cached_object_nr; i++, co++) {\n-\t\tif (!hashcmp(co->sha1, sha1))\n-\t\t\treturn co;\n-\t}\n-\tif (!hashcmp(sha1, empty_tree.sha1))\n-\t\treturn &empty_tree;\n-\treturn NULL;\n-}\n-\n int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,\n \t\t      unsigned char *sha1)\n {\n-- \n1.7.3.4.878.g439c7\n"},{"id":"160441","messageId":"1296914582-619-2-git-send-email-pclouds@gmail.com","threadId":"26419","inReplyTo":"1296914582-619-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/2] sha1_object_info: examine cached_object store too","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-02-05T14:03:02Z","receivedAt":"2011-02-05T14:03:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Cached object store was added in d66b37b (Add pretend_sha1_file()\ninterface. - 2007-02-04) as a way to temporarily inject some objects\nto object store.\n\nBut only read_sha1_file() knows about this store. While it will return\nan object from this store, sha1_object_info() will happily say\n\"object not found\".\n\nTeach sha1_object_info() about the cached store for consistency.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n \"git mktree\" does not accept empty tree as it should do because of this.\n\n sha1_file.c |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 9fd7e16..0b830c8 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2020,9 +2020,17 @@ static int sha1_loose_object_info(const unsigned char *sha1, unsigned long *size\n \n int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)\n {\n+\tstruct cached_object *co;\n \tstruct pack_entry e;\n \tint status;\n \n+\tco = find_cached_object(sha1);\n+\tif (co) {\n+\t\tif (sizep)\n+\t\t\t*sizep = co->size;\n+\t\treturn co->type;\n+\t}\n+\n \tif (!find_pack_entry(sha1, &e)) {\n \t\t/* Most likely it's a loose object. */\n \t\tstatus = sha1_loose_object_info(sha1, sizep);\n-- \n1.7.3.4.878.g439c7\n"}]}