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 <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
37f3012ff2
commit
b926c0d10d
@ -694,50 +694,51 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||||||
if (use_editor && include_status) {
|
if (use_editor && include_status) {
|
||||||
char *ai_tmp, *ci_tmp;
|
char *ai_tmp, *ci_tmp;
|
||||||
if (in_merge)
|
if (in_merge)
|
||||||
fprintf(s->fp,
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||||
"#\n"
|
"\n"
|
||||||
"# It looks like you may be committing a MERGE.\n"
|
"It looks like you may be committing a MERGE.\n"
|
||||||
"# If this is not correct, please remove the file\n"
|
"If this is not correct, please remove the file\n"
|
||||||
"# %s\n"
|
" %s\n"
|
||||||
"# and try again.\n"
|
"and try again.\n"
|
||||||
"#\n",
|
"",
|
||||||
git_path("MERGE_HEAD"));
|
git_path("MERGE_HEAD"));
|
||||||
|
|
||||||
fprintf(s->fp,
|
fprintf(s->fp, "\n");
|
||||||
"\n"
|
status_printf(s, GIT_COLOR_NORMAL,
|
||||||
"# Please enter the commit message for your changes.");
|
"Please enter the commit message for your changes.");
|
||||||
if (cleanup_mode == CLEANUP_ALL)
|
if (cleanup_mode == CLEANUP_ALL)
|
||||||
fprintf(s->fp,
|
status_printf_more(s, GIT_COLOR_NORMAL,
|
||||||
" Lines starting\n"
|
" Lines starting\n"
|
||||||
"# with '#' will be ignored, and an empty"
|
"with '#' will be ignored, and an empty"
|
||||||
" message aborts the commit.\n");
|
" message aborts the commit.\n");
|
||||||
else /* CLEANUP_SPACE, that is. */
|
else /* CLEANUP_SPACE, that is. */
|
||||||
fprintf(s->fp,
|
status_printf_more(s, GIT_COLOR_NORMAL,
|
||||||
" Lines starting\n"
|
" Lines starting\n"
|
||||||
"# with '#' will be kept; you may remove them"
|
"with '#' will be kept; you may remove them"
|
||||||
" yourself if you want to.\n"
|
" yourself if you want to.\n"
|
||||||
"# An empty message aborts the commit.\n");
|
"An empty message aborts the commit.\n");
|
||||||
if (only_include_assumed)
|
if (only_include_assumed)
|
||||||
fprintf(s->fp, "# %s\n", only_include_assumed);
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||||
|
"%s", only_include_assumed);
|
||||||
|
|
||||||
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
|
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
|
||||||
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
|
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
|
||||||
if (strcmp(author_ident->buf, committer_ident.buf))
|
if (strcmp(author_ident->buf, committer_ident.buf))
|
||||||
fprintf(s->fp,
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||||
"%s"
|
"%s"
|
||||||
"# Author: %s\n",
|
"Author: %s",
|
||||||
ident_shown++ ? "" : "#\n",
|
ident_shown++ ? "" : "\n",
|
||||||
author_ident->buf);
|
author_ident->buf);
|
||||||
|
|
||||||
if (!user_ident_sufficiently_given())
|
if (!user_ident_sufficiently_given())
|
||||||
fprintf(s->fp,
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||||
"%s"
|
"%s"
|
||||||
"# Committer: %s\n",
|
"Committer: %s",
|
||||||
ident_shown++ ? "" : "#\n",
|
ident_shown++ ? "" : "\n",
|
||||||
committer_ident.buf);
|
committer_ident.buf);
|
||||||
|
|
||||||
if (ident_shown)
|
if (ident_shown)
|
||||||
fprintf(s->fp, "#\n");
|
status_printf_ln(s, GIT_COLOR_NORMAL, "");
|
||||||
|
|
||||||
saved_color_setting = s->use_color;
|
saved_color_setting = s->use_color;
|
||||||
s->use_color = 0;
|
s->use_color = 0;
|
||||||
|
86
wt-status.c
86
wt-status.c
@ -131,33 +131,33 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
|
|||||||
{
|
{
|
||||||
const char *c = color(WT_STATUS_HEADER, s);
|
const char *c = color(WT_STATUS_HEADER, s);
|
||||||
|
|
||||||
color_fprintf_ln(s->fp, c, "# Unmerged paths:");
|
status_printf_ln(s, c, "Unmerged paths:");
|
||||||
if (!advice_status_hints)
|
if (!advice_status_hints)
|
||||||
return;
|
return;
|
||||||
if (s->in_merge)
|
if (s->in_merge)
|
||||||
;
|
;
|
||||||
else if (!s->is_initial)
|
else if (!s->is_initial)
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
|
status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
|
||||||
else
|
else
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
|
status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" as appropriate to mark resolution)");
|
status_printf_ln(s, c, " (use \"git add/rm <file>...\" as appropriate to mark resolution)");
|
||||||
color_fprintf_ln(s->fp, c, "#");
|
status_printf_ln(s, c, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_print_cached_header(struct wt_status *s)
|
static void wt_status_print_cached_header(struct wt_status *s)
|
||||||
{
|
{
|
||||||
const char *c = color(WT_STATUS_HEADER, s);
|
const char *c = color(WT_STATUS_HEADER, s);
|
||||||
|
|
||||||
color_fprintf_ln(s->fp, c, "# Changes to be committed:");
|
status_printf_ln(s, c, "Changes to be committed:");
|
||||||
if (!advice_status_hints)
|
if (!advice_status_hints)
|
||||||
return;
|
return;
|
||||||
if (s->in_merge)
|
if (s->in_merge)
|
||||||
; /* NEEDSWORK: use "git reset --unresolve"??? */
|
; /* NEEDSWORK: use "git reset --unresolve"??? */
|
||||||
else if (!s->is_initial)
|
else if (!s->is_initial)
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
|
status_printf_ln(s, c, " (use \"git reset %s <file>...\" to unstage)", s->reference);
|
||||||
else
|
else
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
|
status_printf_ln(s, c, " (use \"git rm --cached <file>...\" to unstage)");
|
||||||
color_fprintf_ln(s->fp, c, "#");
|
status_printf_ln(s, c, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_print_dirty_header(struct wt_status *s,
|
static void wt_status_print_dirty_header(struct wt_status *s,
|
||||||
@ -166,17 +166,17 @@ static void wt_status_print_dirty_header(struct wt_status *s,
|
|||||||
{
|
{
|
||||||
const char *c = color(WT_STATUS_HEADER, s);
|
const char *c = color(WT_STATUS_HEADER, s);
|
||||||
|
|
||||||
color_fprintf_ln(s->fp, c, "# Changes not staged for commit:");
|
status_printf_ln(s, c, "Changes not staged for commit:");
|
||||||
if (!advice_status_hints)
|
if (!advice_status_hints)
|
||||||
return;
|
return;
|
||||||
if (!has_deleted)
|
if (!has_deleted)
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
|
status_printf_ln(s, c, " (use \"git add <file>...\" to update what will be committed)");
|
||||||
else
|
else
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
|
status_printf_ln(s, c, " (use \"git add/rm <file>...\" to update what will be committed)");
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
|
status_printf_ln(s, c, " (use \"git checkout -- <file>...\" to discard changes in working directory)");
|
||||||
if (has_dirty_submodules)
|
if (has_dirty_submodules)
|
||||||
color_fprintf_ln(s->fp, c, "# (commit or discard the untracked or modified content in submodules)");
|
status_printf_ln(s, c, " (commit or discard the untracked or modified content in submodules)");
|
||||||
color_fprintf_ln(s->fp, c, "#");
|
status_printf_ln(s, c, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_print_other_header(struct wt_status *s,
|
static void wt_status_print_other_header(struct wt_status *s,
|
||||||
@ -184,16 +184,16 @@ static void wt_status_print_other_header(struct wt_status *s,
|
|||||||
const char *how)
|
const char *how)
|
||||||
{
|
{
|
||||||
const char *c = color(WT_STATUS_HEADER, s);
|
const char *c = color(WT_STATUS_HEADER, s);
|
||||||
color_fprintf_ln(s->fp, c, "# %s files:", what);
|
status_printf_ln(s, c, "%s files:", what);
|
||||||
if (!advice_status_hints)
|
if (!advice_status_hints)
|
||||||
return;
|
return;
|
||||||
color_fprintf_ln(s->fp, c, "# (use \"git %s <file>...\" to include in what will be committed)", how);
|
status_printf_ln(s, c, " (use \"git %s <file>...\" to include in what will be committed)", how);
|
||||||
color_fprintf_ln(s->fp, c, "#");
|
status_printf_ln(s, c, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_print_trailer(struct wt_status *s)
|
static void wt_status_print_trailer(struct wt_status *s)
|
||||||
{
|
{
|
||||||
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
|
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define quote_path quote_path_relative
|
#define quote_path quote_path_relative
|
||||||
@ -207,7 +207,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
|
|||||||
const char *one, *how = "bug";
|
const char *one, *how = "bug";
|
||||||
|
|
||||||
one = quote_path(it->string, -1, &onebuf, s->prefix);
|
one = quote_path(it->string, -1, &onebuf, s->prefix);
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
|
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
|
||||||
switch (d->stagemask) {
|
switch (d->stagemask) {
|
||||||
case 1: how = "both deleted:"; break;
|
case 1: how = "both deleted:"; break;
|
||||||
case 2: how = "added by us:"; break;
|
case 2: how = "added by us:"; break;
|
||||||
@ -217,7 +217,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
|
|||||||
case 6: how = "both added:"; break;
|
case 6: how = "both added:"; break;
|
||||||
case 7: how = "both modified:"; break;
|
case 7: how = "both modified:"; break;
|
||||||
}
|
}
|
||||||
color_fprintf(s->fp, c, "%-20s%s\n", how, one);
|
status_printf_more(s, c, "%-20s%s\n", how, one);
|
||||||
strbuf_release(&onebuf);
|
strbuf_release(&onebuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,40 +260,40 @@ static void wt_status_print_change_data(struct wt_status *s,
|
|||||||
one = quote_path(one_name, -1, &onebuf, s->prefix);
|
one = quote_path(one_name, -1, &onebuf, s->prefix);
|
||||||
two = quote_path(two_name, -1, &twobuf, s->prefix);
|
two = quote_path(two_name, -1, &twobuf, s->prefix);
|
||||||
|
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
|
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DIFF_STATUS_ADDED:
|
case DIFF_STATUS_ADDED:
|
||||||
color_fprintf(s->fp, c, "new file: %s", one);
|
status_printf_more(s, c, "new file: %s", one);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_COPIED:
|
case DIFF_STATUS_COPIED:
|
||||||
color_fprintf(s->fp, c, "copied: %s -> %s", one, two);
|
status_printf_more(s, c, "copied: %s -> %s", one, two);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_DELETED:
|
case DIFF_STATUS_DELETED:
|
||||||
color_fprintf(s->fp, c, "deleted: %s", one);
|
status_printf_more(s, c, "deleted: %s", one);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_MODIFIED:
|
case DIFF_STATUS_MODIFIED:
|
||||||
color_fprintf(s->fp, c, "modified: %s", one);
|
status_printf_more(s, c, "modified: %s", one);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_RENAMED:
|
case DIFF_STATUS_RENAMED:
|
||||||
color_fprintf(s->fp, c, "renamed: %s -> %s", one, two);
|
status_printf_more(s, c, "renamed: %s -> %s", one, two);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_TYPE_CHANGED:
|
case DIFF_STATUS_TYPE_CHANGED:
|
||||||
color_fprintf(s->fp, c, "typechange: %s", one);
|
status_printf_more(s, c, "typechange: %s", one);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_UNKNOWN:
|
case DIFF_STATUS_UNKNOWN:
|
||||||
color_fprintf(s->fp, c, "unknown: %s", one);
|
status_printf_more(s, c, "unknown: %s", one);
|
||||||
break;
|
break;
|
||||||
case DIFF_STATUS_UNMERGED:
|
case DIFF_STATUS_UNMERGED:
|
||||||
color_fprintf(s->fp, c, "unmerged: %s", one);
|
status_printf_more(s, c, "unmerged: %s", one);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("bug: unhandled diff status %c", status);
|
die("bug: unhandled diff status %c", status);
|
||||||
}
|
}
|
||||||
if (extra.len) {
|
if (extra.len) {
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
|
status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
|
||||||
strbuf_release(&extra);
|
strbuf_release(&extra);
|
||||||
}
|
}
|
||||||
fprintf(s->fp, "\n");
|
status_printf_more(s, GIT_COLOR_NORMAL, "\n");
|
||||||
strbuf_release(&onebuf);
|
strbuf_release(&onebuf);
|
||||||
strbuf_release(&twobuf);
|
strbuf_release(&twobuf);
|
||||||
}
|
}
|
||||||
@ -647,9 +647,9 @@ static void wt_status_print_other(struct wt_status *s,
|
|||||||
for (i = 0; i < l->nr; i++) {
|
for (i = 0; i < l->nr; i++) {
|
||||||
struct string_list_item *it;
|
struct string_list_item *it;
|
||||||
it = &(l->items[i]);
|
it = &(l->items[i]);
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
|
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
|
||||||
color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
|
status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
|
||||||
quote_path(it->string, strlen(it->string),
|
"%s\n", quote_path(it->string, strlen(it->string),
|
||||||
&buf, s->prefix));
|
&buf, s->prefix));
|
||||||
}
|
}
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
@ -716,17 +716,17 @@ void wt_status_print(struct wt_status *s)
|
|||||||
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
||||||
on_what = "Not currently on any branch.";
|
on_what = "Not currently on any branch.";
|
||||||
}
|
}
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
|
status_printf(s, color(WT_STATUS_HEADER, s), "");
|
||||||
color_fprintf(s->fp, branch_status_color, "%s", on_what);
|
status_printf_more(s, branch_status_color, "%s", on_what);
|
||||||
color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
|
status_printf_more(s, branch_color, "%s\n", branch_name);
|
||||||
if (!s->is_initial)
|
if (!s->is_initial)
|
||||||
wt_status_print_tracking(s);
|
wt_status_print_tracking(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->is_initial) {
|
if (s->is_initial) {
|
||||||
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
|
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
|
||||||
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
|
status_printf_ln(s, color(WT_STATUS_HEADER, s), "Initial commit");
|
||||||
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
|
status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
wt_status_print_updated(s);
|
wt_status_print_updated(s);
|
||||||
@ -743,7 +743,7 @@ void wt_status_print(struct wt_status *s)
|
|||||||
if (s->show_ignored_files)
|
if (s->show_ignored_files)
|
||||||
wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
|
wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
|
||||||
} else if (s->commitable)
|
} else if (s->commitable)
|
||||||
fprintf(s->fp, "# Untracked files not listed%s\n",
|
status_printf_ln(s, GIT_COLOR_NORMAL, "Untracked files not listed%s",
|
||||||
advice_status_hints
|
advice_status_hints
|
||||||
? " (use -u option to show untracked files)" : "");
|
? " (use -u option to show untracked files)" : "");
|
||||||
|
|
||||||
@ -751,7 +751,7 @@ void wt_status_print(struct wt_status *s)
|
|||||||
wt_status_print_verbose(s);
|
wt_status_print_verbose(s);
|
||||||
if (!s->commitable) {
|
if (!s->commitable) {
|
||||||
if (s->amend)
|
if (s->amend)
|
||||||
fprintf(s->fp, "# No changes\n");
|
status_printf_ln(s, GIT_COLOR_NORMAL, "No changes");
|
||||||
else if (s->nowarn)
|
else if (s->nowarn)
|
||||||
; /* nothing */
|
; /* nothing */
|
||||||
else if (s->workdir_dirty)
|
else if (s->workdir_dirty)
|
||||||
|
Reference in New Issue
Block a user