prefer comment_line_str to comment_line_char for printing

As part of our transition to multi-byte comment characters, we should use the string variable rather than the historical character variable. All of the sites adjusted here are just swapping out "%c" for "%s" in format strings, or strbuf_addch() for strbuf_addstr(). The type system and printf-attribute give the compiler enough information to make sure our formats and variable changes all match (especially important for cases where the format string is defined far away from its use, like prepare_to_commit() in commit.c). 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 f99e1d94f5ed72fd7c5115a814b1087fde919fe5
8 files changed +32 -32
add-patch.c
+2 -2
@@ -1114,10 +1114,10 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
1114 "To remove '%c' lines, make them ' ' lines "
1115 "(context).\n"
1116 "To remove '%c' lines, delete them.\n"
1117 - "Lines starting with %c will be removed.\n"),
1117 + "Lines starting with %s will be removed.\n"),
1118 s->mode->is_reverse ? '+' : '-',
1119 s->mode->is_reverse ? '-' : '+',
1120 - comment_line_char);
1120 + comment_line_str);
1121 strbuf_commented_addf(&s->buf, comment_line_str, "%s",
1122 _(s->mode->edit_hunk_hint));
1123 /*
builtin/branch.c
+2 -2
@@ -670,8 +670,8 @@ static int edit_branch_description(const char *branch_name)
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"),
674 - branch_name, comment_line_char);
673 + "Lines starting with '%s' will be stripped.\n"),
674 + branch_name, comment_line_str);
675 write_file_buf(edit_description(), buf.buf, buf.len);
676 strbuf_reset(&buf);
677 if (launch_editor(edit_description(), &buf, NULL)) {
builtin/commit.c
+6 -6
@@ -910,18 +910,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
910 struct ident_split ci, ai;
911 const char *hint_cleanup_all = allow_empty_message ?
912 _("Please enter the commit message for your changes."
913 - " Lines starting\nwith '%c' will be ignored.\n") :
913 + " Lines starting\nwith '%s' will be ignored.\n") :
914 _("Please enter the commit message for your changes."
915 - " Lines starting\nwith '%c' will be ignored, and an empty"
915 + " Lines starting\nwith '%s' will be ignored, and an empty"
916 " message aborts the commit.\n");
917 const char *hint_cleanup_space = allow_empty_message ?
918 _("Please enter the commit message for your changes."
919 " Lines starting\n"
920 - "with '%c' will be kept; you may remove them"
920 + "with '%s' will be kept; you may remove them"
921 " yourself if you want to.\n") :
922 _("Please enter the commit message for your changes."
923 " Lines starting\n"
924 - "with '%c' will be kept; you may remove them"
924 + "with '%s' will be kept; you may remove them"
925 " yourself if you want to.\n"
926 "An empty message aborts the commit.\n");
927 if (whence != FROM_COMMIT) {
@@ -945,12 +945,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
945
946 fprintf(s->fp, "\n");
947 if (cleanup_mode == COMMIT_MSG_CLEANUP_ALL)
948 - status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_char);
948 + status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_all, comment_line_str);
949 else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
950 if (whence == FROM_COMMIT && !merge_contains_scissors)
951 wt_status_add_cut_line(s->fp);
952 } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */
953 - status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_char);
953 + status_printf(s, GIT_COLOR_NORMAL, hint_cleanup_space, comment_line_str);
954
955 /*
956 * These should never fail because they come from our own
builtin/merge.c
+2 -2
@@ -821,7 +821,7 @@ static const char scissors_editor_comment[] =
821 N_("An empty message aborts the commit.\n");
822
823 static const char no_scissors_editor_comment[] =
824 -N_("Lines starting with '%c' will be ignored, and an empty message aborts\n"
824 +N_("Lines starting with '%s' will be ignored, and an empty message aborts\n"
825 "the commit.\n");
826
827 static void write_merge_heads(struct commit_list *);
@@ -861,7 +861,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
861 _(scissors_editor_comment));
862 else
863 strbuf_commented_addf(&msg, comment_line_str,
864 - _(no_scissors_editor_comment), comment_line_char);
864 + _(no_scissors_editor_comment), comment_line_str);
865 }
866 if (signoff)
867 append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0);
builtin/tag.c
+4 -4
@@ -158,11 +158,11 @@ static int do_sign(struct strbuf *buffer)
158
159 static const char tag_template[] =
160 N_("\nWrite a message for tag:\n %s\n"
161 - "Lines starting with '%c' will be ignored.\n");
161 + "Lines starting with '%s' will be ignored.\n");
162
163 static const char tag_template_nocleanup[] =
164 N_("\nWrite a message for tag:\n %s\n"
165 - "Lines starting with '%c' will be kept; you may remove them"
165 + "Lines starting with '%s' will be kept; you may remove them"
166 " yourself if you want to.\n");
167
168 static int git_tag_config(const char *var, const char *value,
@@ -292,10 +292,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
292 strbuf_addch(&buf, '\n');
293 if (opt->cleanup_mode == CLEANUP_ALL)
294 strbuf_commented_addf(&buf, comment_line_str,
295 - _(tag_template), tag, comment_line_char);
295 + _(tag_template), tag, comment_line_str);
296 else
297 strbuf_commented_addf(&buf, comment_line_str,
298 - _(tag_template_nocleanup), tag, comment_line_char);
298 + _(tag_template_nocleanup), tag, comment_line_str);
299 write_or_die(fd, buf.buf, buf.len);
300 strbuf_release(&buf);
301 }
fmt-merge-msg.c
+1 -1
@@ -321,7 +321,7 @@ static void credit_people(struct strbuf *out,
321 skip_prefix(me, them->items->string, &me) &&
322 starts_with(me, " <")))
323 return;
324 - strbuf_addf(out, "\n%c %s ", comment_line_char, label);
324 + strbuf_addf(out, "\n%s %s ", comment_line_str, label);
325 add_people_count(out, them);
326 }
327
sequencer.c
+10 -10
@@ -663,7 +663,7 @@ void append_conflicts_hint(struct index_state *istate,
663 if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
664 strbuf_addch(msgbuf, '\n');
665 wt_status_append_cut_line(msgbuf);
666 - strbuf_addch(msgbuf, comment_line_char);
666 + strbuf_addstr(msgbuf, comment_line_str);
667 }
668
669 strbuf_addch(msgbuf, '\n');
@@ -1946,7 +1946,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
1946 (starts_with(body, "squash!") || starts_with(body, "fixup!"))))
1947 commented_len = commit_subject_length(body);
1948
1949 - strbuf_addf(buf, "\n%c ", comment_line_char);
1949 + strbuf_addf(buf, "\n%s ", comment_line_str);
1950 strbuf_addf(buf, _(nth_commit_msg_fmt),
1951 ++opts->current_fixup_count + 1);
1952 strbuf_addstr(buf, "\n\n");
@@ -2006,7 +2006,7 @@ static int update_squash_messages(struct repository *r,
2006 eol = buf.buf[0] != comment_line_char ?
2007 buf.buf : strchrnul(buf.buf, '\n');
2008
2009 - strbuf_addf(&header, "%c ", comment_line_char);
2009 + strbuf_addf(&header, "%s ", comment_line_str);
2010 strbuf_addf(&header, _(combined_commit_msg_fmt),
2011 opts->current_fixup_count + 2);
2012 strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
@@ -2032,9 +2032,9 @@ static int update_squash_messages(struct repository *r,
2032 repo_unuse_commit_buffer(r, head_commit, head_message);
2033 return error(_("cannot write '%s'"), rebase_path_fixup_msg());
2034 }
2035 - strbuf_addf(&buf, "%c ", comment_line_char);
2035 + strbuf_addf(&buf, "%s ", comment_line_str);
2036 strbuf_addf(&buf, _(combined_commit_msg_fmt), 2);
2037 - strbuf_addf(&buf, "\n%c ", comment_line_char);
2037 + strbuf_addf(&buf, "\n%s ", comment_line_str);
2038 strbuf_addstr(&buf, is_fixup_flag(command, flag) ?
2039 _(skip_first_commit_msg_str) :
2040 _(first_commit_msg_str));
@@ -2056,7 +2056,7 @@ static int update_squash_messages(struct repository *r,
2056 if (command == TODO_SQUASH || is_fixup_flag(command, flag)) {
2057 res = append_squash_message(&buf, body, command, opts, flag);
2058 } else if (command == TODO_FIXUP) {
2059 - strbuf_addf(&buf, "\n%c ", comment_line_char);
2059 + strbuf_addf(&buf, "\n%s ", comment_line_str);
2060 strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
2061 ++opts->current_fixup_count + 1);
2062 strbuf_addstr(&buf, "\n\n");
@@ -5659,8 +5659,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
5659 oid_to_hex(&commit->object.oid),
5660 oneline.buf);
5661 if (is_empty)
5662 - strbuf_addf(&buf, " %c empty",
5663 - comment_line_char);
5662 + strbuf_addf(&buf, " %s empty",
5663 + comment_line_str);
5664
5665 FLEX_ALLOC_STR(entry, string, buf.buf);
5666 oidcpy(&entry->entry.oid, &commit->object.oid);
@@ -5750,7 +5750,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
5750 entry = oidmap_get(&state.commit2label, &commit->object.oid);
5751
5752 if (entry)
5753 - strbuf_addf(out, "\n%c Branch %s\n", comment_line_char, entry->string);
5753 + strbuf_addf(out, "\n%s Branch %s\n", comment_line_str, entry->string);
5754 else
5755 strbuf_addch(out, '\n');
5756
@@ -5887,7 +5887,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
5887 oid_to_hex(&commit->object.oid));
5888 pretty_print_commit(&pp, commit, out);
5889 if (is_empty)
5890 - strbuf_addf(out, " %c empty", comment_line_char);
5890 + strbuf_addf(out, " %s empty", comment_line_str);
5891 strbuf_addch(out, '\n');
5892 }
5893 if (skipped_commit)
wt-status.c
+5 -5
@@ -70,7 +70,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
70 strbuf_vaddf(&sb, fmt, ap);
71 if (!sb.len) {
72 if (s->display_comment_prefix) {
73 - strbuf_addch(&sb, comment_line_char);
73 + strbuf_addstr(&sb, comment_line_str);
74 if (!trail)
75 strbuf_addch(&sb, ' ');
76 }
@@ -85,7 +85,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
85
86 strbuf_reset(&linebuf);
87 if (at_bol && s->display_comment_prefix) {
88 - strbuf_addch(&linebuf, comment_line_char);
88 + strbuf_addstr(&linebuf, comment_line_str);
89 if (*line != '\n' && *line != '\t')
90 strbuf_addch(&linebuf, ' ');
91 }
@@ -1090,7 +1090,7 @@ size_t wt_status_locate_end(const char *s, size_t len)
1090 const char *p;
1091 struct strbuf pattern = STRBUF_INIT;
1092
1093 - strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1093 + strbuf_addf(&pattern, "\n%s %s", comment_line_str, cut_line);
1094 if (starts_with(s, pattern.buf + 1))
1095 len = 0;
1096 else if ((p = strstr(s, pattern.buf)))
@@ -1214,8 +1214,8 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
1214 "%s%.*s", comment_line_string,
1215 (int)(ep - cp), cp);
1216 if (s->display_comment_prefix)
1217 - color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
1218 - comment_line_char);
1217 + color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%s",
1218 + comment_line_str);
1219 else
1220 fputs("\n", s->fp);
1221 strbuf_release(&sb);