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>
This commit is contained in:
Junio C Hamano 2015-10-18 22:27:56 -07:00
parent 43550efa71
commit 6200b751bb

View file

@ -19,12 +19,13 @@ struct mailinfo {
struct strbuf email; struct strbuf email;
int keep_subject; int keep_subject;
int keep_non_patch_brackets_in_subject; int keep_non_patch_brackets_in_subject;
int add_message_id;
char *message_id;
int patch_lines; int patch_lines;
int filter_stage; /* still reading log or are we copying patch? */ int filter_stage; /* still reading log or are we copying patch? */
int header_stage; /* still checking in-body headers? */ int header_stage; /* still checking in-body headers? */
}; };
static char *message_id;
static enum { static enum {
TE_DONTCARE, TE_QP, TE_BASE64 TE_DONTCARE, TE_QP, TE_BASE64
@ -33,7 +34,6 @@ static enum {
static struct strbuf charset = STRBUF_INIT; static struct strbuf charset = STRBUF_INIT;
static struct strbuf **p_hdr_data, **s_hdr_data; static struct strbuf **p_hdr_data, **s_hdr_data;
static int use_scissors; static int use_scissors;
static int add_message_id;
static int use_inbody_headers = 1; static int use_inbody_headers = 1;
#define MAX_BOUNDARIES 5 #define MAX_BOUNDARIES 5
@ -216,10 +216,10 @@ static void handle_content_type(struct strbuf *line)
} }
} }
static void handle_message_id(const struct strbuf *line) static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)
{ {
if (add_message_id) if (mi->add_message_id)
message_id = strdup(line->buf); mi->message_id = strdup(line->buf);
} }
static void handle_content_transfer_encoding(const struct strbuf *line) static void handle_content_transfer_encoding(const struct strbuf *line)
@ -476,11 +476,13 @@ static void decode_header(struct strbuf *it)
strbuf_release(&piecebuf); strbuf_release(&piecebuf);
} }
static int check_header(const struct strbuf *line, static int check_header(struct mailinfo *mi,
struct strbuf *hdr_data[], int overwrite) const struct strbuf *line,
struct strbuf *hdr_data[], int overwrite)
{ {
int i, ret = 0, len; int i, ret = 0, len;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
/* search for the interesting parts */ /* search for the interesting parts */
for (i = 0; header[i]; i++) { for (i = 0; header[i]; i++) {
int len = strlen(header[i]); int len = strlen(header[i]);
@ -518,7 +520,7 @@ static int check_header(const struct strbuf *line,
len = strlen("Message-Id: "); len = strlen("Message-Id: ");
strbuf_add(&sb, line->buf + len, line->len - len); strbuf_add(&sb, line->buf + len, line->len - len);
decode_header(&sb); decode_header(&sb);
handle_message_id(&sb); handle_message_id(mi, &sb);
ret = 1; ret = 1;
goto check_header_out; goto check_header_out;
} }
@ -662,7 +664,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
} }
if (use_inbody_headers && mi->header_stage) { if (use_inbody_headers && mi->header_stage) {
mi->header_stage = check_header(line, s_hdr_data, 0); mi->header_stage = check_header(mi, line, s_hdr_data, 0);
if (mi->header_stage) if (mi->header_stage)
return 0; return 0;
} else } else
@ -696,8 +698,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
} }
if (patchbreak(line)) { if (patchbreak(line)) {
if (message_id) if (mi->message_id)
fprintf(cmitmsg, "Message-Id: %s\n", message_id); fprintf(cmitmsg, "Message-Id: %s\n", mi->message_id);
fclose(cmitmsg); fclose(cmitmsg);
cmitmsg = NULL; cmitmsg = NULL;
return 1; return 1;
@ -840,7 +842,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
/* slurp in this section's info */ /* slurp in this section's info */
while (read_one_header_line(line, mi->input)) while (read_one_header_line(line, mi->input))
check_header(line, p_hdr_data, 0); check_header(mi, line, p_hdr_data, 0);
strbuf_release(&newline); strbuf_release(&newline);
/* replenish line */ /* replenish line */
@ -994,7 +996,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
/* process the email header */ /* process the email header */
while (read_one_header_line(&line, mi->input)) while (read_one_header_line(&line, mi->input))
check_header(&line, p_hdr_data, 1); check_header(mi, &line, p_hdr_data, 1);
handle_body(mi, &line); handle_body(mi, &line);
fclose(patchfile); fclose(patchfile);
@ -1029,6 +1031,7 @@ static void clear_mailinfo(struct mailinfo *mi)
{ {
strbuf_release(&mi->name); strbuf_release(&mi->name);
strbuf_release(&mi->email); strbuf_release(&mi->email);
free(mi->message_id);
} }
static const char mailinfo_usage[] = static const char mailinfo_usage[] =
@ -1054,7 +1057,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
else if (!strcmp(argv[1], "-b")) else if (!strcmp(argv[1], "-b"))
mi.keep_non_patch_brackets_in_subject = 1; mi.keep_non_patch_brackets_in_subject = 1;
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id")) else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
add_message_id = 1; mi.add_message_id = 1;
else if (!strcmp(argv[1], "-u")) else if (!strcmp(argv[1], "-u"))
metainfo_charset = def_charset; metainfo_charset = def_charset;
else if (!strcmp(argv[1], "-n")) else if (!strcmp(argv[1], "-n"))