{"thread":{"id":"43091","subject":"Re: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack","startedAt":"2006-10-26T03:31:53Z","lastAt":"2006-10-26T13:46:18Z","messageCount":3,"participants":["Junio C Hamano","Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"298201","messageId":"Pine.LNX.4.64.0610252330320.12418@xanadu.home","threadId":"43091","inReplyTo":null,"subject":"[PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-10-26T03:31:53Z","receivedAt":"2006-10-26T03:31:53Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"It appears that git-unpack-objects writes the last part of the input\nbuffer to stdout after the pack has been parsed.  This looks a bit\nsuspicious since the last fill() might have filled the buffer up to\nthe 4096 byte limit and more data might still be pending on stdin,\nbut since this is about being a drop-in replacement for unpack-objects\nlet's simply duplicate the same behavior for now.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n index-pack.c |   17 +++++++++++++++--\n 1 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 2046b37..7f7dc5d 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -456,6 +456,7 @@ static void parse_pack_objects(unsigned\n \tSHA1_Final(sha1, &input_ctx);\n \tif (hashcmp(fill(20), sha1))\n \t\tdie(\"pack is corrupted (SHA1 mismatch)\");\n+\tuse(20);\n \n \t/* If input_fd is a file, we should have reached its end now. */\n \tif (fstat(input_fd, &st))\n@@ -765,6 +766,18 @@ static void final(const char *final_pack\n \t\tif (err)\n \t\t\tdie(\"error while closing pack file: %s\", strerror(errno));\n \t\tchmod(curr_pack_name, 0444);\n+\n+\t\t/*\n+\t\t * Let's just mimic git-unpack-objects here and write\n+\t\t * the last part of the buffer to stdout.\n+\t\t */\n+\t\twhile (input_len) {\n+\t\t\terr = xwrite(1, input_buffer + input_offset, input_len);\n+\t\t\tif (err <= 0)\n+\t\t\t\tbreak;\n+\t\t\tinput_len -= err;\n+\t\t\tinput_offset += err;\n+\t\t}\n \t}\n \n \tif (final_pack_name != curr_pack_name) {\n@@ -863,7 +876,6 @@ int main(int argc, char **argv)\n \t\t\t    nr_deltas - nr_resolved_deltas);\n \t} else {\n \t\t/* Flush remaining pack final 20-byte SHA1. */\n-\t\tuse(20);\n \t\tflush();\n \t}\n \tfree(deltas);\n@@ -872,7 +884,8 @@ int main(int argc, char **argv)\n \tfree(objects);\n \tfree(index_name_buf);\n \n-\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n+\tif (!from_stdin)\n+\t\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n \n \treturn 0;\n }\n-- \n1.4.3.3.g10cf-dirty\n"},{"id":"293833","messageId":"7vmz7jqzoo.fsf@assigned-by-dhcp.cox.net","threadId":"43091","inReplyTo":"Pine.LNX.4.64.0610252330320.12418@xanadu.home","subject":"Re: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-26T07:55:03Z","receivedAt":"2006-10-26T07:55:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Pitre <nico@cam.org> writes:\n\n> It appears that git-unpack-objects writes the last part of the input\n> buffer to stdout after the pack has been parsed.  This looks a bit\n> suspicious since the last fill() might have filled the buffer up to\n> the 4096 byte limit and more data might still be pending on stdin,\n> but since this is about being a drop-in replacement for unpack-objects\n> let's simply duplicate the same behavior for now.\n\nThis seems to break t5300 when applied on top of everything\nelse.  The other two numbered patches are Ok.\n"},{"id":"297330","messageId":"Pine.LNX.4.64.0610260940020.12418@xanadu.home","threadId":"43091","inReplyTo":"7vmz7jqzoo.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/3] mimic unpack-objects when --stdin is used with index-pack","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-10-26T13:46:18Z","receivedAt":"2006-10-26T13:46:18Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Thu, 26 Oct 2006, Junio C Hamano wrote:\n\n> Nicolas Pitre <nico@cam.org> writes:\n> \n> > It appears that git-unpack-objects writes the last part of the input\n> > buffer to stdout after the pack has been parsed.  This looks a bit\n> > suspicious since the last fill() might have filled the buffer up to\n> > the 4096 byte limit and more data might still be pending on stdin,\n> > but since this is about being a drop-in replacement for unpack-objects\n> > let's simply duplicate the same behavior for now.\n> \n> This seems to break t5300 when applied on top of everything\n> else.  The other two numbered patches are Ok.\n\nYeah.... actually the problem appeared to me in my sleep! (Worrisome \nisn't it?)\n\nSo you just need to amend this patch with:\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 7f7dc5d..5c747a6 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -461,7 +461,7 @@ static void parse_pack_objects(unsigned\n \t/* If input_fd is a file, we should have reached its end now. */\n \tif (fstat(input_fd, &st))\n \t\tdie(\"cannot fstat packfile: %s\", strerror(errno));\n-\tif (S_ISREG(st.st_mode) && st.st_size != consumed_bytes + 20)\n+\tif (S_ISREG(st.st_mode) && st.st_size != consumed_bytes)\n \t\tdie(\"pack has junk at the end\");\n \n \tif (!nr_deltas)\n\n\n"}]}