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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 12, 2024 at 05:17 UTC
3a35d96284b4a0551a350707df68f368947630d1
9 files changed
+24
-18
add-patch.c
+4
-4
@@ -1105,11 +1105,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
1105
size_t i;
1106
1107
strbuf_reset(&s->buf);
1108
- strbuf_commented_addf(&s->buf, comment_line_char,
1108
+ strbuf_commented_addf(&s->buf, comment_line_str,
1109
_("Manual hunk edit mode -- see bottom for "
1110
"a quick guide.\n"));
1111
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,
1113
_("---\n"
1114
"To remove '%c' lines, make them ' ' lines "
1115
"(context).\n"
@@ -1118,13 +1118,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
1118
s->mode->is_reverse ? '+' : '-',
1119
s->mode->is_reverse ? '-' : '+',
1120
comment_line_char);
1121
- strbuf_commented_addf(&s->buf, comment_line_char, "%s",
1121
+ strbuf_commented_addf(&s->buf, comment_line_str, "%s",
1122
_(s->mode->edit_hunk_hint));
1123
/*
1124
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
1125
* messages.
1126
*/
1127
- strbuf_commented_addf(&s->buf, comment_line_char,
1127
+ strbuf_commented_addf(&s->buf, comment_line_str,
1128
_("If it does not apply cleanly, you will be "
1129
"given an opportunity to\n"
1130
"edit again. If all lines of the hunk are "
builtin/branch.c
+1
-1
@@ -667,7 +667,7 @@ static int edit_branch_description(const char *branch_name)
667
exists = !read_branch_desc(&buf, branch_name);
668
if (!buf.len || buf.buf[buf.len-1] != '\n')
669
strbuf_addch(&buf, '\n');
670
- strbuf_commented_addf(&buf, comment_line_char,
670
+ strbuf_commented_addf(&buf, comment_line_str,
671
_("Please edit the description for the branch\n"
672
" %s\n"
673
"Lines starting with '%c' will be stripped.\n"),
builtin/merge.c
+4
-4
@@ -852,15 +852,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
852
strbuf_addch(&msg, '\n');
853
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
854
wt_status_append_cut_line(&msg);
855
- strbuf_commented_addf(&msg, comment_line_char, "\n");
855
+ strbuf_commented_addf(&msg, comment_line_str, "\n");
856
}
857
- strbuf_commented_addf(&msg, comment_line_char,
857
+ strbuf_commented_addf(&msg, comment_line_str,
858
_(merge_editor_comment));
859
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
860
- strbuf_commented_addf(&msg, comment_line_char,
860
+ strbuf_commented_addf(&msg, comment_line_str,
861
_(scissors_editor_comment));
862
else
863
- strbuf_commented_addf(&msg, comment_line_char,
863
+ strbuf_commented_addf(&msg, comment_line_str,
864
_(no_scissors_editor_comment), comment_line_char);
865
}
866
if (signoff)
builtin/tag.c
+2
-2
@@ -291,10 +291,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
291
struct strbuf buf = STRBUF_INIT;
292
strbuf_addch(&buf, '\n');
293
if (opt->cleanup_mode == CLEANUP_ALL)
294
- strbuf_commented_addf(&buf, comment_line_char,
294
+ strbuf_commented_addf(&buf, comment_line_str,
295
_(tag_template), tag, comment_line_char);
296
else
297
- strbuf_commented_addf(&buf, comment_line_char,
297
+ strbuf_commented_addf(&buf, comment_line_str,
298
_(tag_template_nocleanup), tag, comment_line_char);
299
write_or_die(fd, buf.buf, buf.len);
300
strbuf_release(&buf);
rebase-interactive.c
+1
-1
@@ -71,7 +71,7 @@ void append_todo_help(int command_count,
71
72
if (!edit_todo) {
73
strbuf_addch(buf, '\n');
74
- strbuf_commented_addf(buf, comment_line_char,
74
+ strbuf_commented_addf(buf, comment_line_str,
75
Q_("Rebase %s onto %s (%d command)",
76
"Rebase %s onto %s (%d commands)",
77
command_count),
sequencer.c
+2
-2
@@ -667,11 +667,11 @@ void append_conflicts_hint(struct index_state *istate,
667
}
668
669
strbuf_addch(msgbuf, '\n');
670
- strbuf_commented_addf(msgbuf, comment_line_char, "Conflicts:\n");
670
+ strbuf_commented_addf(msgbuf, comment_line_str, "Conflicts:\n");
671
for (i = 0; i < istate->cache_nr;) {
672
const struct cache_entry *ce = istate->cache[i++];
673
if (ce_stage(ce)) {
674
- strbuf_commented_addf(msgbuf, comment_line_char,
674
+ strbuf_commented_addf(msgbuf, comment_line_str,
675
"\t%s\n", ce->name);
676
while (i < istate->cache_nr &&
677
!strcmp(ce->name, istate->cache[i]->name))
strbuf.c
+8
-2
@@ -368,7 +368,7 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
368
add_lines(out, prefix, buf, size, 1);
369
}
370
371
-void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
371
+void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
372
const char *fmt, ...)
373
{
374
va_list params;
@@ -379,7 +379,13 @@ void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
379
strbuf_vaddf(&buf, fmt, params);
380
va_end(params);
381
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]);
389
if (incomplete_line)
390
sb->buf[--sb->len] = '\0';
391
strbuf.h
+1
-1
@@ -379,7 +379,7 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
379
* blank to the buffer.
380
*/
381
__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, ...);
383
384
__attribute__((format (printf,2,0)))
385
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
wt-status.c
+1
-1
@@ -1103,7 +1103,7 @@ void wt_status_append_cut_line(struct strbuf *buf)
1103
{
1104
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
1105
1106
- strbuf_commented_addf(buf, comment_line_char, "%s", cut_line);
1106
+ strbuf_commented_addf(buf, comment_line_str, "%s", cut_line);
1107
strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
1108
}
1109