@matheusbsbs / matheus-bagliano / commits / 3c624a30fa
Fork 0

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>

Jonathan Nieder committed Feb 25, 2011 at 23:10 UTC 3c624a30fa3f047d401e08cf019d39b3a79095ea
1 file changed +13 -14
builtin/commit.c
+13 -14
@@ -568,7 +568,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
568 int commitable, saved_color_setting;
569 struct strbuf sb = STRBUF_INIT;
570 char *buffer;
571 - FILE *fp;
571 const char *hook_arg1 = NULL;
572 const char *hook_arg2 = NULL;
573 int ident_shown = 0;
@@ -657,8 +656,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
656 hook_arg2 = "";
657 }
658
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)
661 die_errno("could not open '%s'", git_path(commit_editmsg));
662
663 if (cleanup_mode != CLEANUP_NONE)
@@ -682,7 +681,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
681 strbuf_release(&sob);
682 }
683
685 - if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
684 + if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
685 die_errno("could not write commit template");
686
687 strbuf_release(&sb);
@@ -695,7 +694,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
694 if (use_editor && include_status) {
695 char *ai_tmp, *ci_tmp;
696 if (in_merge)
698 - fprintf(fp,
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"
@@ -704,45 +703,45 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
703 "#\n",
704 git_path("MERGE_HEAD"));
705
707 - fprintf(fp,
706 + fprintf(s->fp,
707 "\n"
708 "# Please enter the commit message for your changes.");
709 if (cleanup_mode == CLEANUP_ALL)
711 - fprintf(fp,
710 + fprintf(s->fp,
711 " Lines starting\n"
712 "# with '#' will be ignored, and an empty"
713 " message aborts the commit.\n");
714 else /* CLEANUP_SPACE, that is. */
716 - fprintf(fp,
715 + fprintf(s->fp,
716 " Lines starting\n"
717 "# with '#' will be kept; you may remove them"
718 " yourself if you want to.\n"
719 "# An empty message aborts the commit.\n");
720 if (only_include_assumed)
722 - fprintf(fp, "# %s\n", only_include_assumed);
721 + fprintf(s->fp, "# %s\n", only_include_assumed);
722
723 ai_tmp = cut_ident_timestamp_part(author_ident->buf);
724 ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
725 if (strcmp(author_ident->buf, committer_ident.buf))
727 - fprintf(fp,
726 + fprintf(s->fp,
727 "%s"
728 "# Author: %s\n",
729 ident_shown++ ? "" : "#\n",
730 author_ident->buf);
731
732 if (!user_ident_sufficiently_given())
734 - fprintf(fp,
733 + fprintf(s->fp,
734 "%s"
735 "# Committer: %s\n",
736 ident_shown++ ? "" : "#\n",
737 committer_ident.buf);
738
739 if (ident_shown)
741 - fprintf(fp, "#\n");
740 + fprintf(s->fp, "#\n");
741
742 saved_color_setting = s->use_color;
743 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);
745 s->use_color = saved_color_setting;
746
747 *ai_tmp = ' ';
@@ -764,7 +763,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
763 }
764 strbuf_release(&committer_ident);
765
767 - fclose(fp);
766 + fclose(s->fp);
767
768 if (!commitable && !in_merge && !allow_empty &&
769 !(amend && is_a_merge(head_sha1))) {