diff options
-rw-r--r-- | builtin/mailinfo.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index cfb667a594..77f96177cc 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -11,17 +11,25 @@ static const char mailinfo_usage[] = "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info"; +struct metainfo_charset +{ + enum { + CHARSET_DEFAULT, + CHARSET_NO_REENCODE, + CHARSET_EXPLICIT, + } policy; + const char *charset; +}; + int cmd_mailinfo(int argc, const char **argv, const char *prefix) { - const char *def_charset; + struct metainfo_charset meta_charset; struct mailinfo mi; int status; char *msgfile, *patchfile; setup_mailinfo(&mi); - - def_charset = get_commit_output_encoding(); - mi.metainfo_charset = def_charset; + meta_charset.policy = CHARSET_DEFAULT; while (1 < argc && argv[1][0] == '-') { if (!strcmp(argv[1], "-k")) @@ -31,12 +39,13 @@ 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")) - mi.metainfo_charset = def_charset; + meta_charset.policy = CHARSET_DEFAULT; else if (!strcmp(argv[1], "-n")) - mi.metainfo_charset = NULL; - else if (starts_with(argv[1], "--encoding=")) - mi.metainfo_charset = argv[1] + 11; - else if (!strcmp(argv[1], "--scissors")) + meta_charset.policy = CHARSET_NO_REENCODE; + else if (starts_with(argv[1], "--encoding=")) { + meta_charset.policy = CHARSET_EXPLICIT; + meta_charset.charset = argv[1] + 11; + } else if (!strcmp(argv[1], "--scissors")) mi.use_scissors = 1; else if (!strcmp(argv[1], "--no-scissors")) mi.use_scissors = 0; @@ -50,6 +59,19 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) if (argc != 3) usage(mailinfo_usage); + switch (meta_charset.policy) { + case CHARSET_DEFAULT: + mi.metainfo_charset = get_commit_output_encoding(); + break; + case CHARSET_NO_REENCODE: + mi.metainfo_charset = NULL; + break; + case CHARSET_EXPLICIT: + break; + default: + BUG("invalid meta_charset.policy"); + } + mi.input = stdin; mi.output = stdout; |