Skip to content

Commit f4784b3

Browse files
committed
Merge branch 'jn/status-translatable'
* jn/status-translatable: commit, status: use status_printf{,_ln,_more} helpers commit: refer to commit template as s->fp wt-status: add helpers for printing wt-status lines Conflicts: builtin/commit.c
2 parents 0d7f242 + b926c0d commit f4784b3

File tree

5 files changed

+166
-72
lines changed

5 files changed

+166
-72
lines changed

builtin/commit.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
612612
int commitable, saved_color_setting;
613613
struct strbuf sb = STRBUF_INIT;
614614
char *buffer;
615-
FILE *fp;
616615
const char *hook_arg1 = NULL;
617616
const char *hook_arg2 = NULL;
618617
int ident_shown = 0;
@@ -705,8 +704,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
705704
hook_arg2 = "";
706705
}
707706

708-
fp = fopen(git_path(commit_editmsg), "w");
709-
if (fp == NULL)
707+
s->fp = fopen(git_path(commit_editmsg), "w");
708+
if (s->fp == NULL)
710709
die_errno("could not open '%s'", git_path(commit_editmsg));
711710

712711
if (cleanup_mode != CLEANUP_NONE)
@@ -730,7 +729,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
730729
strbuf_release(&sob);
731730
}
732731

733-
if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
732+
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
734733
die_errno("could not write commit template");
735734

736735
strbuf_release(&sb);
@@ -743,56 +742,58 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
743742
if (use_editor && include_status) {
744743
char *ai_tmp, *ci_tmp;
745744
if (whence != FROM_COMMIT)
746-
fprintf(fp,
747-
"#\n"
748-
"# It looks like you may be committing a %s.\n"
749-
"# If this is not correct, please remove the file\n"
750-
"# %s\n"
751-
"# and try again.\n"
752-
"#\n",
745+
status_printf_ln(s, GIT_COLOR_NORMAL,
746+
"\n"
747+
"It looks like you may be committing a %s.\n"
748+
"If this is not correct, please remove the file\n"
749+
" %s\n"
750+
"and try again.\n"
751+
"",
753752
whence_s(),
754753
git_path(whence == FROM_MERGE
755754
? "MERGE_HEAD"
756755
: "CHERRY_PICK_HEAD"));
757-
fprintf(fp,
758-
"\n"
759-
"# Please enter the commit message for your changes.");
756+
757+
fprintf(s->fp, "\n");
758+
status_printf(s, GIT_COLOR_NORMAL,
759+
"Please enter the commit message for your changes.");
760760
if (cleanup_mode == CLEANUP_ALL)
761-
fprintf(fp,
761+
status_printf_more(s, GIT_COLOR_NORMAL,
762762
" Lines starting\n"
763-
"# with '#' will be ignored, and an empty"
763+
"with '#' will be ignored, and an empty"
764764
" message aborts the commit.\n");
765765
else /* CLEANUP_SPACE, that is. */
766-
fprintf(fp,
766+
status_printf_more(s, GIT_COLOR_NORMAL,
767767
" Lines starting\n"
768-
"# with '#' will be kept; you may remove them"
768+
"with '#' will be kept; you may remove them"
769769
" yourself if you want to.\n"
770-
"# An empty message aborts the commit.\n");
770+
"An empty message aborts the commit.\n");
771771
if (only_include_assumed)
772-
fprintf(fp, "# %s\n", only_include_assumed);
772+
status_printf_ln(s, GIT_COLOR_NORMAL,
773+
"%s", only_include_assumed);
773774

774775
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
775776
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
776777
if (strcmp(author_ident->buf, committer_ident.buf))
777-
fprintf(fp,
778+
status_printf_ln(s, GIT_COLOR_NORMAL,
778779
"%s"
779-
"# Author: %s\n",
780-
ident_shown++ ? "" : "#\n",
780+
"Author: %s",
781+
ident_shown++ ? "" : "\n",
781782
author_ident->buf);
782783

783784
if (!user_ident_sufficiently_given())
784-
fprintf(fp,
785+
status_printf_ln(s, GIT_COLOR_NORMAL,
785786
"%s"
786-
"# Committer: %s\n",
787-
ident_shown++ ? "" : "#\n",
787+
"Committer: %s",
788+
ident_shown++ ? "" : "\n",
788789
committer_ident.buf);
789790

790791
if (ident_shown)
791-
fprintf(fp, "#\n");
792+
status_printf_ln(s, GIT_COLOR_NORMAL, "");
792793

793794
saved_color_setting = s->use_color;
794795
s->use_color = 0;
795-
commitable = run_status(fp, index_file, prefix, 1, s);
796+
commitable = run_status(s->fp, index_file, prefix, 1, s);
796797
s->use_color = saved_color_setting;
797798

798799
*ai_tmp = ' ';
@@ -814,7 +815,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
814815
}
815816
strbuf_release(&committer_ident);
816817

817-
fclose(fp);
818+
fclose(s->fp);
818819

819820
/*
820821
* Reject an attempt to record a non-merge empty commit without

color.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ int git_color_default_config(const char *var, const char *value, void *cb)
175175
return git_default_config(var, value, cb);
176176
}
177177

178+
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
179+
{
180+
if (*color)
181+
fprintf(fp, "%s", color);
182+
fprintf(fp, "%s", sb->buf);
183+
if (*color)
184+
fprintf(fp, "%s", GIT_COLOR_RESET);
185+
}
186+
178187
static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
179188
va_list args, const char *trail)
180189
{

color.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef COLOR_H
22
#define COLOR_H
33

4+
struct strbuf;
5+
46
/* 2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */
57
/* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */
68
/*
@@ -64,6 +66,7 @@ __attribute__((format (printf, 3, 4)))
6466
int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
6567
__attribute__((format (printf, 3, 4)))
6668
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
69+
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb);
6770

6871
int color_is_nil(const char *color);
6972

0 commit comments

Comments
 (0)