{"thread":{"id":"38173","subject":"[PATCH] use strbuf_complete_line() for adding a newline if needed","startedAt":"2014-12-12T19:16:38Z","lastAt":"2014-12-12T19:16:38Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253646","messageId":"548B3F16.80208@web.de","threadId":"38173","inReplyTo":null,"subject":"[PATCH] use strbuf_complete_line() for adding a newline if needed","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-12-12T19:16:38Z","receivedAt":"2014-12-12T19:16:38Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Call strbuf_complete_line() instead of open-coding it.  Also remove\nsurrounding comments indicating the intent to complete a line since\nthis information is already included in the function name.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/fmt-merge-msg.c | 3 +--\n notes-utils.c           | 3 +--\n trace.c                 | 4 +---\n 3 files changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex 37177c6..af7919e 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -216,8 +216,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)\n \t\t\tstrbuf_addf(out, \"  : %.*s\", (int)(ep - bp), bp);\n \t\t\tbp = ep;\n \t\t}\n-\t\tif (out->buf[out->len - 1] != '\\n')\n-\t\t\tstrbuf_addch(out, '\\n');\n+\t\tstrbuf_complete_line(out);\n \t}\n \tstrbuf_release(&desc);\n }\ndiff --git a/notes-utils.c b/notes-utils.c\nindex b64dc1b..ccbf073 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -44,8 +44,7 @@ void commit_notes(struct notes_tree *t, const char *msg)\n \n \t/* Prepare commit message and reflog message */\n \tstrbuf_addstr(&buf, msg);\n-\tif (buf.buf[buf.len - 1] != '\\n')\n-\t\tstrbuf_addch(&buf, '\\n'); /* Make sure msg ends with newline */\n+\tstrbuf_complete_line(&buf);\n \n \tcreate_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1);\n \tstrbuf_insert(&buf, 0, \"notes: \", 7); /* commit message starts at index 7 */\ndiff --git a/trace.c b/trace.c\nindex 4778608..f6f9f3a 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -122,9 +122,7 @@ static int prepare_trace_line(const char *file, int line,\n \n static void print_trace_line(struct trace_key *key, struct strbuf *buf)\n {\n-\t/* append newline if missing */\n-\tif (buf->len && buf->buf[buf->len - 1] != '\\n')\n-\t\tstrbuf_addch(buf, '\\n');\n+\tstrbuf_complete_line(buf);\n \n \twrite_or_whine_pipe(get_trace_fd(key), buf->buf, buf->len, err_msg);\n \tstrbuf_release(buf);\n-- \n2.2.0\n"}]}