{"thread":{"id":"11244","subject":"'git fast-export' is crashing on the gcc repo","startedAt":"2007-12-11T20:27:33Z","lastAt":"2007-12-12T08:56:35Z","messageCount":10,"participants":["Nicolas Pitre","Marco Costalba","Alex Riesen","Junio C Hamano","David Kastrup"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"62793","messageId":"alpine.LFD.0.99999.0712111509270.555@xanadu.home","threadId":"11244","inReplyTo":null,"subject":"'git fast-export' is crashing on the gcc repo","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-12-11T20:27:33Z","receivedAt":"2007-12-11T20:27:33Z","isPatch":false,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"Simply doing something like:\n\n$ git fast-export --all > /dev/null\n\nresults in:\n\nfatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n\nSince this is extremely enlightening, I patched it as follows:\n\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 2136aad..5c7bfe0 100755\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -104,7 +104,8 @@ static void handle_object(const unsigned char *sha1)\n \n \tprintf(\"blob\\nmark :%d\\ndata %lu\\n\", last_idnum, size);\n \tif (fwrite(buf, size, 1, stdout) != 1)\n-\t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n+\t\tdie (\"Could not write blob %s: %s\",\n+\t\t     sha1_to_hex(sha1), strerror(errno));\n \tprintf(\"\\n\");\n \n \tshow_progress();\n\nAnd then running it again produced:\n\nfatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391: Inappropriate ioctl for device\n\nadding to today's confusion.\n\n\nNicolas\n"},{"id":"62797","messageId":"e5bfff550712111235q10177d9bif314580127a56d67@mail.gmail.com","threadId":"11244","inReplyTo":"alpine.LFD.0.99999.0712111509270.555@xanadu.home","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Marco Costalba","fromEmail":"mcostalba@gmail.com","sentAt":"2007-12-11T20:35:04Z","receivedAt":"2007-12-11T20:35:04Z","isPatch":false,"sender":{"key":"mcostalba@gmail.com","avatar":null},"body":"On Dec 11, 2007 9:27 PM, Nicolas Pitre <nico@cam.org> wrote:\n>\n> And then running it again produced:\n>\n> fatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391: Inappropriate ioctl for device\n>\n> adding to today's confusion.\n>\n\nGCC repo is turning out to be a very good test case indeed ;-)\n"},{"id":"62816","messageId":"20071211220128.GA19857@steel.home","threadId":"11244","inReplyTo":"alpine.LFD.0.99999.0712111509270.555@xanadu.home","subject":"[PATCH] Fix git-fast-export for zero-sized blobs","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-11T22:01:28Z","receivedAt":"2007-12-11T22:01:28Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n builtin-fast-export.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\nNicolas Pitre, Tue, Dec 11, 2007 21:27:33 +0100:\n> Simply doing something like:\n> \n> $ git fast-export --all > /dev/null\n> \n> results in:\n> \n> fatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> \n\nI get this for my git repo:\n\n\t$ git fast-export --all >/dev/null\n\tfatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n\t$ git cat-file blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 |wc -c\n\t0\n\nWriting a zero-size blob will surely returns 0.\n\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 2136aad..ef27eee 100755\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -103,7 +103,7 @@ static void handle_object(const unsigned char *sha1)\n \tmark_object(object);\n \n \tprintf(\"blob\\nmark :%d\\ndata %lu\\n\", last_idnum, size);\n-\tif (fwrite(buf, size, 1, stdout) != 1)\n+\tif (size && fwrite(buf, size, 1, stdout) != 1)\n \t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n \tprintf(\"\\n\");\n \n-- \n1.5.3.7.1177.gb22b\n"},{"id":"62817","messageId":"alpine.LFD.0.99999.0712111703380.555@xanadu.home","threadId":"11244","inReplyTo":"alpine.LFD.0.99999.0712111509270.555@xanadu.home","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-12-11T22:06:42Z","receivedAt":"2007-12-11T22:06:42Z","isPatch":false,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Tue, 11 Dec 2007, Nicolas Pitre wrote:\n\n> Simply doing something like:\n> \n> $ git fast-export --all > /dev/null\n> \n> results in:\n> \n> fatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> \n> Since this is extremely enlightening, I patched it as follows:\n> \n> diff --git a/builtin-fast-export.c b/builtin-fast-export.c\n> index 2136aad..5c7bfe0 100755\n> --- a/builtin-fast-export.c\n> +++ b/builtin-fast-export.c\n> @@ -104,7 +104,8 @@ static void handle_object(const unsigned char *sha1)\n>  \n>  \tprintf(\"blob\\nmark :%d\\ndata %lu\\n\", last_idnum, size);\n>  \tif (fwrite(buf, size, 1, stdout) != 1)\n> -\t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n> +\t\tdie (\"Could not write blob %s: %s\",\n> +\t\t     sha1_to_hex(sha1), strerror(errno));\n>  \tprintf(\"\\n\");\n>  \n>  \tshow_progress();\n> \n> And then running it again produced:\n> \n> fatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391: Inappropriate ioctl for device\n> \n> adding to today's confusion.\n\nWell, ignore the above.  It seems that most of stdio doesn't set errno \nso the above is crap.\n\nEven strace doesn't show any error.\n\nBut, somehow, the following patch fixes it:\n\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 2136aad..c32a124 100755\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -103,7 +103,7 @@ static void handle_object(const unsigned char *sha1)\n \tmark_object(object);\n \n \tprintf(\"blob\\nmark :%d\\ndata %lu\\n\", last_idnum, size);\n-\tif (fwrite(buf, size, 1, stdout) != 1)\n+\tif (fwrite(buf, 1, size, stdout) != size)\n \t\tdie (\"Could not write blob %s\", sha1_to_hex(sha1));\n \tprintf(\"\\n\");\n \n\nGo figure.\n\n\nNicolas\n"},{"id":"62818","messageId":"alpine.LFD.0.99999.0712111719380.555@xanadu.home","threadId":"11244","inReplyTo":"20071211220128.GA19857@steel.home","subject":"Re: [PATCH] Fix git-fast-export for zero-sized blobs","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-12-11T22:20:38Z","receivedAt":"2007-12-11T22:20:38Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Tue, 11 Dec 2007, Alex Riesen wrote:\n\n> Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n> ---\n>  builtin-fast-export.c |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n> \n> Nicolas Pitre, Tue, Dec 11, 2007 21:27:33 +0100:\n> > Simply doing something like:\n> > \n> > $ git fast-export --all > /dev/null\n> > \n> > results in:\n> > \n> > fatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> > \n> \n> I get this for my git repo:\n> \n> \t$ git fast-export --all >/dev/null\n> \tfatal: Could not write blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> \t$ git cat-file blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 |wc -c\n> \t0\n> \n> Writing a zero-size blob will surely returns 0.\n\nIndeed.\n\n\n/me looking at too many piece of code at the same time\n\n\nNicolas\n"},{"id":"62842","messageId":"20071212013828.GC19857@steel.home","threadId":"11244","inReplyTo":"alpine.LFD.0.99999.0712111703380.555@xanadu.home","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-12T01:38:28Z","receivedAt":"2007-12-12T01:38:28Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Nicolas Pitre, Tue, Dec 11, 2007 23:06:42 +0100:\n> \n> Well, ignore the above.  It seems that most of stdio doesn't set errno \n> so the above is crap.\n> \n\nWell, it had no reason to in this case. It's not an error.\nIt does not even have to do a syscall.\n\n> diff --git a/builtin-fast-export.c b/builtin-fast-export.c\n> index 2136aad..c32a124 100755\n> --- a/builtin-fast-export.c\n> +++ b/builtin-fast-export.c\n> @@ -103,7 +103,7 @@ static void handle_object(const unsigned char *sha1)\n>  \tmark_object(object);\n>  \n>  \tprintf(\"blob\\nmark :%d\\ndata %lu\\n\", last_idnum, size);\n> -\tif (fwrite(buf, size, 1, stdout) != 1)\n> +\tif (fwrite(buf, 1, size, stdout) != size)\n\nThat's a probable syscall which could be spared\n"},{"id":"62843","messageId":"alpine.LFD.0.99999.0712112045040.555@xanadu.home","threadId":"11244","inReplyTo":"20071212013828.GC19857@steel.home","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-12-12T01:45:40Z","receivedAt":"2007-12-12T01:45:40Z","isPatch":false,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Wed, 12 Dec 2007, Alex Riesen wrote:\n\n> Nicolas Pitre, Tue, Dec 11, 2007 23:06:42 +0100:\n> > \n> > Well, ignore the above.  It seems that most of stdio doesn't set errno \n> > so the above is crap.\n> > \n> \n> Well, it had no reason to in this case. It's not an error.\n> It does not even have to do a syscall.\n\nWhich is why I later agreed with your patch.\n\n\nNicolas\n"},{"id":"62874","messageId":"7v3au89utj.fsf@gitster.siamese.dyndns.org","threadId":"11244","inReplyTo":"alpine.LFD.0.99999.0712112045040.555@xanadu.home","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-12T08:32:56Z","receivedAt":"2007-12-12T08:32:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Pitre <nico@cam.org> writes:\n\n> On Wed, 12 Dec 2007, Alex Riesen wrote:\n>\n>> Nicolas Pitre, Tue, Dec 11, 2007 23:06:42 +0100:\n>> > \n>> > Well, ignore the above.  It seems that most of stdio doesn't set errno \n>> > so the above is crap.\n>> > \n>> \n>> Well, it had no reason to in this case. It's not an error.\n>> It does not even have to do a syscall.\n>\n> Which is why I later agreed with your patch.\n\nStill, I like your swapping of size and nmemb parameters, regardless of\nthe \"don't bother calling fwrite(3) if size is zero\" fix.\n\nWe are writing 1 element of size n-byte and expecting the call to return\n1.  It may be argued that writing one element of size 0-byte should\nalways write 1 element (without actually having to go down to write(2),\nobviously) successfully and returning 0 from fwrite(3) is a bug ;-)\n\nNo, I am just kidding.  I checked with POSIX and it clearly says it\nshould return 0 if size or nmemb is zero.\n"},{"id":"62875","messageId":"854peo8fm5.fsf@lola.goethe.zz","threadId":"11244","inReplyTo":"7v3au89utj.fsf@gitster.siamese.dyndns.org","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-12-12T08:46:42Z","receivedAt":"2007-12-12T08:46:42Z","isPatch":false,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Nicolas Pitre <nico@cam.org> writes:\n>\n>> On Wed, 12 Dec 2007, Alex Riesen wrote:\n>>\n>>> Nicolas Pitre, Tue, Dec 11, 2007 23:06:42 +0100:\n>>> > \n>>> > Well, ignore the above.  It seems that most of stdio doesn't set errno \n>>> > so the above is crap.\n>>> > \n>>> \n>>> Well, it had no reason to in this case. It's not an error.\n>>> It does not even have to do a syscall.\n>>\n>> Which is why I later agreed with your patch.\n>\n> Still, I like your swapping of size and nmemb parameters, regardless\n> of the \"don't bother calling fwrite(3) if size is zero\" fix.\n\nI don't.  Far too obscure, looks like an unintentional wart waiting to\nbe corrected.\n\nI think that the explicit test is the way to go here.\n\n-- \nDavid Kastrup, Kriemhildstr. 15, 44793 Bochum\n"},{"id":"62876","messageId":"7vy7c08f5o.fsf@gitster.siamese.dyndns.org","threadId":"11244","inReplyTo":"854peo8fm5.fsf@lola.goethe.zz","subject":"Re: 'git fast-export' is crashing on the gcc repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-12T08:56:35Z","receivedAt":"2007-12-12T08:56:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Kastrup <dak@gnu.org> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> ...\n>> Still, I like your swapping of size and nmemb parameters, regardless\n>> of the \"don't bother calling fwrite(3) if size is zero\" fix.\n>\n> I don't.  Far too obscure, looks like an unintentional wart waiting to\n> be corrected.\n\nOh, I did not mean it in the sense that would be a bugfix, but in the\nsense that we are writing N instances of 1 byte, not 1 instance of N\nbyte blob, and should express size and nmemb parameters to fwrite(3) as\nsuch.  IOW, I would have preferred:\n\n\tif (size && fwrite(buf, 1, size, stdout) != size)\n        \tbarf(...);\n"}]}