{"thread":{"id":"3875","subject":"Clean up trailing whitespace when pretty-printing commits","startedAt":"2006-04-15T04:20:51Z","lastAt":"2006-04-15T04:20:51Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18676","messageId":"Pine.LNX.4.64.0604142118550.3701@g5.osdl.org","threadId":"3875","inReplyTo":null,"subject":"Clean up trailing whitespace when pretty-printing commits","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-15T04:20:51Z","receivedAt":"2006-04-15T04:20:51Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nPartly because we've messed up and now have some commits with trailing \nwhitespace, but partly because this also just simplifies the code, let's \nremove trailing whitespace from the end when pretty-printing commits.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/commit.c b/commit.c\nindex c7bb8db..ca25574 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -557,16 +557,11 @@ unsigned long pretty_print_commit(enum c\n \t\tif (fmt == CMIT_FMT_ONELINE)\n \t\t\tbreak;\n \t}\n-\tif (fmt == CMIT_FMT_ONELINE) {\n-\t\t/* We do not want the terminating newline */\n-\t\tif (buf[offset - 1] == '\\n')\n-\t\t\toffset--;\n-\t}\n-\telse {\n-\t\t/* Make sure there is an EOLN */\n-\t\tif (buf[offset - 1] != '\\n')\n-\t\t\tbuf[offset++] = '\\n';\n-\t}\n+\twhile (offset && isspace(buf[offset-1]))\n+\t\toffset--;\n+\t/* Make sure there is an EOLN for the non-oneline case */\n+\tif (fmt != CMIT_FMT_ONELINE)\n+\t\tbuf[offset++] = '\\n';\n \tbuf[offset] = '\\0';\n \treturn offset;\n }\n"}]}