mailinfo: move charset to struct mailinfo

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

Junio C Hamano committed Oct 18, 2015 at 22:30 UTC f1e037b9af77fd9a3f4c5213af66179d0f722a72
1 file changed +8 -7
builtin/mailinfo.c
+8 -7
@@ -22,6 +22,7 @@ struct mailinfo {
22 int use_inbody_headers;
23 const char *metainfo_charset;
24
25 + struct strbuf charset;
26 char *message_id;
27 enum {
28 TE_DONTCARE, TE_QP, TE_BASE64
@@ -31,8 +32,6 @@ struct mailinfo {
32 int header_stage; /* still checking in-body headers? */
33 };
34
34 -
35 -static struct strbuf charset = STRBUF_INIT;
35 static struct strbuf **p_hdr_data, **s_hdr_data;
36
37 #define MAX_BOUNDARIES 5
@@ -193,7 +192,7 @@ static struct strbuf *content[MAX_BOUNDARIES];
192
193 static struct strbuf **content_top = content;
194
196 -static void handle_content_type(struct strbuf *line)
195 +static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
196 {
197 struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
198 strbuf_init(boundary, line->len);
@@ -207,7 +206,7 @@ static void handle_content_type(struct strbuf *line)
206 *content_top = boundary;
207 boundary = NULL;
208 }
210 - slurp_attr(line->buf, "charset=", &charset);
209 + slurp_attr(line->buf, "charset=", &mi->charset);
210
211 if (boundary) {
212 strbuf_release(boundary);
@@ -504,7 +503,7 @@ static int check_header(struct mailinfo *mi,
503 strbuf_add(&sb, line->buf + len, line->len - len);
504 decode_header(mi, &sb);
505 strbuf_insert(&sb, 0, "Content-Type: ", len);
507 - handle_content_type(&sb);
506 + handle_content_type(mi, &sb);
507 ret = 1;
508 goto check_header_out;
509 }
@@ -674,7 +673,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
673 mi->header_stage = 0;
674
675 /* normalize the log message to UTF-8. */
677 - convert_to_utf8(mi, line, charset.buf);
676 + convert_to_utf8(mi, line, mi->charset.buf);
677
678 if (mi->use_scissors && is_scissors_line(line)) {
679 int i;
@@ -837,7 +836,7 @@ again:
836
837 /* set some defaults */
838 mi->transfer_encoding = TE_DONTCARE;
840 - strbuf_reset(&charset);
839 + strbuf_reset(&mi->charset);
840
841 /* slurp in this section's info */
842 while (read_one_header_line(line, mi->input))
@@ -1024,6 +1023,7 @@ static void setup_mailinfo(struct mailinfo *mi)
1023 memset(mi, 0, sizeof(*mi));
1024 strbuf_init(&mi->name, 0);
1025 strbuf_init(&mi->email, 0);
1026 + strbuf_init(&mi->charset, 0);
1027 mi->header_stage = 1;
1028 mi->use_inbody_headers = 1;
1029 git_config(git_mailinfo_config, &mi);
@@ -1033,6 +1033,7 @@ static void clear_mailinfo(struct mailinfo *mi)
1033 {
1034 strbuf_release(&mi->name);
1035 strbuf_release(&mi->email);
1036 + strbuf_release(&mi->charset);
1037 free(mi->message_id);
1038 }
1039