From 28be2d083cfce464dc898dfb78f2b957b7116277 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 14 Oct 2015 16:15:40 -0700 Subject: [PATCH] mailinfo: move metainfo_charset to struct mailinfo This requires us to pass the struct down to decode_header() and convert_to_utf8() callchain. Signed-off-by: Junio C Hamano --- builtin/mailinfo.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 7531b3df3b..0b49bf6a1a 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -9,8 +9,6 @@ static FILE *cmitmsg, *patchfile; -static const char *metainfo_charset; - struct mailinfo { FILE *input; FILE *output; @@ -22,6 +20,7 @@ struct mailinfo { int add_message_id; int use_scissors; int use_inbody_headers; + const char *metainfo_charset; char *message_id; int patch_lines; @@ -380,23 +379,24 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg) return out; } -static void convert_to_utf8(struct strbuf *line, const char *charset) +static void convert_to_utf8(struct mailinfo *mi, + struct strbuf *line, const char *charset) { char *out; if (!charset || !*charset) return; - if (same_encoding(metainfo_charset, charset)) + if (same_encoding(mi->metainfo_charset, charset)) return; - out = reencode_string(line->buf, metainfo_charset, charset); + out = reencode_string(line->buf, mi->metainfo_charset, charset); if (!out) die("cannot convert from %s to %s", - charset, metainfo_charset); + charset, mi->metainfo_charset); strbuf_attach(line, out, strlen(out), strlen(out)); } -static void decode_header(struct strbuf *it) +static void decode_header(struct mailinfo *mi, struct strbuf *it) { char *in, *ep, *cp; struct strbuf outbuf = STRBUF_INIT, *dec; @@ -459,8 +459,8 @@ static void decode_header(struct strbuf *it) dec = decode_q_segment(&piecebuf, 1); break; } - if (metainfo_charset) - convert_to_utf8(dec, charset_q.buf); + if (mi->metainfo_charset) + convert_to_utf8(mi, dec, charset_q.buf); strbuf_addbuf(&outbuf, dec); strbuf_release(dec); @@ -491,7 +491,7 @@ static int check_header(struct mailinfo *mi, * normalize the meta information to utf8. */ strbuf_add(&sb, line->buf + len + 2, line->len - len - 2); - decode_header(&sb); + decode_header(mi, &sb); handle_header(&hdr_data[i], &sb); ret = 1; goto check_header_out; @@ -502,7 +502,7 @@ static int check_header(struct mailinfo *mi, if (cmp_header(line, "Content-Type")) { len = strlen("Content-Type: "); strbuf_add(&sb, line->buf + len, line->len - len); - decode_header(&sb); + decode_header(mi, &sb); strbuf_insert(&sb, 0, "Content-Type: ", len); handle_content_type(&sb); ret = 1; @@ -511,7 +511,7 @@ static int check_header(struct mailinfo *mi, if (cmp_header(line, "Content-Transfer-Encoding")) { len = strlen("Content-Transfer-Encoding: "); strbuf_add(&sb, line->buf + len, line->len - len); - decode_header(&sb); + decode_header(mi, &sb); handle_content_transfer_encoding(&sb); ret = 1; goto check_header_out; @@ -519,7 +519,7 @@ static int check_header(struct mailinfo *mi, if (cmp_header(line, "Message-Id")) { len = strlen("Message-Id: "); strbuf_add(&sb, line->buf + len, line->len - len); - decode_header(&sb); + decode_header(mi, &sb); handle_message_id(mi, &sb); ret = 1; goto check_header_out; @@ -674,8 +674,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line) mi->header_stage = 0; /* normalize the log message to UTF-8. */ - if (metainfo_charset) - convert_to_utf8(line, charset.buf); + if (mi->metainfo_charset) + convert_to_utf8(mi, line, charset.buf); if (mi->use_scissors && is_scissors_line(line)) { int i; @@ -1052,7 +1052,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) setup_mailinfo(&mi); def_charset = get_commit_output_encoding(); - metainfo_charset = def_charset; + mi.metainfo_charset = def_charset; while (1 < argc && argv[1][0] == '-') { if (!strcmp(argv[1], "-k")) @@ -1062,11 +1062,11 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id")) mi.add_message_id = 1; else if (!strcmp(argv[1], "-u")) - metainfo_charset = def_charset; + mi.metainfo_charset = def_charset; else if (!strcmp(argv[1], "-n")) - metainfo_charset = NULL; + mi.metainfo_charset = NULL; else if (starts_with(argv[1], "--encoding=")) - metainfo_charset = argv[1] + 11; + mi.metainfo_charset = argv[1] + 11; else if (!strcmp(argv[1], "--scissors")) mi.use_scissors = 1; else if (!strcmp(argv[1], "--no-scissors")) -- 2.11.4.GIT