mirror of
https://github.com/git/git
synced 2024-09-13 21:34:42 +00:00
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 <gitster@pobox.com>
This commit is contained in:
parent
ad57ef9da9
commit
28be2d083c
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
static FILE *cmitmsg, *patchfile;
|
static FILE *cmitmsg, *patchfile;
|
||||||
|
|
||||||
static const char *metainfo_charset;
|
|
||||||
|
|
||||||
struct mailinfo {
|
struct mailinfo {
|
||||||
FILE *input;
|
FILE *input;
|
||||||
FILE *output;
|
FILE *output;
|
||||||
|
@ -22,6 +20,7 @@ struct mailinfo {
|
||||||
int add_message_id;
|
int add_message_id;
|
||||||
int use_scissors;
|
int use_scissors;
|
||||||
int use_inbody_headers;
|
int use_inbody_headers;
|
||||||
|
const char *metainfo_charset;
|
||||||
|
|
||||||
char *message_id;
|
char *message_id;
|
||||||
int patch_lines;
|
int patch_lines;
|
||||||
|
@ -380,23 +379,24 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
|
||||||
return out;
|
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;
|
char *out;
|
||||||
|
|
||||||
if (!charset || !*charset)
|
if (!charset || !*charset)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (same_encoding(metainfo_charset, charset))
|
if (same_encoding(mi->metainfo_charset, charset))
|
||||||
return;
|
return;
|
||||||
out = reencode_string(line->buf, metainfo_charset, charset);
|
out = reencode_string(line->buf, mi->metainfo_charset, charset);
|
||||||
if (!out)
|
if (!out)
|
||||||
die("cannot convert from %s to %s",
|
die("cannot convert from %s to %s",
|
||||||
charset, metainfo_charset);
|
charset, mi->metainfo_charset);
|
||||||
strbuf_attach(line, out, strlen(out), strlen(out));
|
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;
|
char *in, *ep, *cp;
|
||||||
struct strbuf outbuf = STRBUF_INIT, *dec;
|
struct strbuf outbuf = STRBUF_INIT, *dec;
|
||||||
|
@ -459,8 +459,8 @@ static void decode_header(struct strbuf *it)
|
||||||
dec = decode_q_segment(&piecebuf, 1);
|
dec = decode_q_segment(&piecebuf, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (metainfo_charset)
|
if (mi->metainfo_charset)
|
||||||
convert_to_utf8(dec, charset_q.buf);
|
convert_to_utf8(mi, dec, charset_q.buf);
|
||||||
|
|
||||||
strbuf_addbuf(&outbuf, dec);
|
strbuf_addbuf(&outbuf, dec);
|
||||||
strbuf_release(dec);
|
strbuf_release(dec);
|
||||||
|
@ -491,7 +491,7 @@ static int check_header(struct mailinfo *mi,
|
||||||
* normalize the meta information to utf8.
|
* normalize the meta information to utf8.
|
||||||
*/
|
*/
|
||||||
strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
|
strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
|
||||||
decode_header(&sb);
|
decode_header(mi, &sb);
|
||||||
handle_header(&hdr_data[i], &sb);
|
handle_header(&hdr_data[i], &sb);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto check_header_out;
|
goto check_header_out;
|
||||||
|
@ -502,7 +502,7 @@ static int check_header(struct mailinfo *mi,
|
||||||
if (cmp_header(line, "Content-Type")) {
|
if (cmp_header(line, "Content-Type")) {
|
||||||
len = strlen("Content-Type: ");
|
len = strlen("Content-Type: ");
|
||||||
strbuf_add(&sb, line->buf + len, line->len - len);
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
||||||
decode_header(&sb);
|
decode_header(mi, &sb);
|
||||||
strbuf_insert(&sb, 0, "Content-Type: ", len);
|
strbuf_insert(&sb, 0, "Content-Type: ", len);
|
||||||
handle_content_type(&sb);
|
handle_content_type(&sb);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -511,7 +511,7 @@ static int check_header(struct mailinfo *mi,
|
||||||
if (cmp_header(line, "Content-Transfer-Encoding")) {
|
if (cmp_header(line, "Content-Transfer-Encoding")) {
|
||||||
len = strlen("Content-Transfer-Encoding: ");
|
len = strlen("Content-Transfer-Encoding: ");
|
||||||
strbuf_add(&sb, line->buf + len, line->len - len);
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
||||||
decode_header(&sb);
|
decode_header(mi, &sb);
|
||||||
handle_content_transfer_encoding(&sb);
|
handle_content_transfer_encoding(&sb);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto check_header_out;
|
goto check_header_out;
|
||||||
|
@ -519,7 +519,7 @@ static int check_header(struct mailinfo *mi,
|
||||||
if (cmp_header(line, "Message-Id")) {
|
if (cmp_header(line, "Message-Id")) {
|
||||||
len = strlen("Message-Id: ");
|
len = strlen("Message-Id: ");
|
||||||
strbuf_add(&sb, line->buf + len, line->len - len);
|
strbuf_add(&sb, line->buf + len, line->len - len);
|
||||||
decode_header(&sb);
|
decode_header(mi, &sb);
|
||||||
handle_message_id(mi, &sb);
|
handle_message_id(mi, &sb);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto check_header_out;
|
goto check_header_out;
|
||||||
|
@ -674,8 +674,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
|
||||||
mi->header_stage = 0;
|
mi->header_stage = 0;
|
||||||
|
|
||||||
/* normalize the log message to UTF-8. */
|
/* normalize the log message to UTF-8. */
|
||||||
if (metainfo_charset)
|
if (mi->metainfo_charset)
|
||||||
convert_to_utf8(line, charset.buf);
|
convert_to_utf8(mi, line, charset.buf);
|
||||||
|
|
||||||
if (mi->use_scissors && is_scissors_line(line)) {
|
if (mi->use_scissors && is_scissors_line(line)) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1052,7 +1052,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
|
||||||
setup_mailinfo(&mi);
|
setup_mailinfo(&mi);
|
||||||
|
|
||||||
def_charset = get_commit_output_encoding();
|
def_charset = get_commit_output_encoding();
|
||||||
metainfo_charset = def_charset;
|
mi.metainfo_charset = def_charset;
|
||||||
|
|
||||||
while (1 < argc && argv[1][0] == '-') {
|
while (1 < argc && argv[1][0] == '-') {
|
||||||
if (!strcmp(argv[1], "-k"))
|
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"))
|
else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
|
||||||
mi.add_message_id = 1;
|
mi.add_message_id = 1;
|
||||||
else if (!strcmp(argv[1], "-u"))
|
else if (!strcmp(argv[1], "-u"))
|
||||||
metainfo_charset = def_charset;
|
mi.metainfo_charset = def_charset;
|
||||||
else if (!strcmp(argv[1], "-n"))
|
else if (!strcmp(argv[1], "-n"))
|
||||||
metainfo_charset = NULL;
|
mi.metainfo_charset = NULL;
|
||||||
else if (starts_with(argv[1], "--encoding="))
|
else if (starts_with(argv[1], "--encoding="))
|
||||||
metainfo_charset = argv[1] + 11;
|
mi.metainfo_charset = argv[1] + 11;
|
||||||
else if (!strcmp(argv[1], "--scissors"))
|
else if (!strcmp(argv[1], "--scissors"))
|
||||||
mi.use_scissors = 1;
|
mi.use_scissors = 1;
|
||||||
else if (!strcmp(argv[1], "--no-scissors"))
|
else if (!strcmp(argv[1], "--no-scissors"))
|
||||||
|
|
Loading…
Reference in a new issue