mirror of
https://github.com/git/git
synced 2024-10-30 04:01:21 +00:00
commit: refer to commit template as s->fp
Instead of maintaining a local variable for it, use s->fp to keep track of where the commit message template should be written. This prepares us to take advantage of the status_printf functions, which use a struct wt_status instead of a FILE pointer to determine where to send their output. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e0335fcdad
commit
3c624a30fa
1 changed files with 13 additions and 14 deletions
|
@ -568,7 +568,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
int commitable, saved_color_setting;
|
int commitable, saved_color_setting;
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
FILE *fp;
|
|
||||||
const char *hook_arg1 = NULL;
|
const char *hook_arg1 = NULL;
|
||||||
const char *hook_arg2 = NULL;
|
const char *hook_arg2 = NULL;
|
||||||
int ident_shown = 0;
|
int ident_shown = 0;
|
||||||
|
@ -657,8 +656,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
hook_arg2 = "";
|
hook_arg2 = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen(git_path(commit_editmsg), "w");
|
s->fp = fopen(git_path(commit_editmsg), "w");
|
||||||
if (fp == NULL)
|
if (s->fp == NULL)
|
||||||
die_errno("could not open '%s'", git_path(commit_editmsg));
|
die_errno("could not open '%s'", git_path(commit_editmsg));
|
||||||
|
|
||||||
if (cleanup_mode != CLEANUP_NONE)
|
if (cleanup_mode != CLEANUP_NONE)
|
||||||
|
@ -682,7 +681,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
strbuf_release(&sob);
|
strbuf_release(&sob);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
|
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
|
||||||
die_errno("could not write commit template");
|
die_errno("could not write commit template");
|
||||||
|
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
|
@ -695,7 +694,7 @@ 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(fp,
|
fprintf(s->fp,
|
||||||
"#\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"
|
||||||
|
@ -704,45 +703,45 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
"#\n",
|
"#\n",
|
||||||
git_path("MERGE_HEAD"));
|
git_path("MERGE_HEAD"));
|
||||||
|
|
||||||
fprintf(fp,
|
fprintf(s->fp,
|
||||||
"\n"
|
"\n"
|
||||||
"# 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(fp,
|
fprintf(s->fp,
|
||||||
" 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(fp,
|
fprintf(s->fp,
|
||||||
" 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(fp, "# %s\n", only_include_assumed);
|
fprintf(s->fp, "# %s\n", 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(fp,
|
fprintf(s->fp,
|
||||||
"%s"
|
"%s"
|
||||||
"# Author: %s\n",
|
"# Author: %s\n",
|
||||||
ident_shown++ ? "" : "#\n",
|
ident_shown++ ? "" : "#\n",
|
||||||
author_ident->buf);
|
author_ident->buf);
|
||||||
|
|
||||||
if (!user_ident_sufficiently_given())
|
if (!user_ident_sufficiently_given())
|
||||||
fprintf(fp,
|
fprintf(s->fp,
|
||||||
"%s"
|
"%s"
|
||||||
"# Committer: %s\n",
|
"# Committer: %s\n",
|
||||||
ident_shown++ ? "" : "#\n",
|
ident_shown++ ? "" : "#\n",
|
||||||
committer_ident.buf);
|
committer_ident.buf);
|
||||||
|
|
||||||
if (ident_shown)
|
if (ident_shown)
|
||||||
fprintf(fp, "#\n");
|
fprintf(s->fp, "#\n");
|
||||||
|
|
||||||
saved_color_setting = s->use_color;
|
saved_color_setting = s->use_color;
|
||||||
s->use_color = 0;
|
s->use_color = 0;
|
||||||
commitable = run_status(fp, index_file, prefix, 1, s);
|
commitable = run_status(s->fp, index_file, prefix, 1, s);
|
||||||
s->use_color = saved_color_setting;
|
s->use_color = saved_color_setting;
|
||||||
|
|
||||||
*ai_tmp = ' ';
|
*ai_tmp = ' ';
|
||||||
|
@ -764,7 +763,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
}
|
}
|
||||||
strbuf_release(&committer_ident);
|
strbuf_release(&committer_ident);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(s->fp);
|
||||||
|
|
||||||
if (!commitable && !in_merge && !allow_empty &&
|
if (!commitable && !in_merge && !allow_empty &&
|
||||||
!(amend && is_a_merge(head_sha1))) {
|
!(amend && is_a_merge(head_sha1))) {
|
||||||
|
|
Loading…
Reference in a new issue