Skip to content

Commit b926c0d

Browse files
jrngitster
authored andcommitted
commit, status: use status_printf{,_ln,_more} helpers
wt-status code is used to provide a reminder of changes included and not included for the commit message template opened in the operator's text editor by "git commit". Therefore each line of its output begins with the comment character "#": # Please enter the commit message for your changes. Lines starting Use the new status_printf{,_ln,_more} functions to take care of adding "#" to the beginning of such status lines automatically. Using these will have two advantages over the current code: - The obvious one is to force separation of the "#" from the translatable part of the message when git learns to translate its output. - Another advantage is that this makes it easier for us to drop "#" prefix in "git status" output in later versions of git if we want to. Explained-by: Junio C Hamano <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37f3012 commit b926c0d

File tree

2 files changed

+67
-66
lines changed

2 files changed

+67
-66
lines changed

builtin/commit.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
694694
if (use_editor && include_status) {
695695
char *ai_tmp, *ci_tmp;
696696
if (in_merge)
697-
fprintf(s->fp,
698-
"#\n"
699-
"# It looks like you may be committing a MERGE.\n"
700-
"# If this is not correct, please remove the file\n"
701-
"# %s\n"
702-
"# and try again.\n"
703-
"#\n",
697+
status_printf_ln(s, GIT_COLOR_NORMAL,
698+
"\n"
699+
"It looks like you may be committing a MERGE.\n"
700+
"If this is not correct, please remove the file\n"
701+
" %s\n"
702+
"and try again.\n"
703+
"",
704704
git_path("MERGE_HEAD"));
705705

706-
fprintf(s->fp,
707-
"\n"
708-
"# Please enter the commit message for your changes.");
706+
fprintf(s->fp, "\n");
707+
status_printf(s, GIT_COLOR_NORMAL,
708+
"Please enter the commit message for your changes.");
709709
if (cleanup_mode == CLEANUP_ALL)
710-
fprintf(s->fp,
710+
status_printf_more(s, GIT_COLOR_NORMAL,
711711
" Lines starting\n"
712-
"# with '#' will be ignored, and an empty"
712+
"with '#' will be ignored, and an empty"
713713
" message aborts the commit.\n");
714714
else /* CLEANUP_SPACE, that is. */
715-
fprintf(s->fp,
715+
status_printf_more(s, GIT_COLOR_NORMAL,
716716
" Lines starting\n"
717-
"# with '#' will be kept; you may remove them"
717+
"with '#' will be kept; you may remove them"
718718
" yourself if you want to.\n"
719-
"# An empty message aborts the commit.\n");
719+
"An empty message aborts the commit.\n");
720720
if (only_include_assumed)
721-
fprintf(s->fp, "# %s\n", only_include_assumed);
721+
status_printf_ln(s, GIT_COLOR_NORMAL,
722+
"%s", only_include_assumed);
722723

723724
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
724725
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
725726
if (strcmp(author_ident->buf, committer_ident.buf))
726-
fprintf(s->fp,
727+
status_printf_ln(s, GIT_COLOR_NORMAL,
727728
"%s"
728-
"# Author: %s\n",
729-
ident_shown++ ? "" : "#\n",
729+
"Author: %s",
730+
ident_shown++ ? "" : "\n",
730731
author_ident->buf);
731732

732733
if (!user_ident_sufficiently_given())
733-
fprintf(s->fp,
734+
status_printf_ln(s, GIT_COLOR_NORMAL,
734735
"%s"
735-
"# Committer: %s\n",
736-
ident_shown++ ? "" : "#\n",
736+
"Committer: %s",
737+
ident_shown++ ? "" : "\n",
737738
committer_ident.buf);
738739

739740
if (ident_shown)
740-
fprintf(s->fp, "#\n");
741+
status_printf_ln(s, GIT_COLOR_NORMAL, "");
741742

742743
saved_color_setting = s->use_color;
743744
s->use_color = 0;

wt-status.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
131131
{
132132
const char *c = color(WT_STATUS_HEADER, s);
133133

134-
color_fprintf_ln(s->fp, c, "# Unmerged paths:");
134+
status_printf_ln(s, c, "Unmerged paths:");
135135
if (!advice_status_hints)
136136
return;
137137
if (s->in_merge)
138138
;
139139
else if (!s->is_initial)
140-
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
140+
status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
141141
else
142-
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
143-
color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" as appropriate to mark resolution)");
144-
color_fprintf_ln(s->fp, c, "#");
142+
status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
143+
status_printf_ln(s, c, " (use \"git add/rm <file>...\" as appropriate to mark resolution)");
144+
status_printf_ln(s, c, "");
145145
}
146146

147147
static void wt_status_print_cached_header(struct wt_status *s)
148148
{
149149
const char *c = color(WT_STATUS_HEADER, s);
150150

151-
color_fprintf_ln(s->fp, c, "# Changes to be committed:");
151+
status_printf_ln(s, c, "Changes to be committed:");
152152
if (!advice_status_hints)
153153
return;
154154
if (s->in_merge)
155155
; /* NEEDSWORK: use "git reset --unresolve"??? */
156156
else if (!s->is_initial)
157-
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
157+
status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
158158
else
159-
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
160-
color_fprintf_ln(s->fp, c, "#");
159+
status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
160+
status_printf_ln(s, c, "");
161161
}
162162

163163
static void wt_status_print_dirty_header(struct wt_status *s,
@@ -166,34 +166,34 @@ static void wt_status_print_dirty_header(struct wt_status *s,
166166
{
167167
const char *c = color(WT_STATUS_HEADER, s);
168168

169-
color_fprintf_ln(s->fp, c, "# Changes not staged for commit:");
169+
status_printf_ln(s, c, "Changes not staged for commit:");
170170
if (!advice_status_hints)
171171
return;
172172
if (!has_deleted)
173-
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
173+
status_printf_ln(s, c, " (use \"git add <file>...\" to update what will be committed)");
174174
else
175-
color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
176-
color_fprintf_ln(s->fp, c, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
175+
status_printf_ln(s, c, " (use \"git add/rm <file>...\" to update what will be committed)");
176+
status_printf_ln(s, c, " (use \"git checkout -- <file>...\" to discard changes in working directory)");
177177
if (has_dirty_submodules)
178-
color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)");
179-
color_fprintf_ln(s->fp, c, "#");
178+
status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)");
179+
status_printf_ln(s, c, "");
180180
}
181181

182182
static void wt_status_print_other_header(struct wt_status *s,
183183
const char *what,
184184
const char *how)
185185
{
186186
const char *c = color(WT_STATUS_HEADER, s);
187-
color_fprintf_ln(s->fp, c, "# %s files:", what);
187+
status_printf_ln(s, c, "%s files:", what);
188188
if (!advice_status_hints)
189189
return;
190-
color_fprintf_ln(s->fp, c, "# (use \"git %s <file>...\" to include in what will be committed)", how);
191-
color_fprintf_ln(s->fp, c, "#");
190+
status_printf_ln(s, c, " (use \"git %s <file>...\" to include in what will be committed)", how);
191+
status_printf_ln(s, c, "");
192192
}
193193

194194
static void wt_status_print_trailer(struct wt_status *s)
195195
{
196-
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
196+
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
197197
}
198198

199199
#define quote_path quote_path_relative
@@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
207207
const char *one, *how = "bug";
208208

209209
one = quote_path(it->string, -1, &onebuf, s->prefix);
210-
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
210+
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
211211
switch (d->stagemask) {
212212
case 1: how = "both deleted:"; break;
213213
case 2: how = "added by us:"; break;
@@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
217217
case 6: how = "both added:"; break;
218218
case 7: how = "both modified:"; break;
219219
}
220-
color_fprintf(s->fp, c, "%-20s%s\n", how, one);
220+
status_printf_more(s, c, "%-20s%s\n", how, one);
221221
strbuf_release(&onebuf);
222222
}
223223

@@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s,
260260
one = quote_path(one_name, -1, &onebuf, s->prefix);
261261
two = quote_path(two_name, -1, &twobuf, s->prefix);
262262

263-
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
263+
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
264264
switch (status) {
265265
case DIFF_STATUS_ADDED:
266-
color_fprintf(s->fp, c, "new file: %s", one);
266+
status_printf_more(s, c, "new file: %s", one);
267267
break;
268268
case DIFF_STATUS_COPIED:
269-
color_fprintf(s->fp, c, "copied: %s -> %s", one, two);
269+
status_printf_more(s, c, "copied: %s -> %s", one, two);
270270
break;
271271
case DIFF_STATUS_DELETED:
272-
color_fprintf(s->fp, c, "deleted: %s", one);
272+
status_printf_more(s, c, "deleted: %s", one);
273273
break;
274274
case DIFF_STATUS_MODIFIED:
275-
color_fprintf(s->fp, c, "modified: %s", one);
275+
status_printf_more(s, c, "modified: %s", one);
276276
break;
277277
case DIFF_STATUS_RENAMED:
278-
color_fprintf(s->fp, c, "renamed: %s -> %s", one, two);
278+
status_printf_more(s, c, "renamed: %s -> %s", one, two);
279279
break;
280280
case DIFF_STATUS_TYPE_CHANGED:
281-
color_fprintf(s->fp, c, "typechange: %s", one);
281+
status_printf_more(s, c, "typechange: %s", one);
282282
break;
283283
case DIFF_STATUS_UNKNOWN:
284-
color_fprintf(s->fp, c, "unknown: %s", one);
284+
status_printf_more(s, c, "unknown: %s", one);
285285
break;
286286
case DIFF_STATUS_UNMERGED:
287-
color_fprintf(s->fp, c, "unmerged: %s", one);
287+
status_printf_more(s, c, "unmerged: %s", one);
288288
break;
289289
default:
290290
die("bug: unhandled diff status %c", status);
291291
}
292292
if (extra.len) {
293-
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
293+
status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
294294
strbuf_release(&extra);
295295
}
296-
fprintf(s->fp, "\n");
296+
status_printf_more(s, GIT_COLOR_NORMAL, "\n");
297297
strbuf_release(&onebuf);
298298
strbuf_release(&twobuf);
299299
}
@@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s,
647647
for (i = 0; i < l->nr; i++) {
648648
struct string_list_item *it;
649649
it = &(l->items[i]);
650-
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
651-
color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
652-
quote_path(it->string, strlen(it->string),
650+
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
651+
status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
652+
"%s\n", quote_path(it->string, strlen(it->string),
653653
&buf, s->prefix));
654654
}
655655
strbuf_release(&buf);
@@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s)
716716
branch_status_color = color(WT_STATUS_NOBRANCH, s);
717717
on_what = "Not currently on any branch.";
718718
}
719-
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
720-
color_fprintf(s->fp, branch_status_color, "%s", on_what);
721-
color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
719+
status_printf(s, color(WT_STATUS_HEADER, s), "");
720+
status_printf_more(s, branch_status_color, "%s", on_what);
721+
status_printf_more(s, branch_color, "%s\n", branch_name);
722722
if (!s->is_initial)
723723
wt_status_print_tracking(s);
724724
}
725725

726726
if (s->is_initial) {
727-
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
728-
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
729-
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
727+
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
728+
status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit");
729+
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
730730
}
731731

732732
wt_status_print_updated(s);
@@ -743,15 +743,15 @@ void wt_status_print(struct wt_status *s)
743743
if (s->show_ignored_files)
744744
wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
745745
} else if (s->commitable)
746-
fprintf(s->fp, "# Untracked files not listed%s\n",
746+
status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s",
747747
advice_status_hints
748748
? " (use -u option to show untracked files)" : "");
749749

750750
if (s->verbose)
751751
wt_status_print_verbose(s);
752752
if (!s->commitable) {
753753
if (s->amend)
754-
fprintf(s->fp, "# No changes\n");
754+
status_printf_ln(s, GIT_COLOR_NORMAL, "No changes");
755755
else if (s->nowarn)
756756
; /* nothing */
757757
else if (s->workdir_dirty)

0 commit comments

Comments
 (0)