Skip to content

Commit 19e27e2

Browse files
committed
strbuf: retire strbuf_commented_lines()
The API allows the caller to pass any string as the comment prefix, but in reality, everybody passes the comment_line_str from the environment. Replace this overly flexible API with strbuf_comment_lines() that does not allow customization of the comment_line_str (usually '#' but can be configured via the core.commentChar). Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3582c0 commit 19e27e2

File tree

8 files changed

+28
-37
lines changed

8 files changed

+28
-37
lines changed

builtin/notes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void write_commented_object(int fd, const struct object_id *object)
178178

179179
if (strbuf_read(&buf, show.out, 0) < 0)
180180
die_errno(_("could not read 'show' output"));
181-
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
181+
strbuf_add_comment_lines(&cbuf, buf.buf, buf.len);
182182
write_or_die(fd, cbuf.buf, cbuf.len);
183183

184184
strbuf_release(&cbuf);
@@ -206,10 +206,10 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
206206
copy_obj_to_fd(fd, old_note);
207207

208208
strbuf_addch(&buf, '\n');
209-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
210-
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
211-
comment_line_str);
212-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
209+
strbuf_add_comment_lines(&buf, "\n", strlen("\n"));
210+
strbuf_add_comment_lines(&buf, _(note_template),
211+
strlen(_(note_template)));
212+
strbuf_add_comment_lines(&buf, "\n", strlen("\n"));
213213
write_or_die(fd, buf.buf, buf.len);
214214

215215
write_commented_object(fd, object);

builtin/stripspace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static void comment_lines(struct strbuf *buf)
1313
size_t len;
1414

1515
msg = strbuf_detach(buf, &len);
16-
strbuf_add_commented_lines(buf, msg, len, comment_line_str);
16+
strbuf_add_comment_lines(buf, msg, len);
1717
free(msg);
1818
}
1919

fmt-merge-msg.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
511511
strbuf_complete_line(tagbuf);
512512
if (sig->len) {
513513
strbuf_addch(tagbuf, '\n');
514-
strbuf_add_commented_lines(tagbuf, sig->buf, sig->len,
515-
comment_line_str);
514+
strbuf_add_comment_lines(tagbuf, sig->buf, sig->len);
516515
}
517516
}
518517

@@ -556,19 +555,17 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
556555
if (tag_number == 2) {
557556
struct strbuf tagline = STRBUF_INIT;
558557
strbuf_addch(&tagline, '\n');
559-
strbuf_add_commented_lines(&tagline,
560-
origins.items[first_tag].string,
561-
strlen(origins.items[first_tag].string),
562-
comment_line_str);
558+
strbuf_add_comment_lines(&tagline,
559+
origins.items[first_tag].string,
560+
strlen(origins.items[first_tag].string));
563561
strbuf_insert(&tagbuf, 0, tagline.buf,
564562
tagline.len);
565563
strbuf_release(&tagline);
566564
}
567565
strbuf_addch(&tagbuf, '\n');
568-
strbuf_add_commented_lines(&tagbuf,
569-
origins.items[i].string,
570-
strlen(origins.items[i].string),
571-
comment_line_str);
566+
strbuf_add_comment_lines(&tagbuf,
567+
origins.items[i].string,
568+
strlen(origins.items[i].string));
572569
fmt_tag_signature(&tagbuf, &sig, buf, len);
573570
}
574571
strbuf_release(&payload);

rebase-interactive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void append_todo_help(int command_count,
8080
shortrevisions, shortonto, command_count);
8181
}
8282

83-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
83+
strbuf_add_comment_lines(buf, msg, strlen(msg));
8484

8585
if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR)
8686
msg = _("\nDo not remove any line. Use 'drop' "
@@ -89,7 +89,7 @@ void append_todo_help(int command_count,
8989
msg = _("\nIf you remove a line here "
9090
"THAT COMMIT WILL BE LOST.\n");
9191

92-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
92+
strbuf_add_comment_lines(buf, msg, strlen(msg));
9393

9494
if (edit_todo)
9595
msg = _("\nYou are editing the todo file "
@@ -100,7 +100,7 @@ void append_todo_help(int command_count,
100100
msg = _("\nHowever, if you remove everything, "
101101
"the rebase will be aborted.\n\n");
102102

103-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
103+
strbuf_add_comment_lines(buf, msg, strlen(msg));
104104
}
105105

106106
int edit_todo_list(struct repository *r, struct replay_opts *opts,

sequencer.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ static int is_fixup_flag(enum todo_command command, unsigned flag)
19111911
}
19121912

19131913
/*
1914-
* Wrapper around strbuf_add_commented_lines() which avoids double
1914+
* Wrapper around strbuf_add_comment_lines() which avoids double
19151915
* commenting commit subjects.
19161916
*/
19171917
static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
@@ -1928,7 +1928,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
19281928
s += count;
19291929
len -= count;
19301930
}
1931-
strbuf_add_commented_lines(buf, s, len, comment_line_str);
1931+
strbuf_add_comment_lines(buf, s, len);
19321932
}
19331933

19341934
/* Does the current fixup chain contain a squash command? */
@@ -2028,7 +2028,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
20282028
strbuf_addf(buf, _(nth_commit_msg_fmt),
20292029
++ctx->current_fixup_count + 1);
20302030
strbuf_addstr(buf, "\n\n");
2031-
strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
2031+
strbuf_add_comment_lines(buf, body, commented_len);
20322032
/* buf->buf may be reallocated so store an offset into the buffer */
20332033
fixup_off = buf->len;
20342034
strbuf_addstr(buf, body + commented_len);
@@ -2119,8 +2119,7 @@ static int update_squash_messages(struct repository *r,
21192119
_(first_commit_msg_str));
21202120
strbuf_addstr(&buf, "\n\n");
21212121
if (is_fixup_flag(command, flag))
2122-
strbuf_add_commented_lines(&buf, body, strlen(body),
2123-
comment_line_str);
2122+
strbuf_add_comment_lines(&buf, body, strlen(body));
21242123
else
21252124
strbuf_addstr(&buf, body);
21262125

@@ -2139,8 +2138,7 @@ static int update_squash_messages(struct repository *r,
21392138
strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
21402139
++ctx->current_fixup_count + 1);
21412140
strbuf_addstr(&buf, "\n\n");
2142-
strbuf_add_commented_lines(&buf, body, strlen(body),
2143-
comment_line_str);
2141+
strbuf_add_comment_lines(&buf, body, strlen(body));
21442142
} else
21452143
return error(_("unknown command: %d"), command);
21462144
repo_unuse_commit_buffer(r, commit, message);

strbuf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,9 @@ static void add_lines(struct strbuf *out,
379379
strbuf_complete_line(out);
380380
}
381381

382-
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
383-
size_t size, const char *comment_prefix)
382+
void strbuf_add_comment_lines(struct strbuf *out, const char *buf, size_t size)
384383
{
385-
add_lines(out, comment_prefix, buf, size, 1);
384+
add_lines(out, comment_line_str, buf, size, 1);
386385
}
387386

388387
void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...)
@@ -395,7 +394,7 @@ void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...)
395394
strbuf_vaddf(&buf, fmt, params);
396395
va_end(params);
397396

398-
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_str);
397+
strbuf_add_comment_lines(sb, buf.buf, buf.len);
399398
if (incomplete_line)
400399
sb->buf[--sb->len] = '\0';
401400

strbuf.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,9 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
284284

285285
/**
286286
* Add a NUL-terminated string to the buffer. Each line will be prepended
287-
* by a comment character and a blank.
287+
* by the comment character and a blank.
288288
*/
289-
void strbuf_add_commented_lines(struct strbuf *out,
290-
const char *buf, size_t size,
291-
const char *comment_prefix);
292-
289+
void strbuf_add_comment_lines(struct strbuf *out, const char *buf, size_t size);
293290

294291
/**
295292
* Add data of given length to the buffer.

wt-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
10331033
if (s->display_comment_prefix) {
10341034
size_t len;
10351035
summary_content = strbuf_detach(&summary, &len);
1036-
strbuf_add_commented_lines(&summary, summary_content, len, comment_line_str);
1036+
strbuf_add_comment_lines(&summary, summary_content, len);
10371037
free(summary_content);
10381038
}
10391039

@@ -1112,7 +1112,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
11121112
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
11131113

11141114
strbuf_comment_addf(buf, "%s", cut_line);
1115-
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_str);
1115+
strbuf_add_comment_lines(buf, explanation, strlen(explanation));
11161116
}
11171117

11181118
void wt_status_add_cut_line(struct wt_status *s)

0 commit comments

Comments
 (0)