{"thread":{"id":"1725","subject":"[PATCH] Make git-apply understand \"\\ No newline at end of file\" in non-english locales","startedAt":"2005-09-04T17:29:02Z","lastAt":"2005-09-05T05:25:49Z","messageCount":4,"participants":["Fredrik Kuivinen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"8057","messageId":"20050904172901.GA20574@c165.ib.student.liu.se","threadId":"1725","inReplyTo":null,"subject":"[PATCH] Make git-apply understand \"\\ No newline at end of file\" in non-english locales","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-04T17:29:02Z","receivedAt":"2005-09-04T17:29:02Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"The message \"\\ No newline at end of file\" which sometimes is produced by\ndiff(1) is locale dependent. We can't assume more than that it begins\nwith \"\\ \".\n\nSigned-off-by: Fredrik Kuivinen <freku045@student.liu.se>\n---\n\nFor example, given two files, \"foo\" and \"bar\", with appropriate\ncontents 'diff -u foo bar' will produce the following output on my\nsystem.\n\n\n--- foo 2005-09-04 18:59:38.000000000 +0200\n+++ bar 2005-09-04 18:59:16.000000000 +0200\n@@ -1 +1 @@\n-foobar\n+foo\n\\ Ingen nyrad vid filslut\n\n\n apply.c |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\n18d17c911a200c9d45414af403a145c7ac4f9317\ndiff --git a/apply.c b/apply.c\n--- a/apply.c\n+++ b/apply.c\n@@ -672,9 +672,13 @@ static int parse_fragment(char *line, un\n \t\t\tadded++;\n \t\t\tnewlines--;\n \t\t\tbreak;\n-\t\t/* We allow \"\\ No newline at end of file\" */\n+\n+                /* We allow \"\\ No newline at end of file\". Depending\n+                 * on locale settings when the patch was produced we\n+                 * don't know what this line looks like. The only\n+                 * thing we do know is that it begins with \"\\ \". */\n \t\tcase '\\\\':\n-\t\t\tif (len < 12 || memcmp(line, \"\\\\ No newline\", 12))\n+\t\t\tif (len < 12 || memcmp(line, \"\\\\ \", 2))\n \t\t\t\treturn -1;\n \t\t\tbreak;\n \t\t}\n@@ -683,7 +687,7 @@ static int parse_fragment(char *line, un\n \t * it in the above loop because we hit oldlines == newlines == 0\n \t * before seeing it.\n \t */\n-\tif (12 < size && !memcmp(line, \"\\\\ No newline\", 12))\n+\tif (12 < size && !memcmp(line, \"\\\\ \", 2))\n \t\toffset += linelen(line, size);\n \n \tpatch->lines_added += added;\n"},{"id":"8061","messageId":"20050904184625.GB23525@c165.ib.student.liu.se","threadId":"1725","inReplyTo":"20050904172901.GA20574@c165.ib.student.liu.se","subject":"Re: [PATCH] Make git-apply understand \"\\ No newline at end of file\" in non-english locales","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-04T18:46:25Z","receivedAt":"2005-09-04T18:46:25Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"\nThe message \"\\ No newline at end of file\" which sometimes is produced\nby diff(1) is locale dependent. We can't assume more than that it\nbegins with \"\\ \".\n\nSigned-off-by: Fredrik Kuivinen <freku@ida.liu.se>\n---\n\nThe previous patch wasn't doing the right thing. Hopefully I have\nmanaged to get it right this time.\n\n\n apply.c |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\nb94e5e845c241fff14334001aa5d418d22cd115e\ndiff --git a/apply.c b/apply.c\n--- a/apply.c\n+++ b/apply.c\n@@ -672,9 +672,13 @@ static int parse_fragment(char *line, un\n \t\t\tadded++;\n \t\t\tnewlines--;\n \t\t\tbreak;\n-\t\t/* We allow \"\\ No newline at end of file\" */\n+\n+\t\t/* We allow \"\\ No newline at end of file\". Depending\n+\t\t * on locale settings when the patch was produced we\n+\t\t * don't know what this line looks like. The only\n+\t\t * thing we do know is that it begins with \"\\ \". */\n \t\tcase '\\\\':\n-\t\t\tif (len < 12 || memcmp(line, \"\\\\ No newline\", 12))\n+\t\t\tif (len < 2 || line[1] != ' ')\n \t\t\t\treturn -1;\n \t\t\tbreak;\n \t\t}\n@@ -683,7 +687,7 @@ static int parse_fragment(char *line, un\n \t * it in the above loop because we hit oldlines == newlines == 0\n \t * before seeing it.\n \t */\n-\tif (12 < size && !memcmp(line, \"\\\\ No newline\", 12))\n+\tif (2 < size && !memcmp(line, \"\\\\ \", 2))\n \t\toffset += linelen(line, size);\n \n \tpatch->lines_added += added;\n"},{"id":"8064","messageId":"7vd5noeiub.fsf@assigned-by-dhcp.cox.net","threadId":"1725","inReplyTo":"20050904184625.GB23525@c165.ib.student.liu.se","subject":"Re: [PATCH] Make git-apply understand \"\\ No newline at end of file\" in non-english locales","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-04T19:25:16Z","receivedAt":"2005-09-04T19:25:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fredrik Kuivinen <freku045@student.liu.se> writes:\n\n> The message \"\\ No newline at end of file\" which sometimes is produced\n> by diff(1) is locale dependent. We can't assume more than that it\n> begins with \"\\ \".\n>\n> Signed-off-by: Fredrik Kuivinen <freku@ida.liu.se>\n> ---\n>\n> The previous patch wasn't doing the right thing. Hopefully I have\n> managed to get it right this time.\n\nI noticed that you left 12 in the previous patch, and thought it\nwas a sane safety measure to make sure that the incomplete line\nmarker is of reasonably length, not just any line that starts\nwith '\\ ' (i.e. \"\\ foobar\\n\", which is a tad short).\n"},{"id":"8077","messageId":"20050905052549.GA1875@c165.ib.student.liu.se","threadId":"1725","inReplyTo":"7vd5noeiub.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make git-apply understand \"\\ No newline at end of file\" in non-english locales","fromName":"Fredrik Kuivinen","fromEmail":"freku045@student.liu.se","sentAt":"2005-09-05T05:25:49Z","receivedAt":"2005-09-05T05:25:49Z","isPatch":true,"sender":{"key":"frekui@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13770967?v=4"},"body":"On Sun, Sep 04, 2005 at 12:25:16PM -0700, Junio C Hamano wrote:\n> Fredrik Kuivinen <freku045@student.liu.se> writes:\n> \n> > The message \"\\ No newline at end of file\" which sometimes is produced\n> > by diff(1) is locale dependent. We can't assume more than that it\n> > begins with \"\\ \".\n> >\n> > Signed-off-by: Fredrik Kuivinen <freku@ida.liu.se>\n> > ---\n> >\n> > The previous patch wasn't doing the right thing. Hopefully I have\n> > managed to get it right this time.\n> \n> I noticed that you left 12 in the previous patch, and thought it\n> was a sane safety measure to make sure that the incomplete line\n> marker is of reasonably length, not just any line that starts\n> with '\\ ' (i.e. \"\\ foobar\\n\", which is a tad short).\n> \n\nMaybe the first patch wasn't that bad after all :)\n\nIn the current diffutils package the Swedish translation is one of the\nshortest ones, so 12 is ok for now at least.\n\n- Fredrik\n"}]}