Skip to content

Commit 6200b75

Browse files
committed
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 <[email protected]>
1 parent 43550ef commit 6200b75

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

builtin/mailinfo.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ struct mailinfo {
1919
struct strbuf email;
2020
int keep_subject;
2121
int keep_non_patch_brackets_in_subject;
22+
int add_message_id;
2223

24+
char *message_id;
2325
int patch_lines;
2426
int filter_stage; /* still reading log or are we copying patch? */
2527
int header_stage; /* still checking in-body headers? */
2628
};
27-
static char *message_id;
2829

2930
static enum {
3031
TE_DONTCARE, TE_QP, TE_BASE64
@@ -33,7 +34,6 @@ static enum {
3334
static struct strbuf charset = STRBUF_INIT;
3435
static struct strbuf **p_hdr_data, **s_hdr_data;
3536
static int use_scissors;
36-
static int add_message_id;
3737
static int use_inbody_headers = 1;
3838

3939
#define MAX_BOUNDARIES 5
@@ -216,10 +216,10 @@ static void handle_content_type(struct strbuf *line)
216216
}
217217
}
218218

219-
static void handle_message_id(const struct strbuf *line)
219+
static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)
220220
{
221-
if (add_message_id)
222-
message_id = strdup(line->buf);
221+
if (mi->add_message_id)
222+
mi->message_id = strdup(line->buf);
223223
}
224224

225225
static void handle_content_transfer_encoding(const struct strbuf *line)
@@ -476,11 +476,13 @@ static void decode_header(struct strbuf *it)
476476
strbuf_release(&piecebuf);
477477
}
478478

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)
481482
{
482483
int i, ret = 0, len;
483484
struct strbuf sb = STRBUF_INIT;
485+
484486
/* search for the interesting parts */
485487
for (i = 0; header[i]; i++) {
486488
int len = strlen(header[i]);
@@ -518,7 +520,7 @@ static int check_header(const struct strbuf *line,
518520
len = strlen("Message-Id: ");
519521
strbuf_add(&sb, line->buf + len, line->len - len);
520522
decode_header(&sb);
521-
handle_message_id(&sb);
523+
handle_message_id(mi, &sb);
522524
ret = 1;
523525
goto check_header_out;
524526
}
@@ -662,7 +664,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
662664
}
663665

664666
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);
666668
if (mi->header_stage)
667669
return 0;
668670
} else
@@ -696,8 +698,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
696698
}
697699

698700
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);
701703
fclose(cmitmsg);
702704
cmitmsg = NULL;
703705
return 1;
@@ -840,7 +842,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
840842

841843
/* slurp in this section's info */
842844
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);
844846

845847
strbuf_release(&newline);
846848
/* replenish line */
@@ -994,7 +996,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
994996

995997
/* process the email header */
996998
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);
9981000

9991001
handle_body(mi, &line);
10001002
fclose(patchfile);
@@ -1029,6 +1031,7 @@ static void clear_mailinfo(struct mailinfo *mi)
10291031
{
10301032
strbuf_release(&mi->name);
10311033
strbuf_release(&mi->email);
1034+
free(mi->message_id);
10321035
}
10331036

10341037
static const char mailinfo_usage[] =
@@ -1054,7 +1057,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10541057
else if (!strcmp(argv[1], "-b"))
10551058
mi.keep_non_patch_brackets_in_subject = 1;
10561059
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
1057-
add_message_id = 1;
1060+
mi.add_message_id = 1;
10581061
else if (!strcmp(argv[1], "-u"))
10591062
metainfo_charset = def_charset;
10601063
else if (!strcmp(argv[1], "-n"))

0 commit comments

Comments
 (0)