Skip to content

Commit a0d4923

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fa1365 commit a0d4923

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

builtin/fmt-merge-msg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ static void add_branch_desc(struct strbuf *out, const char *name)
216216
strbuf_addf(out, " : %.*s", (int)(ep - bp), bp);
217217
bp = ep;
218218
}
219-
if (out->buf[out->len - 1] != '\n')
220-
strbuf_addch(out, '\n');
219+
strbuf_complete_line(out);
221220
}
222221
strbuf_release(&desc);
223222
}

notes-utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
4444

4545
/* Prepare commit message and reflog message */
4646
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);
4948

5049
create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1);
5150
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */

trace.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ static int prepare_trace_line(const char *file, int line,
122122

123123
static void print_trace_line(struct trace_key *key, struct strbuf *buf)
124124
{
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);
128126

129127
write_or_whine_pipe(get_trace_fd(key), buf->buf, buf->len, err_msg);
130128
strbuf_release(buf);

0 commit comments

Comments
 (0)