99
1010static FILE * cmitmsg , * patchfile ;
1111
12- static const char * metainfo_charset ;
13-
1412struct mailinfo {
1513 FILE * input ;
1614 FILE * output ;
@@ -22,6 +20,7 @@ struct mailinfo {
2220 int add_message_id ;
2321 int use_scissors ;
2422 int use_inbody_headers ;
23+ const char * metainfo_charset ;
2524
2625 char * message_id ;
2726 int patch_lines ;
@@ -380,23 +379,24 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
380379 return out ;
381380}
382381
383- static void convert_to_utf8 (struct strbuf * line , const char * charset )
382+ static void convert_to_utf8 (struct mailinfo * mi ,
383+ struct strbuf * line , const char * charset )
384384{
385385 char * out ;
386386
387387 if (!charset || !* charset )
388388 return ;
389389
390- if (same_encoding (metainfo_charset , charset ))
390+ if (same_encoding (mi -> metainfo_charset , charset ))
391391 return ;
392- out = reencode_string (line -> buf , metainfo_charset , charset );
392+ out = reencode_string (line -> buf , mi -> metainfo_charset , charset );
393393 if (!out )
394394 die ("cannot convert from %s to %s" ,
395- charset , metainfo_charset );
395+ charset , mi -> metainfo_charset );
396396 strbuf_attach (line , out , strlen (out ), strlen (out ));
397397}
398398
399- static void decode_header (struct strbuf * it )
399+ static void decode_header (struct mailinfo * mi , struct strbuf * it )
400400{
401401 char * in , * ep , * cp ;
402402 struct strbuf outbuf = STRBUF_INIT , * dec ;
@@ -459,8 +459,8 @@ static void decode_header(struct strbuf *it)
459459 dec = decode_q_segment (& piecebuf , 1 );
460460 break ;
461461 }
462- if (metainfo_charset )
463- convert_to_utf8 (dec , charset_q .buf );
462+ if (mi -> metainfo_charset )
463+ convert_to_utf8 (mi , dec , charset_q .buf );
464464
465465 strbuf_addbuf (& outbuf , dec );
466466 strbuf_release (dec );
@@ -491,7 +491,7 @@ static int check_header(struct mailinfo *mi,
491491 * normalize the meta information to utf8.
492492 */
493493 strbuf_add (& sb , line -> buf + len + 2 , line -> len - len - 2 );
494- decode_header (& sb );
494+ decode_header (mi , & sb );
495495 handle_header (& hdr_data [i ], & sb );
496496 ret = 1 ;
497497 goto check_header_out ;
@@ -502,7 +502,7 @@ static int check_header(struct mailinfo *mi,
502502 if (cmp_header (line , "Content-Type" )) {
503503 len = strlen ("Content-Type: " );
504504 strbuf_add (& sb , line -> buf + len , line -> len - len );
505- decode_header (& sb );
505+ decode_header (mi , & sb );
506506 strbuf_insert (& sb , 0 , "Content-Type: " , len );
507507 handle_content_type (& sb );
508508 ret = 1 ;
@@ -511,15 +511,15 @@ static int check_header(struct mailinfo *mi,
511511 if (cmp_header (line , "Content-Transfer-Encoding" )) {
512512 len = strlen ("Content-Transfer-Encoding: " );
513513 strbuf_add (& sb , line -> buf + len , line -> len - len );
514- decode_header (& sb );
514+ decode_header (mi , & sb );
515515 handle_content_transfer_encoding (& sb );
516516 ret = 1 ;
517517 goto check_header_out ;
518518 }
519519 if (cmp_header (line , "Message-Id" )) {
520520 len = strlen ("Message-Id: " );
521521 strbuf_add (& sb , line -> buf + len , line -> len - len );
522- decode_header (& sb );
522+ decode_header (mi , & sb );
523523 handle_message_id (mi , & sb );
524524 ret = 1 ;
525525 goto check_header_out ;
@@ -674,8 +674,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
674674 mi -> header_stage = 0 ;
675675
676676 /* normalize the log message to UTF-8. */
677- if (metainfo_charset )
678- convert_to_utf8 (line , charset .buf );
677+ if (mi -> metainfo_charset )
678+ convert_to_utf8 (mi , line , charset .buf );
679679
680680 if (mi -> use_scissors && is_scissors_line (line )) {
681681 int i ;
@@ -1052,7 +1052,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10521052 setup_mailinfo (& mi );
10531053
10541054 def_charset = get_commit_output_encoding ();
1055- metainfo_charset = def_charset ;
1055+ mi . metainfo_charset = def_charset ;
10561056
10571057 while (1 < argc && argv [1 ][0 ] == '-' ) {
10581058 if (!strcmp (argv [1 ], "-k" ))
@@ -1062,11 +1062,11 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
10621062 else if (!strcmp (argv [1 ], "-m" ) || !strcmp (argv [1 ], "--message-id" ))
10631063 mi .add_message_id = 1 ;
10641064 else if (!strcmp (argv [1 ], "-u" ))
1065- metainfo_charset = def_charset ;
1065+ mi . metainfo_charset = def_charset ;
10661066 else if (!strcmp (argv [1 ], "-n" ))
1067- metainfo_charset = NULL ;
1067+ mi . metainfo_charset = NULL ;
10681068 else if (starts_with (argv [1 ], "--encoding=" ))
1069- metainfo_charset = argv [1 ] + 11 ;
1069+ mi . metainfo_charset = argv [1 ] + 11 ;
10701070 else if (!strcmp (argv [1 ], "--scissors" ))
10711071 mi .use_scissors = 1 ;
10721072 else if (!strcmp (argv [1 ], "--no-scissors" ))
0 commit comments