Skip to content

Commit 3a35d96

Browse files
peffgitster
authored andcommitted
strbuf: accept a comment string for strbuf_commented_addf()
As part of our transition to multi-byte comment characters, let's take a NUL-terminated string pointer for strbuf_commented_addf() rather than a single character. All of the callers have to be adjusted, but they can just pass comment_line_str rather than comment_line_char. Note that we rely on strbuf_add_commented_lines() under the hood, so we'll cheat a bit to squeeze our string into a single character (for now the two are equivalent, and we'll address this TODO in the next patch). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2982b65 commit 3a35d96

File tree

9 files changed

+24
-18
lines changed

9 files changed

+24
-18
lines changed

add-patch.c

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

11071107
strbuf_reset(&s->buf);
1108-
strbuf_commented_addf(&s->buf, comment_line_char,
1108+
strbuf_commented_addf(&s->buf, comment_line_str,
11091109
_("Manual hunk edit mode -- see bottom for "
11101110
"a quick guide.\n"));
11111111
render_hunk(s, hunk, 0, 0, &s->buf);
1112-
strbuf_commented_addf(&s->buf, comment_line_char,
1112+
strbuf_commented_addf(&s->buf, comment_line_str,
11131113
_("---\n"
11141114
"To remove '%c' lines, make them ' ' lines "
11151115
"(context).\n"
@@ -1118,13 +1118,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11181118
s->mode->is_reverse ? '+' : '-',
11191119
s->mode->is_reverse ? '-' : '+',
11201120
comment_line_char);
1121-
strbuf_commented_addf(&s->buf, comment_line_char, "%s",
1121+
strbuf_commented_addf(&s->buf, comment_line_str, "%s",
11221122
_(s->mode->edit_hunk_hint));
11231123
/*
11241124
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
11251125
* messages.
11261126
*/
1127-
strbuf_commented_addf(&s->buf, comment_line_char,
1127+
strbuf_commented_addf(&s->buf, comment_line_str,
11281128
_("If it does not apply cleanly, you will be "
11291129
"given an opportunity to\n"
11301130
"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
@@ -667,7 +667,7 @@ static int edit_branch_description(const char *branch_name)
667667
exists = !read_branch_desc(&buf, branch_name);
668668
if (!buf.len || buf.buf[buf.len-1] != '\n')
669669
strbuf_addch(&buf, '\n');
670-
strbuf_commented_addf(&buf, comment_line_char,
670+
strbuf_commented_addf(&buf, comment_line_str,
671671
_("Please edit the description for the branch\n"
672672
" %s\n"
673673
"Lines starting with '%c' will be stripped.\n"),

builtin/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,15 +852,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
852852
strbuf_addch(&msg, '\n');
853853
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
854854
wt_status_append_cut_line(&msg);
855-
strbuf_commented_addf(&msg, comment_line_char, "\n");
855+
strbuf_commented_addf(&msg, comment_line_str, "\n");
856856
}
857-
strbuf_commented_addf(&msg, comment_line_char,
857+
strbuf_commented_addf(&msg, comment_line_str,
858858
_(merge_editor_comment));
859859
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
860-
strbuf_commented_addf(&msg, comment_line_char,
860+
strbuf_commented_addf(&msg, comment_line_str,
861861
_(scissors_editor_comment));
862862
else
863-
strbuf_commented_addf(&msg, comment_line_char,
863+
strbuf_commented_addf(&msg, comment_line_str,
864864
_(no_scissors_editor_comment), comment_line_char);
865865
}
866866
if (signoff)

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
291291
struct strbuf buf = STRBUF_INIT;
292292
strbuf_addch(&buf, '\n');
293293
if (opt->cleanup_mode == CLEANUP_ALL)
294-
strbuf_commented_addf(&buf, comment_line_char,
294+
strbuf_commented_addf(&buf, comment_line_str,
295295
_(tag_template), tag, comment_line_char);
296296
else
297-
strbuf_commented_addf(&buf, comment_line_char,
297+
strbuf_commented_addf(&buf, comment_line_str,
298298
_(tag_template_nocleanup), tag, comment_line_char);
299299
write_or_die(fd, buf.buf, buf.len);
300300
strbuf_release(&buf);

rebase-interactive.c

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

7272
if (!edit_todo) {
7373
strbuf_addch(buf, '\n');
74-
strbuf_commented_addf(buf, comment_line_char,
74+
strbuf_commented_addf(buf, comment_line_str,
7575
Q_("Rebase %s onto %s (%d command)",
7676
"Rebase %s onto %s (%d commands)",
7777
command_count),

sequencer.c

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

669669
strbuf_addch(msgbuf, '\n');
670-
strbuf_commented_addf(msgbuf, comment_line_char, "Conflicts:\n");
670+
strbuf_commented_addf(msgbuf, comment_line_str, "Conflicts:\n");
671671
for (i = 0; i < istate->cache_nr;) {
672672
const struct cache_entry *ce = istate->cache[i++];
673673
if (ce_stage(ce)) {
674-
strbuf_commented_addf(msgbuf, comment_line_char,
674+
strbuf_commented_addf(msgbuf, comment_line_str,
675675
"\t%s\n", ce->name);
676676
while (i < istate->cache_nr &&
677677
!strcmp(ce->name, istate->cache[i]->name))

strbuf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
368368
add_lines(out, prefix, buf, size, 1);
369369
}
370370

371-
void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
371+
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
372372
const char *fmt, ...)
373373
{
374374
va_list params;
@@ -379,7 +379,13 @@ void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
379379
strbuf_vaddf(&buf, fmt, params);
380380
va_end(params);
381381

382-
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
382+
/*
383+
* TODO Our commented_lines helper does not yet understand
384+
* comment strings. But since we know that the strings are
385+
* always single-char, we can cheat for the moment, and
386+
* fix this later.
387+
*/
388+
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix[0]);
383389
if (incomplete_line)
384390
sb->buf[--sb->len] = '\0';
385391

strbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
379379
* blank to the buffer.
380380
*/
381381
__attribute__((format (printf, 3, 4)))
382-
void strbuf_commented_addf(struct strbuf *sb, char comment_prefix, const char *fmt, ...);
382+
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix, const char *fmt, ...);
383383

384384
__attribute__((format (printf,2,0)))
385385
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
@@ -1103,7 +1103,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
11031103
{
11041104
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
11051105

1106-
strbuf_commented_addf(buf, comment_line_char, "%s", cut_line);
1106+
strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
11071107
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
11081108
}
11091109

0 commit comments

Comments
 (0)