{"thread":{"id":"3086","subject":"git-mailinfo: cut lines at ^M","startedAt":"2006-01-16T19:13:15Z","lastAt":"2006-01-16T23:49:35Z","messageCount":3,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"14741","messageId":"Pine.LNX.4.64.0601161104070.13339@g5.osdl.org","threadId":"3086","inReplyTo":null,"subject":"git-mailinfo: cut lines at ^M","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-16T19:13:15Z","receivedAt":"2006-01-16T19:13:15Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis changes \"eatspace()\" to cut lines at the first ^M (\\r, CR) character.\n\nNormally it should make no difference at all, since even if you have a \nnon-UNIX CR/LF end-of-line, it would have removed the ^M at the end of the \nline as whitespace.\n\nThe main reason for this patch is that I seem to have something buggy in \nmy mail path (possibly fetchmail) which very occasionally causes the mail \nheaders to have an appended \"^M)\" line. This silly thing works around it, \nand shouldn't hurt anything else.\n\nThe alternative would be to simply disallow control characters in the \ncommit message (so that I would not commit these things by mistake).\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nJunio, feel free to ignore this. It shouldn't hurt, but admittedly it's a \nstupid hack for a problem that has nothing to do with git. The \"disallow \ncontrol characters\" fix is probably better, if you prefer that I can do it \nthat way instead.\n\n\t\tLinus\n\ndiff --git a/mailinfo.c b/mailinfo.c\nindex 0265a29..e1c95a9 100644\n--- a/mailinfo.c\n+++ b/mailinfo.c\n@@ -226,9 +226,19 @@ static int is_multipart_boundary(const c\n \n static int eatspace(char *line)\n {\n-\tint len = strlen(line);\n-\twhile (len > 0 && isspace(line[len-1]))\n-\t\tline[--len] = 0;\n+\tint len, idx;\n+\n+\tlen = idx = 0;\n+\tfor (;;) {\n+\t\tunsigned char c = line[idx++];\n+\t\tif (isspace(c)) {\n+\t\t\tif (c == '\\n' || c == '\\r')\n+\t\t\t\tbreak;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tlen = idx;\n+\t}\n+\tline[len] = 0;\n \treturn len;\n }\n \n"},{"id":"14753","messageId":"7v1wz7n3oz.fsf@assigned-by-dhcp.cox.net","threadId":"3086","inReplyTo":"Pine.LNX.4.64.0601161104070.13339@g5.osdl.org","subject":"Re: git-mailinfo: cut lines at ^M","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-16T23:38:52Z","receivedAt":"2006-01-16T23:38:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Junio, feel free to ignore this. It shouldn't hurt, but\n> admittedly it's a stupid hack for a problem that has nothing\n> to do with git...\n\nThis is doing \"instead of removing trailing spaces, terminate a\nline at the first CR or LF and discard the rest\".  So your \"^M)\"\nat the end, especially the close paren, is dropped.\n\nI've briefly wondered if a better alternative is to split lines\nat \"\\r\\n\", \"\\n\", or \"\\r\", which would make the next line begin\nwith \")\" in your example.  Normally the first two would have\nalready been done by fgets(), so the alternative approach would\ninvolve wrapping the use of fgets() with something of our own.\nI do not think \"keeping the rest of the line after '\\r' in the\nmiddle\" is worth that trouble, so I am personally fine with your\npatch.\n"},{"id":"14755","messageId":"Pine.LNX.4.64.0601161548560.13339@g5.osdl.org","threadId":"3086","inReplyTo":"7v1wz7n3oz.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-mailinfo: cut lines at ^M","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-01-16T23:49:35Z","receivedAt":"2006-01-16T23:49:35Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 16 Jan 2006, Junio C Hamano wrote:\n> \n> I've briefly wondered if a better alternative is to split lines\n> at \"\\r\\n\", \"\\n\", or \"\\r\", which would make the next line begin\n> with \")\" in your example.\n\nIn which case the patch does nothing good for me. I want to either drop \nthe bogus line, or have applymbox refuse to apply such an email..\n\n\t\tLinus\n"}]}