Re: [PATCH v2 16/31] mailinfo: move metainfo_charset to struct mailinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 14, 2015 at 4:45 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
> This requires us to pass the struct down to decode_header() and
> convert_to_utf8() callchain.
>
> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
> ---
> @@ -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.

> -       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.

>                 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;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]