mailinfo: move cmitmsg and patchfile to struct mailinfo

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 14, 2015 at 16:16 UTC 8f63588a6e23685b8deae681c9f126158c612e97
1 file changed +16 -16
builtin/mailinfo.c
+16 -16
@@ -7,11 +7,11 @@
7 #include "utf8.h"
8 #include "strbuf.h"
9
10 -static FILE *cmitmsg, *patchfile;
11 -
10 struct mailinfo {
11 FILE *input;
12 FILE *output;
13 + FILE *cmitmsg;
14 + FILE *patchfile;
15
16 struct strbuf name;
17 struct strbuf email;
@@ -654,7 +654,7 @@ static int is_scissors_line(const struct strbuf *line)
654
655 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
656 {
657 - if (!cmitmsg)
657 + if (!mi->cmitmsg)
658 return 0;
659
660 if (mi->header_stage) {
@@ -677,9 +677,9 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
677
678 if (mi->use_scissors && is_scissors_line(line)) {
679 int i;
680 - if (fseek(cmitmsg, 0L, SEEK_SET))
680 + if (fseek(mi->cmitmsg, 0L, SEEK_SET))
681 die_errno("Could not rewind output message file");
682 - if (ftruncate(fileno(cmitmsg), 0))
682 + if (ftruncate(fileno(mi->cmitmsg), 0))
683 die_errno("Could not truncate output message file at scissors");
684 mi->header_stage = 1;
685
@@ -697,19 +697,19 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
697
698 if (patchbreak(line)) {
699 if (mi->message_id)
700 - fprintf(cmitmsg, "Message-Id: %s\n", mi->message_id);
701 - fclose(cmitmsg);
702 - cmitmsg = NULL;
700 + fprintf(mi->cmitmsg, "Message-Id: %s\n", mi->message_id);
701 + fclose(mi->cmitmsg);
702 + mi->cmitmsg = NULL;
703 return 1;
704 }
705
706 - fputs(line->buf, cmitmsg);
706 + fputs(line->buf, mi->cmitmsg);
707 return 0;
708 }
709
710 static void handle_patch(struct mailinfo *mi, const struct strbuf *line)
711 {
712 - fwrite(line->buf, 1, line->len, patchfile);
712 + fwrite(line->buf, 1, line->len, mi->patchfile);
713 mi->patch_lines++;
714 }
715
@@ -972,15 +972,15 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
972 int peek;
973 struct strbuf line = STRBUF_INIT;
974
975 - cmitmsg = fopen(msg, "w");
976 - if (!cmitmsg) {
975 + mi->cmitmsg = fopen(msg, "w");
976 + if (!mi->cmitmsg) {
977 perror(msg);
978 return -1;
979 }
980 - patchfile = fopen(patch, "w");
981 - if (!patchfile) {
980 + mi->patchfile = fopen(patch, "w");
981 + if (!mi->patchfile) {
982 perror(patch);
983 - fclose(cmitmsg);
983 + fclose(mi->cmitmsg);
984 return -1;
985 }
986
@@ -997,7 +997,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
997 check_header(mi, &line, p_hdr_data, 1);
998
999 handle_body(mi, &line);
1000 - fclose(patchfile);
1000 + fclose(mi->patchfile);
1001
1002 handle_info(mi);
1003 strbuf_release(&line);