{"thread":{"id":"43715","subject":"[PATCH] sha1_object_info(): be consistent with read_sha1_file()","startedAt":"2006-11-27T23:18:55Z","lastAt":"2006-11-28T01:05:58Z","messageCount":2,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"297244","messageId":"Pine.LNX.4.63.0611280016150.30004@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43715","inReplyTo":null,"subject":"[PATCH] sha1_object_info(): be consistent with read_sha1_file()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-11-27T23:18:55Z","receivedAt":"2006-11-27T23:18:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWe used to try loose objects first with sha1_object_info(), but packed\nobjects first with read_sha1_file(). Now, prefer packed objects over loose\nones with sha1_object_info(), too.\n\nUsually the old behaviour would pose no problem, but when you tried to fix \na fscked up repository by inserting a known-good pack,\n\n\tgit cat-file $(git cat-file -t <sha1>) <sha1>\n\ncould fail, even when\n\n\tgit cat-file blob <sha1>\n\nwould _not_ fail. Worse, a repack would fail, too.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n sha1_file.c |   35 ++++++++++++++++++++---------------\n 1 files changed, 20 insertions(+), 15 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 09456d2..63f416b 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1261,7 +1261,7 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,\n \t\n }\n \n-int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)\n+static int sha1_loose_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)\n {\n \tint status;\n \tunsigned long mapsize, size;\n@@ -1270,20 +1270,8 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep\n \tchar hdr[128];\n \n \tmap = map_sha1_file(sha1, &mapsize);\n-\tif (!map) {\n-\t\tstruct pack_entry e;\n-\n-\t\tif (!find_pack_entry(sha1, &e, NULL)) {\n-\t\t\treprepare_packed_git();\n-\t\t\tif (!find_pack_entry(sha1, &e, NULL))\n-\t\t\t\treturn error(\"unable to find %s\", sha1_to_hex(sha1));\n-\t\t}\n-\t\tif (use_packed_git(e.p))\n-\t\t\tdie(\"cannot map packed file\");\n-\t\tstatus = packed_object_info(e.p, e.offset, type, sizep);\n-\t\tunuse_packed_git(e.p);\n-\t\treturn status;\n-\t}\n+\tif (!map)\n+\t\treturn error(\"unable to find %s\", sha1_to_hex(sha1));\n \tif (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)\n \t\tstatus = error(\"unable to unpack %s header\",\n \t\t\t       sha1_to_hex(sha1));\n@@ -1299,6 +1287,23 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep\n \treturn status;\n }\n \n+int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep)\n+{\n+\tint status;\n+\tstruct pack_entry e;\n+\n+\tif (!find_pack_entry(sha1, &e, NULL)) {\n+\t\treprepare_packed_git();\n+\t\tif (!find_pack_entry(sha1, &e, NULL))\n+\t\t\treturn sha1_loose_object_info(sha1, type, sizep);\n+\t}\n+\tif (use_packed_git(e.p))\n+\t\tdie(\"cannot map packed file\");\n+\tstatus = packed_object_info(e.p, e.offset, type, sizep);\n+\tunuse_packed_git(e.p);\n+\treturn status;\n+}\n+\n static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned long *size)\n {\n \tstruct pack_entry e;\n-- \n1.4.4.1.gfac7-dirty\n"},{"id":"298487","messageId":"7vslg4crd5.fsf@assigned-by-dhcp.cox.net","threadId":"43715","inReplyTo":"Pine.LNX.4.63.0611280016150.30004@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_object_info(): be consistent with read_sha1_file()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-28T01:05:58Z","receivedAt":"2006-11-28T01:05:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> We used to try loose objects first with sha1_object_info(), but packed\n> objects first with read_sha1_file(). Now, prefer packed objects over loose\n> ones with sha1_object_info(), too.\n\nWell caught.  It appears this inconsistent order was from the\nday one when we started using the packed git, and I forgot to\nswap them when I did ab90ea5 to swap the reading side.\n\nThanks.\n\n\n"}]}