mailinfo: move [ps]_hdr_data to struct mailinfo

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

Junio C Hamano committed Oct 14, 2015 at 17:43 UTC d895bf0f57aa162142c011c92c1bde3822323f33
1 file changed +23 -14
builtin/mailinfo.c
+23 -14
@@ -30,10 +30,10 @@ struct mailinfo {
30 int patch_lines;
31 int filter_stage; /* still reading log or are we copying patch? */
32 int header_stage; /* still checking in-body headers? */
33 + struct strbuf **p_hdr_data;
34 + struct strbuf **s_hdr_data;
35 };
36
35 -static struct strbuf **p_hdr_data, **s_hdr_data;
36 -
37 #define MAX_BOUNDARIES 5
38
39 static void cleanup_space(struct strbuf *sb)
@@ -663,7 +663,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
663 }
664
665 if (mi->use_inbody_headers && mi->header_stage) {
666 - mi->header_stage = check_header(mi, line, s_hdr_data, 0);
666 + mi->header_stage = check_header(mi, line, mi->s_hdr_data, 0);
667 if (mi->header_stage)
668 return 0;
669 } else
@@ -688,9 +688,9 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
688 * them to give ourselves a clean restart.
689 */
690 for (i = 0; header[i]; i++) {
691 - if (s_hdr_data[i])
692 - strbuf_release(s_hdr_data[i]);
693 - s_hdr_data[i] = NULL;
691 + if (mi->s_hdr_data[i])
692 + strbuf_release(mi->s_hdr_data[i]);
693 + mi->s_hdr_data[i] = NULL;
694 }
695 return 0;
696 }
@@ -840,7 +840,7 @@ again:
840
841 /* slurp in this section's info */
842 while (read_one_header_line(line, mi->input))
843 - check_header(mi, line, p_hdr_data, 0);
843 + check_header(mi, line, mi->p_hdr_data, 0);
844
845 strbuf_release(&newline);
846 /* replenish line */
@@ -941,10 +941,10 @@ static void handle_info(struct mailinfo *mi)
941
942 for (i = 0; header[i]; i++) {
943 /* only print inbody headers if we output a patch file */
944 - if (mi->patch_lines && s_hdr_data[i])
945 - hdr = s_hdr_data[i];
946 - else if (p_hdr_data[i])
947 - hdr = p_hdr_data[i];
944 + if (mi->patch_lines && mi->s_hdr_data[i])
945 + hdr = mi->s_hdr_data[i];
946 + else if (mi->p_hdr_data[i])
947 + hdr = mi->p_hdr_data[i];
948 else
949 continue;
950
@@ -984,8 +984,8 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
984 return -1;
985 }
986
987 - p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*p_hdr_data));
988 - s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data));
987 + mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data)));
988 + mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data)));
989
990 do {
991 peek = fgetc(mi->input);
@@ -994,7 +994,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
994
995 /* process the email header */
996 while (read_one_header_line(&line, mi->input))
997 - check_header(mi, &line, p_hdr_data, 1);
997 + check_header(mi, &line, mi->p_hdr_data, 1);
998
999 handle_body(mi, &line);
1000 fclose(mi->patchfile);
@@ -1031,10 +1031,19 @@ static void setup_mailinfo(struct mailinfo *mi)
1031
1032 static void clear_mailinfo(struct mailinfo *mi)
1033 {
1034 + int i;
1035 +
1036 strbuf_release(&mi->name);
1037 strbuf_release(&mi->email);
1038 strbuf_release(&mi->charset);
1039 free(mi->message_id);
1040 +
1041 + for (i = 0; mi->p_hdr_data[i]; i++)
1042 + strbuf_release(mi->p_hdr_data[i]);
1043 + free(mi->p_hdr_data);
1044 + for (i = 0; mi->s_hdr_data[i]; i++)
1045 + strbuf_release(mi->s_hdr_data[i]);
1046 + free(mi->s_hdr_data);
1047 }
1048
1049 static const char mailinfo_usage[] =