use strbuf_complete_line() for adding a newline if needed
Call strbuf_complete_line() instead of open-coding it. Also remove surrounding comments indicating the intent to complete a line since this information is already included in the function name. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 12, 2014 at 20:16 UTC
a0d4923ddfb65c91d2b84ca74eee09424f986a8b
3 files changed
+3
-7
builtin/fmt-merge-msg.c
+1
-2
@@ -216,8 +216,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)
216
strbuf_addf(out, " : %.*s", (int)(ep - bp), bp);
217
bp = ep;
218
}
219
- if (out->buf[out->len - 1] != '\n')
220
- strbuf_addch(out, '\n');
219
+ strbuf_complete_line(out);
220
}
221
strbuf_release(&desc);
222
}
notes-utils.c
+1
-2
@@ -44,8 +44,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
44
45
/* Prepare commit message and reflog message */
46
strbuf_addstr(&buf, msg);
47
- if (buf.buf[buf.len - 1] != '\n')
48
- strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */
47
+ strbuf_complete_line(&buf);
48
49
create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1);
50
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
trace.c
+1
-3
@@ -122,9 +122,7 @@ static int prepare_trace_line(const char *file, int line,
122
123
static void print_trace_line(struct trace_key *key, struct strbuf *buf)
124
{
125
- /* append newline if missing */
126
- if (buf->len && buf->buf[buf->len - 1] != '\n')
127
- strbuf_addch(buf, '\n');
125
+ strbuf_complete_line(buf);
126
127
write_or_whine_pipe(get_trace_fd(key), buf->buf, buf->len, err_msg);
128
strbuf_release(buf);