Skip to content

Commit f99e1d9

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a1bb146 commit f99e1d9

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

add-patch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,10 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11141114
"To remove '%c' lines, make them ' ' lines "
11151115
"(context).\n"
11161116
"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"),
11181118
s->mode->is_reverse ? '+' : '-',
11191119
s->mode->is_reverse ? '-' : '+',
1120-
comment_line_char);
1120+
comment_line_str);
11211121
strbuf_commented_addf(&s->buf, comment_line_str, "%s",
11221122
_(s->mode->edit_hunk_hint));
11231123
/*

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ static int edit_branch_description(const char *branch_name)
670670
strbuf_commented_addf(&buf, comment_line_str,
671671
_("Please edit the description for the branch\n"
672672
" %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);
675675
write_file_buf(edit_description(), buf.buf, buf.len);
676676
strbuf_reset(&buf);
677677
if (launch_editor(edit_description(), &buf, NULL)) {

builtin/commit.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,18 +910,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
910910
struct ident_split ci, ai;
911911
const char *hint_cleanup_all = allow_empty_message ?
912912
_("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") :
914914
_("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"
916916
" message aborts the commit.\n");
917917
const char *hint_cleanup_space = allow_empty_message ?
918918
_("Please enter the commit message for your changes."
919919
" Lines starting\n"
920-
"with '%c' will be kept; you may remove them"
920+
"with '%s' will be kept; you may remove them"
921921
" yourself if you want to.\n") :
922922
_("Please enter the commit message for your changes."
923923
" Lines starting\n"
924-
"with '%c' will be kept; you may remove them"
924+
"with '%s' will be kept; you may remove them"
925925
" yourself if you want to.\n"
926926
"An empty message aborts the commit.\n");
927927
if (whence != FROM_COMMIT) {
@@ -945,12 +945,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
945945

946946
fprintf(s->fp, "\n");
947947
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);
949949
else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
950950
if (whence == FROM_COMMIT && !merge_contains_scissors)
951951
wt_status_add_cut_line(s->fp);
952952
} 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);
954954

955955
/*
956956
* These should never fail because they come from our own

builtin/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static const char scissors_editor_comment[] =
821821
N_("An empty message aborts the commit.\n");
822822

823823
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"
825825
"the commit.\n");
826826

827827
static void write_merge_heads(struct commit_list *);
@@ -861,7 +861,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
861861
_(scissors_editor_comment));
862862
else
863863
strbuf_commented_addf(&msg, comment_line_str,
864-
_(no_scissors_editor_comment), comment_line_char);
864+
_(no_scissors_editor_comment), comment_line_str);
865865
}
866866
if (signoff)
867867
append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0);

builtin/tag.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ static int do_sign(struct strbuf *buffer)
158158

159159
static const char tag_template[] =
160160
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");
162162

163163
static const char tag_template_nocleanup[] =
164164
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"
166166
" yourself if you want to.\n");
167167

168168
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,
292292
strbuf_addch(&buf, '\n');
293293
if (opt->cleanup_mode == CLEANUP_ALL)
294294
strbuf_commented_addf(&buf, comment_line_str,
295-
_(tag_template), tag, comment_line_char);
295+
_(tag_template), tag, comment_line_str);
296296
else
297297
strbuf_commented_addf(&buf, comment_line_str,
298-
_(tag_template_nocleanup), tag, comment_line_char);
298+
_(tag_template_nocleanup), tag, comment_line_str);
299299
write_or_die(fd, buf.buf, buf.len);
300300
strbuf_release(&buf);
301301
}

fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static void credit_people(struct strbuf *out,
321321
skip_prefix(me, them->items->string, &me) &&
322322
starts_with(me, " <")))
323323
return;
324-
strbuf_addf(out, "\n%c %s ", comment_line_char, label);
324+
strbuf_addf(out, "\n%s %s ", comment_line_str, label);
325325
add_people_count(out, them);
326326
}
327327

sequencer.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ void append_conflicts_hint(struct index_state *istate,
663663
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
664664
strbuf_addch(msgbuf, '\n');
665665
wt_status_append_cut_line(msgbuf);
666-
strbuf_addch(msgbuf, comment_line_char);
666+
strbuf_addstr(msgbuf, comment_line_str);
667667
}
668668

669669
strbuf_addch(msgbuf, '\n');
@@ -1946,7 +1946,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
19461946
(starts_with(body, "squash!") || starts_with(body, "fixup!"))))
19471947
commented_len = commit_subject_length(body);
19481948

1949-
strbuf_addf(buf, "\n%c ", comment_line_char);
1949+
strbuf_addf(buf, "\n%s ", comment_line_str);
19501950
strbuf_addf(buf, _(nth_commit_msg_fmt),
19511951
++opts->current_fixup_count + 1);
19521952
strbuf_addstr(buf, "\n\n");
@@ -2006,7 +2006,7 @@ static int update_squash_messages(struct repository *r,
20062006
eol = buf.buf[0] != comment_line_char ?
20072007
buf.buf : strchrnul(buf.buf, '\n');
20082008

2009-
strbuf_addf(&header, "%c ", comment_line_char);
2009+
strbuf_addf(&header, "%s ", comment_line_str);
20102010
strbuf_addf(&header, _(combined_commit_msg_fmt),
20112011
opts->current_fixup_count + 2);
20122012
strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
@@ -2032,9 +2032,9 @@ static int update_squash_messages(struct repository *r,
20322032
repo_unuse_commit_buffer(r, head_commit, head_message);
20332033
return error(_("cannot write '%s'"), rebase_path_fixup_msg());
20342034
}
2035-
strbuf_addf(&buf, "%c ", comment_line_char);
2035+
strbuf_addf(&buf, "%s ", comment_line_str);
20362036
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);
20382038
strbuf_addstr(&buf, is_fixup_flag(command, flag) ?
20392039
_(skip_first_commit_msg_str) :
20402040
_(first_commit_msg_str));
@@ -2056,7 +2056,7 @@ static int update_squash_messages(struct repository *r,
20562056
if (command == TODO_SQUASH || is_fixup_flag(command, flag)) {
20572057
res = append_squash_message(&buf, body, command, opts, flag);
20582058
} else if (command == TODO_FIXUP) {
2059-
strbuf_addf(&buf, "\n%c ", comment_line_char);
2059+
strbuf_addf(&buf, "\n%s ", comment_line_str);
20602060
strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
20612061
++opts->current_fixup_count + 1);
20622062
strbuf_addstr(&buf, "\n\n");
@@ -5659,8 +5659,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
56595659
oid_to_hex(&commit->object.oid),
56605660
oneline.buf);
56615661
if (is_empty)
5662-
strbuf_addf(&buf, " %c empty",
5663-
comment_line_char);
5662+
strbuf_addf(&buf, " %s empty",
5663+
comment_line_str);
56645664

56655665
FLEX_ALLOC_STR(entry, string, buf.buf);
56665666
oidcpy(&entry->entry.oid, &commit->object.oid);
@@ -5750,7 +5750,7 @@ static int make_script_with_merges(struct pretty_print_context *pp,
57505750
entry = oidmap_get(&state.commit2label, &commit->object.oid);
57515751

57525752
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);
57545754
else
57555755
strbuf_addch(out, '\n');
57565756

@@ -5887,7 +5887,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
58875887
oid_to_hex(&commit->object.oid));
58885888
pretty_print_commit(&pp, commit, out);
58895889
if (is_empty)
5890-
strbuf_addf(out, " %c empty", comment_line_char);
5890+
strbuf_addf(out, " %s empty", comment_line_str);
58915891
strbuf_addch(out, '\n');
58925892
}
58935893
if (skipped_commit)

wt-status.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
7070
strbuf_vaddf(&sb, fmt, ap);
7171
if (!sb.len) {
7272
if (s->display_comment_prefix) {
73-
strbuf_addch(&sb, comment_line_char);
73+
strbuf_addstr(&sb, comment_line_str);
7474
if (!trail)
7575
strbuf_addch(&sb, ' ');
7676
}
@@ -85,7 +85,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
8585

8686
strbuf_reset(&linebuf);
8787
if (at_bol && s->display_comment_prefix) {
88-
strbuf_addch(&linebuf, comment_line_char);
88+
strbuf_addstr(&linebuf, comment_line_str);
8989
if (*line != '\n' && *line != '\t')
9090
strbuf_addch(&linebuf, ' ');
9191
}
@@ -1090,7 +1090,7 @@ size_t wt_status_locate_end(const char *s, size_t len)
10901090
const char *p;
10911091
struct strbuf pattern = STRBUF_INIT;
10921092

1093-
strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
1093+
strbuf_addf(&pattern, "\n%s %s", comment_line_str, cut_line);
10941094
if (starts_with(s, pattern.buf + 1))
10951095
len = 0;
10961096
else if ((p = strstr(s, pattern.buf)))
@@ -1214,8 +1214,8 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
12141214
"%s%.*s", comment_line_string,
12151215
(int)(ep - cp), cp);
12161216
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);
12191219
else
12201220
fputs("\n", s->fp);
12211221
strbuf_release(&sb);

0 commit comments

Comments
 (0)