Skip to content

Commit

Permalink
strbuf: retire strbuf_commented_addf()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gitster committed Sep 12, 2024
1 parent 6809f8c commit f3582c0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,11 +1114,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
size_t i;

strbuf_reset(&s->buf);
strbuf_commented_addf(&s->buf, comment_line_str,
strbuf_comment_addf(&s->buf,
_("Manual hunk edit mode -- see bottom for "
"a quick guide.\n"));
render_hunk(s, hunk, 0, 0, &s->buf);
strbuf_commented_addf(&s->buf, comment_line_str,
strbuf_comment_addf(&s->buf,
_("---\n"
"To remove '%c' lines, make them ' ' lines "
"(context).\n"
Expand All @@ -1127,13 +1127,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
s->mode->is_reverse ? '+' : '-',
s->mode->is_reverse ? '-' : '+',
comment_line_str);
strbuf_commented_addf(&s->buf, comment_line_str, "%s",
strbuf_comment_addf(&s->buf, "%s",
_(s->mode->edit_hunk_hint));
/*
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
* messages.
*/
strbuf_commented_addf(&s->buf, comment_line_str,
strbuf_comment_addf(&s->buf,
_("If it does not apply cleanly, you will be "
"given an opportunity to\n"
"edit again. If all lines of the hunk are "
Expand Down
2 changes: 1 addition & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ static int edit_branch_description(const char *branch_name)
exists = !read_branch_desc(&buf, branch_name);
if (!buf.len || buf.buf[buf.len-1] != '\n')
strbuf_addch(&buf, '\n');
strbuf_commented_addf(&buf, comment_line_str,
strbuf_comment_addf(&buf,
_("Please edit the description for the branch\n"
" %s\n"
"Lines starting with '%s' will be stripped.\n"),
Expand Down
8 changes: 4 additions & 4 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,15 +863,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
strbuf_addch(&msg, '\n');
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
wt_status_append_cut_line(&msg);
strbuf_commented_addf(&msg, comment_line_str, "\n");
strbuf_comment_addf(&msg, "\n");
}
strbuf_commented_addf(&msg, comment_line_str,
strbuf_comment_addf(&msg,
_(merge_editor_comment));
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
strbuf_commented_addf(&msg, comment_line_str,
strbuf_comment_addf(&msg,
_(scissors_editor_comment));
else
strbuf_commented_addf(&msg, comment_line_str,
strbuf_comment_addf(&msg,
_(no_scissors_editor_comment), comment_line_str);
}
if (signoff)
Expand Down
4 changes: 2 additions & 2 deletions builtin/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf buf = STRBUF_INIT;
strbuf_addch(&buf, '\n');
if (opt->cleanup_mode == CLEANUP_ALL)
strbuf_commented_addf(&buf, comment_line_str,
strbuf_comment_addf(&buf,
_(tag_template), tag, comment_line_str);
else
strbuf_commented_addf(&buf, comment_line_str,
strbuf_comment_addf(&buf,
_(tag_template_nocleanup), tag, comment_line_str);
write_or_die(fd, buf.buf, buf.len);
strbuf_release(&buf);
Expand Down
2 changes: 1 addition & 1 deletion rebase-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void append_todo_help(int command_count,

if (!edit_todo) {
strbuf_addch(buf, '\n');
strbuf_commented_addf(buf, comment_line_str,
strbuf_comment_addf(buf,
Q_("Rebase %s onto %s (%d command)",
"Rebase %s onto %s (%d commands)",
command_count),
Expand Down
4 changes: 2 additions & 2 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,11 @@ void append_conflicts_hint(struct index_state *istate,
}

strbuf_addch(msgbuf, '\n');
strbuf_commented_addf(msgbuf, comment_line_str, "Conflicts:\n");
strbuf_comment_addf(msgbuf, "Conflicts:\n");
for (i = 0; i < istate->cache_nr;) {
const struct cache_entry *ce = istate->cache[i++];
if (ce_stage(ce)) {
strbuf_commented_addf(msgbuf, comment_line_str,
strbuf_comment_addf(msgbuf,
"\t%s\n", ce->name);
while (i < istate->cache_nr &&
!strcmp(ce->name, istate->cache[i]->name))
Expand Down
6 changes: 3 additions & 3 deletions strbuf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
#include "hex-ll.h"
#include "strbuf.h"
Expand Down Expand Up @@ -384,8 +385,7 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
add_lines(out, comment_prefix, buf, size, 1);
}

void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
const char *fmt, ...)
void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...)
{
va_list params;
struct strbuf buf = STRBUF_INIT;
Expand All @@ -395,7 +395,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
strbuf_vaddf(&buf, fmt, params);
va_end(params);

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

Expand Down
6 changes: 3 additions & 3 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ __attribute__((format (printf,2,3)))
void strbuf_addf(struct strbuf *sb, const char *fmt, ...);

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

__attribute__((format (printf,2,0)))
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
Expand Down
2 changes: 1 addition & 1 deletion wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
{
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");

strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
strbuf_comment_addf(buf, "%s", cut_line);
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_str);
}

Expand Down

0 comments on commit f3582c0

Please sign in to comment.