Re: [PATCH v2 16/31] mailinfo: move metainfo_charset to struct mailinfo
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 15, 2015, 20:47 UTC
- Message-ID
- <CAPig+cSnPT=oEB7bxFufaZ8JtDTxtrkiaUDcz4K+hu4wM-wOmg@mail.gmail.com>
- In-Reply-To
- <1444855557-2127-17-git-send-email-gitster@pobox.com>
On Wed, Oct 14, 2015 at 4:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> This requires us to pass the struct down to decode_header() and
> convert_to_utf8() callchain.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> @@ -520,23 +519,24 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
> -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)
> + if (!mi->metainfo_charset || !charset || !*charset)
> return;Mental note: convert_to_utf8() is updated to return early when metainfo_charset==NULL.
Show 24 quoted lines
> - 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;
> @@ -599,8 +599,7 @@ static void decode_header(struct strbuf *it)
> dec = decode_q_segment(&piecebuf, 1);
> break;
> }
> - if (metainfo_charset)
> - convert_to_utf8(dec, charset_q.buf);
> + convert_to_utf8(mi, dec, charset_q.buf);It's safe to drop the conditional here since convert_to_utf8() now checks metainfo_charset. Okay.
Show 9 quoted lines
> strbuf_addbuf(&outbuf, dec); > strbuf_release(dec); > @@ -745,8 +744,7 @@ 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); > + convert_to_utf8(mi, line, charset.buf);
Ditto.
> if (mi->use_scissors && is_scissors_line(line)) {
> int i;