{"thread":{"id":"25936","subject":"Problem in Patches with commit-messages containing non-ascii","startedAt":"2010-12-03T11:19:31Z","lastAt":"2010-12-03T19:03:22Z","messageCount":4,"participants":["Martin Krüger","Jan Krüger","Michael J Gruber","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"157201","messageId":"4CF8D243.50108@gmx.com","threadId":"25936","inReplyTo":null,"subject":"Problem in Patches with commit-messages containing non-ascii","fromName":"Martin Krüger","fromEmail":"martin.krueger@gmx.com","sentAt":"2010-12-03T11:19:31Z","receivedAt":"2010-12-03T11:19:31Z","isPatch":false,"sender":{"key":"martin.krueger@gmx.com","avatar":null},"body":"Hello\n\nI stumbled over a problem with git handling patches.\nPerhaps i am then only developer who hast this problem because im am the\nonly developer writing commit-mesages in german.\n\nConsider this log-Message:\ncommit ea2cd63dfe9b3ac3581b6cff8b13a52e69066242\nAuthor: martin <martin@chad.upnx.de>\nDate:   Fri Nov 19 18:58:58 2010 +0100\n\n    Methoden überall angepasst.\n    Ausser Aussnahmen\n\nUsing format-patch the result is:\n\nFrom ea2cd63dfe9b3ac3581b6cff8b13a52e69066242 Mon Sep 17 00:00:00 2001\nFrom: martin <martin@chad.upnx.de>\nDate: Fri, 19 Nov 2010 18:58:58 +0100\nSubject: [PATCH] =?UTF-8?q?Methoden=20=C3=BCberall=20angepasst.\n=20Ausser=20Aussnahmen?=\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nThe content of the subject field ist split up in two lines .\nThe blank in the second line indicates an header-folding according to\nRFC2822 .\nAfter this the string is encoded according to RFC2047 because it\ncontains non-ascii chars. The blank indicatinc the folding ist encoded\ntoo, with =20.\nThat is a Problem because the unfolding according to RFC2822 cant't\ndetect the folding anymore. RFC2822 suggests that the unfolding must be\ndone before any further processing of the header which applies to the\nRFC2047 decoding.\n\nApplying this patch leads to this commit-Message:\n\ncommit 3949e57e4773e85e6c55482b68ade7c409426b3c\nAuthor: martin <martin@chad.upnx.de>\nDate:   Fri Nov 19 18:58:58 2010 +0100\n\n    =?UTF-8?q?Methoden=20=C3=BCberall=20angepasst.\n\n    =20Ausser=20Aussnahmen?=\n    MIME-Version: 1.0\n    Content-Type: text/plain; charset=UTF-8\n    Content-Transfer-Encoding: 8bit\n\nThe solution is to make an exception not to encode blanks indicating a\nfolding.\n\nI wrote this patch:\n\ndiff --git a/pretty.c b/pretty.c\nindex f85444b..8a78a4e 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -216,7 +216,7 @@ static int is_rfc2047_special(char ch)\n static void add_rfc2047(struct strbuf *sb, const char *line, int len,\n \t\t       const char *encoding)\n {\n-\tint i, last;\n+\tint i, last, num_foldings;\n\n \tfor (i = 0; i < len; i++) {\n \t\tint ch = line[i];\n@@ -229,8 +229,14 @@ static void add_rfc2047(struct strbuf *sb, const\nchar *line, int len,\n \treturn;\n\n needquote:\n-\tstrbuf_grow(sb, len * 3 + strlen(encoding) + 100);\n+        num_foldings=0;\n+        for (i = 1; i < len; i++)\n+          if(line[i]==' '&&line[i]=='\\n')\n+           num_foldings++;\n+\n+\tstrbuf_grow(sb, len * 3 + num_foldings*(7+strlen(encoding)) + 100);\n \tstrbuf_addf(sb, \"=?%s?q?\", encoding);\n+        unsigned last_ch=0;\n \tfor (i = last = 0; i < len; i++) {\n \t\tunsigned ch = line[i] & 0xFF;\n \t\t/*\n@@ -240,10 +246,19 @@ needquote:\n \t\t * leave the underscore in place.\n \t\t */\n \t\tif (is_rfc2047_special(ch) || ch == ' ') {\n-\t\t\tstrbuf_add(sb, line + last, i - last);\n-\t\t\tstrbuf_addf(sb, \"=%02X\", ch);\n-\t\t\tlast = i + 1;\n+                    if(!(ch == ' '&& last_ch=='\\n')){\n+                        strbuf_add(sb, line + last, i - last);\n+\t\t\tstrbuf_addf(sb, \"=%02X\", ch);\n+                    }\n+                    else{\n+                     if(i>last+1)\n+                      strbuf_add(sb, line + last, i - last-1);\n+                     strbuf_addstr(sb, \"?=\\n \");\n+                     strbuf_addf(sb, \"=?%s?q?\", encoding);\n+                    }\n+                  last = i + 1;\n \t\t}\n+           last_ch=ch;\n \t}\n \tstrbuf_add(sb, line + last, len - last);\n \tstrbuf_addstr(sb, \"?=\");\n\n\n\nThen git generates this patch:\n\nFrom ea2cd63dfe9b3ac3581b6cff8b13a52e69066242 Mon Sep 17 00:00:00 2001\nFrom: martin <martin@chad.upnx.de>\nDate: Fri, 19 Nov 2010 18:58:58 +0100\nSubject: [PATCH] =?UTF-8?q?Methoden=20=C3=BCberall=20angepasst.?=\n =?UTF-8?q?Ausser=20Aussnahmen?=\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n\nApplyin leads to a correct commit-Messsage:\n\ncommit 62d06e3415ec0726dbd58c11ed93771502b77805\nAuthor: martin <martin@chad.upnx.de>\nDate:   Fri Nov 19 18:58:58 2010 +0100\n\n    Methoden überall angepasst.Ausser Aussnahmen\n\n\nBest regards\n   martin\n"},{"id":"157203","messageId":"20101203135944.31d7cfbf@jk.gs","threadId":"25936","inReplyTo":"4CF8D243.50108@gmx.com","subject":"Re: Problem in Patches with commit-messages containing non-ascii","fromName":"Jan Krüger","fromEmail":"jk@jk.gs","sentAt":"2010-12-03T12:59:44Z","receivedAt":"2010-12-03T12:59:44Z","isPatch":false,"sender":{"key":"jk@jk.gs","avatar":"https://avatars.githubusercontent.com/u/1774?v=4"},"body":"--- Martin Krüger <martin.krueger@gmx.com> wrote:\n\n> Consider this log-Message:\n> commit ea2cd63dfe9b3ac3581b6cff8b13a52e69066242\n> Author: martin <martin@chad.upnx.de>\n> Date:   Fri Nov 19 18:58:58 2010 +0100\n> \n>     Methoden überall angepasst.\n>     Ausser Aussnahmen\n> \n\nFWIW, support for multi-line summaries is very limited. Several\ntools assume that the log message has this format:\n\n<Summary in one line>\n<Blank line>\n<Details>\n\nSo one could argue that your patch fixes something that isn't really\nsupported anyway.\n\n> [...]\n> \n> Applyin leads to a correct commit-Messsage:\n> \n> commit 62d06e3415ec0726dbd58c11ed93771502b77805\n> Author: martin <martin@chad.upnx.de>\n> Date:   Fri Nov 19 18:58:58 2010 +0100\n> \n>     Methoden überall angepasst.Ausser Aussnahmen\n\nHow is that correct? It's different from the original commit message.\n\n-Jan\n"},{"id":"157206","messageId":"4CF8EBC4.7060107@drmicha.warpmail.net","threadId":"25936","inReplyTo":"20101203135944.31d7cfbf@jk.gs","subject":"Re: Problem in Patches with commit-messages containing non-ascii","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-12-03T13:08:20Z","receivedAt":"2010-12-03T13:08:20Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jan Krüger venit, vidit, dixit 03.12.2010 13:59:\n> --- Martin Krüger <martin.krueger@gmx.com> wrote:\n> \n>> Consider this log-Message:\n>> commit ea2cd63dfe9b3ac3581b6cff8b13a52e69066242\n>> Author: martin <martin@chad.upnx.de>\n>> Date:   Fri Nov 19 18:58:58 2010 +0100\n>>\n>>     Methoden überall angepasst.\n>>     Ausser Aussnahmen\n>>\n> \n> FWIW, support for multi-line summaries is very limited. Several\n> tools assume that the log message has this format:\n> \n> <Summary in one line>\n> <Blank line>\n> <Details>\n> \n> So one could argue that your patch fixes something that isn't really\n> supported anyway.\n> \n>> [...]\n>>\n>> Applyin leads to a correct commit-Messsage:\n>>\n>> commit 62d06e3415ec0726dbd58c11ed93771502b77805\n>> Author: martin <martin@chad.upnx.de>\n>> Date:   Fri Nov 19 18:58:58 2010 +0100\n>>\n>>     Methoden überall angepasst.Ausser Aussnahmen\n> \n> How is that correct? It's different from the original commit message.\n> \n> -Jan\n\nAlso, it is \"Außer Ausnahmen\" even after the latest spelling reform ;)\n\nMichael\n"},{"id":"157236","messageId":"m2r5dyd6h1.fsf@igel.home","threadId":"25936","inReplyTo":"4CF8D243.50108@gmx.com","subject":"Re: Problem in Patches with commit-messages containing non-ascii","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2010-12-03T19:03:22Z","receivedAt":"2010-12-03T19:03:22Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Martin Krüger <martin.krueger@gmx.com> writes:\n\n> Then git generates this patch:\n>\n> From ea2cd63dfe9b3ac3581b6cff8b13a52e69066242 Mon Sep 17 00:00:00 2001\n> From: martin <martin@chad.upnx.de>\n> Date: Fri, 19 Nov 2010 18:58:58 +0100\n> Subject: [PATCH] =?UTF-8?q?Methoden=20=C3=BCberall=20angepasst.?=\n>  =?UTF-8?q?Ausser=20Aussnahmen?=\n> MIME-Version: 1.0\n> Content-Type: text/plain; charset=UTF-8\n> Content-Transfer-Encoding: 8bit\n>\n> Applyin leads to a correct commit-Messsage:\n>\n> commit 62d06e3415ec0726dbd58c11ed93771502b77805\n> Author: martin <martin@chad.upnx.de>\n> Date:   Fri Nov 19 18:58:58 2010 +0100\n>\n>     Methoden überall angepasst.Ausser Aussnahmen\n\nThat's at least missing a space after the period.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"}]}