{"thread":{"id":"24775","subject":"BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","startedAt":"2010-08-17T23:27:27Z","lastAt":"2010-08-18T09:15:31Z","messageCount":5,"participants":["Tor Arvid Lund","Jonathan Nieder","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"148316","messageId":"AANLkTineHiG9vCpbJzJ2x9CFjZ7LQeExs7cN5YhoZhft@mail.gmail.com","threadId":"24775","inReplyTo":null,"subject":"BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-08-17T23:27:27Z","receivedAt":"2010-08-17T23:27:27Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"Hi.\n\nI often use git-gui when staging commits, and I noticed that if the\nfile I'm working with has a:\n\n\\ No newline at end of file\n\n... as the last line of the diff, and I try to \"Stage lines for\ncommit\", then git-gui (or really git-apply, as I understand it) says\nthat I have a \"corrupt patch at line <so-and-so>\".\n\nI don't really know the git-gui code or the git C code well, but it\nseems that I got around the error with this small patch:\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 12ef9ea..124791f 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1335,6 +1335,8 @@ static int parse_fragment(char *line, unsigned long size,\n \t\t * l10n of \"\\ No newline...\" is at least that long.\n \t\t */\n \t\tcase '\\\\':\n+\t\t\tif (newlines == oldlines == 1)\n+\t\t\t\tnewlines = oldlines = 0;\n \t\t\tif (len < 12 || memcmp(line, \"\\\\ \", 2))\n \t\t\t\treturn -1;\n \t\t\tbreak;\n\n\n\n\nIs this a bug? Or is it maybe git-gui that sends something wrong to\ngit-apply? I don't know... :-/\n\n(I'm using msysGit on Windows, if that matters)\n\n-Tor Arvid-\n"},{"id":"148320","messageId":"20100817234314.GK2221@burratino","threadId":"24775","inReplyTo":"AANLkTineHiG9vCpbJzJ2x9CFjZ7LQeExs7cN5YhoZhft@mail.gmail.com","subject":"Re: BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-17T23:43:14Z","receivedAt":"2010-08-17T23:43:14Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Tor Arvid Lund wrote:\n\n> I don't really know the git-gui code or the git C code well, but it\n> seems that I got around the error with this small patch:\n> \n> diff --git a/builtin/apply.c b/builtin/apply.c\n> index 12ef9ea..124791f 100644\n> --- a/builtin/apply.c\n> +++ b/builtin/apply.c\n> @@ -1335,6 +1335,8 @@ static int parse_fragment(char *line, unsigned long size,\n>  \t\t * l10n of \"\\ No newline...\" is at least that long.\n>  \t\t */\n>  \t\tcase '\\\\':\n> +\t\t\tif (newlines == oldlines == 1)\n[...]\n\nHeh.  This code is a roundabout way to say \"if (newlines == oldlines)\",\nrather than \"if (newlines == 1 && oldlines == 1)\" that might have been\nintended.\n\nUnfortunately I do not have any more insight than that.  If you can\ngive an example reproducing this with git apply from the command\nline, that would be very helpful.\n\nThanks,\nJonathan\n"},{"id":"148329","messageId":"AANLkTi=mJdufWiKDQBSA6EVpb6Qj3GfGPKZL4pJGdKYu@mail.gmail.com","threadId":"24775","inReplyTo":"20100817234314.GK2221@burratino","subject":"Re: BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-08-18T01:37:34Z","receivedAt":"2010-08-18T01:37:34Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Wed, Aug 18, 2010 at 1:43 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Tor Arvid Lund wrote:\n>\n>> I don't really know the git-gui code or the git C code well, but it\n>> seems that I got around the error with this small patch:\n>>\n>> diff --git a/builtin/apply.c b/builtin/apply.c\n>> index 12ef9ea..124791f 100644\n>> --- a/builtin/apply.c\n>> +++ b/builtin/apply.c\n>> @@ -1335,6 +1335,8 @@ static int parse_fragment(char *line, unsigned long size,\n>>                * l10n of \"\\ No newline...\" is at least that long.\n>>                */\n>>               case '\\\\':\n>> +                     if (newlines == oldlines == 1)\n> [...]\n>\n> Heh.  This code is a roundabout way to say \"if (newlines == oldlines)\",\n> rather than \"if (newlines == 1 && oldlines == 1)\" that might have been\n> intended.\n\nRight you are, good sir ;-)\n\n> Unfortunately I do not have any more insight than that.  If you can\n> give an example reproducing this with git apply from the command\n> line, that would be very helpful.\n\nI'll try to do that tomorrow.. My brain needs sleep before it will function :)\n\n-Tor Arvid-\n"},{"id":"148341","messageId":"4C6B8BC8.9050301@viscovery.net","threadId":"24775","inReplyTo":"AANLkTineHiG9vCpbJzJ2x9CFjZ7LQeExs7cN5YhoZhft@mail.gmail.com","subject":"Re: BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-08-18T07:29:12Z","receivedAt":"2010-08-18T07:29:12Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 8/18/2010 1:27, schrieb Tor Arvid Lund:\n> I often use git-gui when staging commits, and I noticed that if the\n> file I'm working with has a:\n> \n> \\ No newline at end of file\n> \n> ... as the last line of the diff, and I try to \"Stage lines for\n> commit\", then git-gui (or really git-apply, as I understand it) says\n> that I have a \"corrupt patch at line <so-and-so>\".\n> \n> Is this a bug? Or is it maybe git-gui that sends something wrong to\n> git-apply? I don't know... :-/\n\nThis is really a bug in git-gui, not in git-apply: The big while loop in\nlib/diff.tcl, function apply_range_or_line, must be taught about \"\\ No\nnewline...\".\n\n-- Hannes\n"},{"id":"148348","messageId":"AANLkTimSnKxMpYZ263muV4nE-ppfWXfpM6SEo4HKAB66@mail.gmail.com","threadId":"24775","inReplyTo":"4C6B8BC8.9050301@viscovery.net","subject":"Re: BUG?: git-apply sometimes says \"corrupt patch\" when adding single lines","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-08-18T09:15:31Z","receivedAt":"2010-08-18T09:15:31Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Wed, Aug 18, 2010 at 9:29 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Am 8/18/2010 1:27, schrieb Tor Arvid Lund:\n>> I often use git-gui when staging commits, and I noticed that if the\n>> file I'm working with has a:\n>>\n>> \\ No newline at end of file\n>>\n>> ... as the last line of the diff, and I try to \"Stage lines for\n>> commit\", then git-gui (or really git-apply, as I understand it) says\n>> that I have a \"corrupt patch at line <so-and-so>\".\n>>\n>> Is this a bug? Or is it maybe git-gui that sends something wrong to\n>> git-apply? I don't know... :-/\n>\n> This is really a bug in git-gui, not in git-apply: The big while loop in\n> lib/diff.tcl, function apply_range_or_line, must be taught about \"\\ No\n> newline...\".\n\nOk, thanks for tracking it down. I suspected this, since the tests for\ngit-apply seemed to have example patches for \"\\ No newline...\".\nUltimately, this doesn't scratch me enough that I want to learn (or\nguess) how to fix the Tcl stuff...\n\n-Tor Arvid-\n"}]}