Skip to content

Commit f3582c0

Browse files
committed
strbuf: retire strbuf_commented_addf()
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_addf() 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 6809f8c commit f3582c0

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

add-patch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11141114
size_t i;
11151115

11161116
strbuf_reset(&s->buf);
1117-
strbuf_commented_addf(&s->buf, comment_line_str,
1117+
strbuf_comment_addf(&s->buf,
11181118
_("Manual hunk edit mode -- see bottom for "
11191119
"a quick guide.\n"));
11201120
render_hunk(s, hunk, 0, 0, &s->buf);
1121-
strbuf_commented_addf(&s->buf, comment_line_str,
1121+
strbuf_comment_addf(&s->buf,
11221122
_("---\n"
11231123
"To remove '%c' lines, make them ' ' lines "
11241124
"(context).\n"
@@ -1127,13 +1127,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11271127
s->mode->is_reverse ? '+' : '-',
11281128
s->mode->is_reverse ? '-' : '+',
11291129
comment_line_str);
1130-
strbuf_commented_addf(&s->buf, comment_line_str, "%s",
1130+
strbuf_comment_addf(&s->buf, "%s",
11311131
_(s->mode->edit_hunk_hint));
11321132
/*
11331133
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
11341134
* messages.
11351135
*/
1136-
strbuf_commented_addf(&s->buf, comment_line_str,
1136+
strbuf_comment_addf(&s->buf,
11371137
_("If it does not apply cleanly, you will be "
11381138
"given an opportunity to\n"
11391139
"edit again. If all lines of the hunk are "

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static int edit_branch_description(const char *branch_name)
681681
exists = !read_branch_desc(&buf, branch_name);
682682
if (!buf.len || buf.buf[buf.len-1] != '\n')
683683
strbuf_addch(&buf, '\n');
684-
strbuf_commented_addf(&buf, comment_line_str,
684+
strbuf_comment_addf(&buf,
685685
_("Please edit the description for the branch\n"
686686
" %s\n"
687687
"Lines starting with '%s' will be stripped.\n"),

builtin/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,15 +863,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
863863
strbuf_addch(&msg, '\n');
864864
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
865865
wt_status_append_cut_line(&msg);
866-
strbuf_commented_addf(&msg, comment_line_str, "\n");
866+
strbuf_comment_addf(&msg, "\n");
867867
}
868-
strbuf_commented_addf(&msg, comment_line_str,
868+
strbuf_comment_addf(&msg,
869869
_(merge_editor_comment));
870870
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
871-
strbuf_commented_addf(&msg, comment_line_str,
871+
strbuf_comment_addf(&msg,
872872
_(scissors_editor_comment));
873873
else
874-
strbuf_commented_addf(&msg, comment_line_str,
874+
strbuf_comment_addf(&msg,
875875
_(no_scissors_editor_comment), comment_line_str);
876876
}
877877
if (signoff)

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
334334
struct strbuf buf = STRBUF_INIT;
335335
strbuf_addch(&buf, '\n');
336336
if (opt->cleanup_mode == CLEANUP_ALL)
337-
strbuf_commented_addf(&buf, comment_line_str,
337+
strbuf_comment_addf(&buf,
338338
_(tag_template), tag, comment_line_str);
339339
else
340-
strbuf_commented_addf(&buf, comment_line_str,
340+
strbuf_comment_addf(&buf,
341341
_(tag_template_nocleanup), tag, comment_line_str);
342342
write_or_die(fd, buf.buf, buf.len);
343343
strbuf_release(&buf);

rebase-interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void append_todo_help(int command_count,
7373

7474
if (!edit_todo) {
7575
strbuf_addch(buf, '\n');
76-
strbuf_commented_addf(buf, comment_line_str,
76+
strbuf_comment_addf(buf,
7777
Q_("Rebase %s onto %s (%d command)",
7878
"Rebase %s onto %s (%d commands)",
7979
command_count),

sequencer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,11 @@ void append_conflicts_hint(struct index_state *istate,
731731
}
732732

733733
strbuf_addch(msgbuf, '\n');
734-
strbuf_commented_addf(msgbuf, comment_line_str, "Conflicts:\n");
734+
strbuf_comment_addf(msgbuf, "Conflicts:\n");
735735
for (i = 0; i < istate->cache_nr;) {
736736
const struct cache_entry *ce = istate->cache[i++];
737737
if (ce_stage(ce)) {
738-
strbuf_commented_addf(msgbuf, comment_line_str,
738+
strbuf_comment_addf(msgbuf,
739739
"\t%s\n", ce->name);
740740
while (i < istate->cache_nr &&
741741
!strcmp(ce->name, istate->cache[i]->name))

strbuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "git-compat-util.h"
2+
#include "environment.h"
23
#include "gettext.h"
34
#include "hex-ll.h"
45
#include "strbuf.h"
@@ -384,8 +385,7 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
384385
add_lines(out, comment_prefix, buf, size, 1);
385386
}
386387

387-
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
388-
const char *fmt, ...)
388+
void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...)
389389
{
390390
va_list params;
391391
struct strbuf buf = STRBUF_INIT;
@@ -395,7 +395,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
395395
strbuf_vaddf(&buf, fmt, params);
396396
va_end(params);
397397

398-
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
398+
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_str);
399399
if (incomplete_line)
400400
sb->buf[--sb->len] = '\0';
401401

strbuf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ __attribute__((format (printf,2,3)))
385385
void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
386386

387387
/**
388-
* Add a formatted string prepended by a comment character and a
388+
* Add a formatted string prepended by the comment character and a
389389
* blank to the buffer.
390390
*/
391-
__attribute__((format (printf, 3, 4)))
392-
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix, const char *fmt, ...);
391+
__attribute__((format (printf,2,3)))
392+
void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...);
393393

394394
__attribute__((format (printf,2,0)))
395395
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
11111111
{
11121112
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
11131113

1114-
strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
1114+
strbuf_comment_addf(buf, "%s", cut_line);
11151115
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_str);
11161116
}
11171117

0 commit comments

Comments
 (0)