Skip to content

Commit a1bb146

Browse files
peffgitster
authored andcommitted
strbuf: accept a comment string for strbuf_add_commented_lines()
As part of our transition to multi-byte comment characters, let's take a NUL-terminated string pointer for strbuf_add_commented_lines() rather than a single character. All of the callers have to be adjusted; most can just pass comment_line_str rather than comment_line_char. And now our "cheat" in strbuf_commented_addf() can go away, as we can take the full string from it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a35d96 commit a1bb146

File tree

8 files changed

+21
-31
lines changed

8 files changed

+21
-31
lines changed

builtin/notes.c

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

180180
if (strbuf_read(&buf, show.out, 0) < 0)
181181
die_errno(_("could not read 'show' output"));
182-
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char);
182+
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
183183
write_or_die(fd, cbuf.buf, cbuf.len);
184184

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

209209
strbuf_addch(&buf, '\n');
210-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
210+
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
211211
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
212-
comment_line_char);
213-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
212+
comment_line_str);
213+
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
214214
write_or_die(fd, buf.buf, buf.len);
215215

216216
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_char);
16+
strbuf_add_commented_lines(buf, msg, len, comment_line_str);
1717
free(msg);
1818
}
1919

fmt-merge-msg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
510510
if (sig->len) {
511511
strbuf_addch(tagbuf, '\n');
512512
strbuf_add_commented_lines(tagbuf, sig->buf, sig->len,
513-
comment_line_char);
513+
comment_line_str);
514514
}
515515
}
516516

@@ -557,7 +557,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
557557
strbuf_add_commented_lines(&tagline,
558558
origins.items[first_tag].string,
559559
strlen(origins.items[first_tag].string),
560-
comment_line_char);
560+
comment_line_str);
561561
strbuf_insert(&tagbuf, 0, tagline.buf,
562562
tagline.len);
563563
strbuf_release(&tagline);
@@ -566,7 +566,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
566566
strbuf_add_commented_lines(&tagbuf,
567567
origins.items[i].string,
568568
strlen(origins.items[i].string),
569-
comment_line_char);
569+
comment_line_str);
570570
fmt_tag_signature(&tagbuf, &sig, buf, len);
571571
}
572572
strbuf_release(&payload);

rebase-interactive.c

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

81-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
81+
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
8282

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

90-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
90+
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
9191

9292
if (edit_todo)
9393
msg = _("\nYou are editing the todo file "
@@ -98,7 +98,7 @@ void append_todo_help(int command_count,
9898
msg = _("\nHowever, if you remove everything, "
9999
"the rebase will be aborted.\n\n");
100100

101-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
101+
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
102102
}
103103

104104
int edit_todo_list(struct repository *r, struct todo_list *todo_list,

sequencer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
18511851
s += count;
18521852
len -= count;
18531853
}
1854-
strbuf_add_commented_lines(buf, s, len, comment_line_char);
1854+
strbuf_add_commented_lines(buf, s, len, comment_line_str);
18551855
}
18561856

18571857
/* Does the current fixup chain contain a squash command? */
@@ -1950,7 +1950,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
19501950
strbuf_addf(buf, _(nth_commit_msg_fmt),
19511951
++opts->current_fixup_count + 1);
19521952
strbuf_addstr(buf, "\n\n");
1953-
strbuf_add_commented_lines(buf, body, commented_len, comment_line_char);
1953+
strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
19541954
/* buf->buf may be reallocated so store an offset into the buffer */
19551955
fixup_off = buf->len;
19561956
strbuf_addstr(buf, body + commented_len);
@@ -2041,7 +2041,7 @@ static int update_squash_messages(struct repository *r,
20412041
strbuf_addstr(&buf, "\n\n");
20422042
if (is_fixup_flag(command, flag))
20432043
strbuf_add_commented_lines(&buf, body, strlen(body),
2044-
comment_line_char);
2044+
comment_line_str);
20452045
else
20462046
strbuf_addstr(&buf, body);
20472047

@@ -2061,7 +2061,7 @@ static int update_squash_messages(struct repository *r,
20612061
++opts->current_fixup_count + 1);
20622062
strbuf_addstr(&buf, "\n\n");
20632063
strbuf_add_commented_lines(&buf, body, strlen(body),
2064-
comment_line_char);
2064+
comment_line_str);
20652065
} else
20662066
return error(_("unknown command: %d"), command);
20672067
repo_unuse_commit_buffer(r, commit, message);

strbuf.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,9 @@ static void add_lines(struct strbuf *out,
359359
}
360360

361361
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
362-
size_t size, char comment_prefix)
362+
size_t size, const char *comment_prefix)
363363
{
364-
char prefix[2];
365-
366-
prefix[0] = comment_prefix;
367-
prefix[1] = '\0';
368-
add_lines(out, prefix, buf, size, 1);
364+
add_lines(out, comment_prefix, buf, size, 1);
369365
}
370366

371367
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
@@ -379,13 +375,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
379375
strbuf_vaddf(&buf, fmt, params);
380376
va_end(params);
381377

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]);
378+
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
389379
if (incomplete_line)
390380
sb->buf[--sb->len] = '\0';
391381

strbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
288288
*/
289289
void strbuf_add_commented_lines(struct strbuf *out,
290290
const char *buf, size_t size,
291-
char comment_prefix);
291+
const char *comment_prefix);
292292

293293

294294
/**

wt-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
10281028
if (s->display_comment_prefix) {
10291029
size_t len;
10301030
summary_content = strbuf_detach(&summary, &len);
1031-
strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char);
1031+
strbuf_add_commented_lines(&summary, summary_content, len, comment_line_str);
10321032
free(summary_content);
10331033
}
10341034

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

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

11101110
void wt_status_add_cut_line(FILE *fp)

0 commit comments

Comments
 (0)