Skip to content

Commit 3c624a3

Browse files
jrngitster
authored andcommitted
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>
1 parent e0335fc commit 3c624a3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

builtin/commit.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
568568
int commitable, saved_color_setting;
569569
struct strbuf sb = STRBUF_INIT;
570570
char *buffer;
571-
FILE *fp;
572571
const char *hook_arg1 = NULL;
573572
const char *hook_arg2 = NULL;
574573
int ident_shown = 0;
@@ -657,8 +656,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
657656
hook_arg2 = "";
658657
}
659658

660-
fp = fopen(git_path(commit_editmsg), "w");
661-
if (fp == NULL)
659+
s->fp = fopen(git_path(commit_editmsg), "w");
660+
if (s->fp == NULL)
662661
die_errno("could not open '%s'", git_path(commit_editmsg));
663662

664663
if (cleanup_mode != CLEANUP_NONE)
@@ -682,7 +681,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
682681
strbuf_release(&sob);
683682
}
684683

685-
if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
684+
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
686685
die_errno("could not write commit template");
687686

688687
strbuf_release(&sb);
@@ -695,7 +694,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
695694
if (use_editor && include_status) {
696695
char *ai_tmp, *ci_tmp;
697696
if (in_merge)
698-
fprintf(fp,
697+
fprintf(s->fp,
699698
"#\n"
700699
"# It looks like you may be committing a MERGE.\n"
701700
"# 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,
704703
"#\n",
705704
git_path("MERGE_HEAD"));
706705

707-
fprintf(fp,
706+
fprintf(s->fp,
708707
"\n"
709708
"# Please enter the commit message for your changes.");
710709
if (cleanup_mode == CLEANUP_ALL)
711-
fprintf(fp,
710+
fprintf(s->fp,
712711
" Lines starting\n"
713712
"# with '#' will be ignored, and an empty"
714713
" message aborts the commit.\n");
715714
else /* CLEANUP_SPACE, that is. */
716-
fprintf(fp,
715+
fprintf(s->fp,
717716
" Lines starting\n"
718717
"# with '#' will be kept; you may remove them"
719718
" yourself if you want to.\n"
720719
"# An empty message aborts the commit.\n");
721720
if (only_include_assumed)
722-
fprintf(fp, "# %s\n", only_include_assumed);
721+
fprintf(s->fp, "# %s\n", only_include_assumed);
723722

724723
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
725724
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
726725
if (strcmp(author_ident->buf, committer_ident.buf))
727-
fprintf(fp,
726+
fprintf(s->fp,
728727
"%s"
729728
"# Author: %s\n",
730729
ident_shown++ ? "" : "#\n",
731730
author_ident->buf);
732731

733732
if (!user_ident_sufficiently_given())
734-
fprintf(fp,
733+
fprintf(s->fp,
735734
"%s"
736735
"# Committer: %s\n",
737736
ident_shown++ ? "" : "#\n",
738737
committer_ident.buf);
739738

740739
if (ident_shown)
741-
fprintf(fp, "#\n");
740+
fprintf(s->fp, "#\n");
742741

743742
saved_color_setting = s->use_color;
744743
s->use_color = 0;
745-
commitable = run_status(fp, index_file, prefix, 1, s);
744+
commitable = run_status(s->fp, index_file, prefix, 1, s);
746745
s->use_color = saved_color_setting;
747746

748747
*ai_tmp = ' ';
@@ -764,7 +763,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
764763
}
765764
strbuf_release(&committer_ident);
766765

767-
fclose(fp);
766+
fclose(s->fp);
768767

769768
if (!commitable && !in_merge && !allow_empty &&
770769
!(amend && is_a_merge(head_sha1))) {

0 commit comments

Comments
 (0)