mailinfo: move add_message_id and message_id to struct mailinfo

This requires us to pass the structure into check_header() codepath. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 18, 2015 at 22:27 UTC 6200b751bb83d3ea982774e479ad6674c9e84b0a
1 file changed +17 -14
builtin/mailinfo.c
+17 -14
@@ -19,12 +19,13 @@ struct mailinfo {
19 struct strbuf email;
20 int keep_subject;
21 int keep_non_patch_brackets_in_subject;
22 + int add_message_id;
23
24 + char *message_id;
25 int patch_lines;
26 int filter_stage; /* still reading log or are we copying patch? */
27 int header_stage; /* still checking in-body headers? */
28 };
27 -static char *message_id;
29
30 static enum {
31 TE_DONTCARE, TE_QP, TE_BASE64
@@ -33,7 +34,6 @@ static enum {
34 static struct strbuf charset = STRBUF_INIT;
35 static struct strbuf **p_hdr_data, **s_hdr_data;
36 static int use_scissors;
36 -static int add_message_id;
37 static int use_inbody_headers = 1;
38
39 #define MAX_BOUNDARIES 5
@@ -216,10 +216,10 @@ static void handle_content_type(struct strbuf *line)
216 }
217 }
218
219 -static void handle_message_id(const struct strbuf *line)
219 +static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)
220 {
221 - if (add_message_id)
222 - message_id = strdup(line->buf);
221 + if (mi->add_message_id)
222 + mi->message_id = strdup(line->buf);
223 }
224
225 static void handle_content_transfer_encoding(const struct strbuf *line)
@@ -476,11 +476,13 @@ release_return:
476 strbuf_release(&piecebuf);
477 }
478
479 -static int check_header(const struct strbuf *line,
480 - struct strbuf *hdr_data[], int overwrite)
479 +static int check_header(struct mailinfo *mi,
480 + const struct strbuf *line,
481 + struct strbuf *hdr_data[], int overwrite)
482 {
483 int i, ret = 0, len;
484 struct strbuf sb = STRBUF_INIT;
485 +
486 /* search for the interesting parts */
487 for (i = 0; header[i]; i++) {
488 int len = strlen(header[i]);
@@ -518,7 +520,7 @@ static int check_header(const struct strbuf *line,
520 len = strlen("Message-Id: ");
521 strbuf_add(&sb, line->buf + len, line->len - len);
522 decode_header(&sb);
521 - handle_message_id(&sb);
523 + handle_message_id(mi, &sb);
524 ret = 1;
525 goto check_header_out;
526 }
@@ -662,7 +664,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
664 }
665
666 if (use_inbody_headers && mi->header_stage) {
665 - mi->header_stage = check_header(line, s_hdr_data, 0);
667 + mi->header_stage = check_header(mi, line, s_hdr_data, 0);
668 if (mi->header_stage)
669 return 0;
670 } else
@@ -696,8 +698,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
698 }
699
700 if (patchbreak(line)) {
699 - if (message_id)
700 - fprintf(cmitmsg, "Message-Id: %s\n", message_id);
701 + if (mi->message_id)
702 + fprintf(cmitmsg, "Message-Id: %s\n", mi->message_id);
703 fclose(cmitmsg);
704 cmitmsg = NULL;
705 return 1;
@@ -840,7 +842,7 @@ again:
842
843 /* slurp in this section's info */
844 while (read_one_header_line(line, mi->input))
843 - check_header(line, p_hdr_data, 0);
845 + check_header(mi, line, p_hdr_data, 0);
846
847 strbuf_release(&newline);
848 /* replenish line */
@@ -994,7 +996,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
996
997 /* process the email header */
998 while (read_one_header_line(&line, mi->input))
997 - check_header(&line, p_hdr_data, 1);
999 + check_header(mi, &line, p_hdr_data, 1);
1000
1001 handle_body(mi, &line);
1002 fclose(patchfile);
@@ -1029,6 +1031,7 @@ static void clear_mailinfo(struct mailinfo *mi)
1031 {
1032 strbuf_release(&mi->name);
1033 strbuf_release(&mi->email);
1034 + free(mi->message_id);
1035 }
1036
1037 static const char mailinfo_usage[] =
@@ -1054,7 +1057,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1057 else if (!strcmp(argv[1], "-b"))
1058 mi.keep_non_patch_brackets_in_subject = 1;
1059 else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
1057 - add_message_id = 1;
1060 + mi.add_message_id = 1;
1061 else if (!strcmp(argv[1], "-u"))
1062 metainfo_charset = def_charset;
1063 else if (!strcmp(argv[1], "-n"))