]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/mailinfo.c
Merge branch 'js/update-index-ignore-removal-for-skip-worktree'
[thirdparty/git.git] / builtin / mailinfo.c
CommitLineData
2744b234
LT
1/*
2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
4 */
f1f909e3 5#include "cache.h"
34488e3c 6#include "builtin.h"
b45974a6 7#include "utf8.h"
3b6121f6 8#include "strbuf.h"
c6905e45 9#include "mailinfo.h"
c69f2395 10
6bff6a60 11static const char mailinfo_usage[] =
9c9b4f2f 12 "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
d4a9ce78 13
a633fca0 14int cmd_mailinfo(int argc, const char **argv, const char *prefix)
2744b234 15{
bb1091a4 16 const char *def_charset;
c69f2395
JH
17 struct mailinfo mi;
18 int status;
3f0ec068 19 char *msgfile, *patchfile;
bb1091a4 20
c69f2395 21 setup_mailinfo(&mi);
f1f909e3 22
a6fa5992 23 def_charset = get_commit_output_encoding();
28be2d08 24 mi.metainfo_charset = def_charset;
bb1091a4 25
6bff6a60
JH
26 while (1 < argc && argv[1][0] == '-') {
27 if (!strcmp(argv[1], "-k"))
849106d5 28 mi.keep_subject = 1;
17635fc9 29 else if (!strcmp(argv[1], "-b"))
849106d5 30 mi.keep_non_patch_brackets_in_subject = 1;
452dfbed 31 else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
6200b751 32 mi.add_message_id = 1;
d4a9ce78 33 else if (!strcmp(argv[1], "-u"))
28be2d08 34 mi.metainfo_charset = def_charset;
bb1091a4 35 else if (!strcmp(argv[1], "-n"))
28be2d08 36 mi.metainfo_charset = NULL;
59556548 37 else if (starts_with(argv[1], "--encoding="))
28be2d08 38 mi.metainfo_charset = argv[1] + 11;
017678b4 39 else if (!strcmp(argv[1], "--scissors"))
ad57ef9d 40 mi.use_scissors = 1;
017678b4 41 else if (!strcmp(argv[1], "--no-scissors"))
ad57ef9d 42 mi.use_scissors = 0;
d25e5159 43 else if (!strcmp(argv[1], "--no-inbody-headers"))
ad57ef9d 44 mi.use_inbody_headers = 0;
d4a9ce78 45 else
f1f909e3 46 usage(mailinfo_usage);
6bff6a60
JH
47 argc--; argv++;
48 }
49
a196d8d4 50 if (argc != 3)
f1f909e3 51 usage(mailinfo_usage);
34488e3c 52
173aef7c
JH
53 mi.input = stdin;
54 mi.output = stdout;
3f0ec068 55
e4da43b1
JK
56 msgfile = prefix_filename(prefix, argv[1]);
57 patchfile = prefix_filename(prefix, argv[2]);
3f0ec068
JH
58
59 status = !!mailinfo(&mi, msgfile, patchfile);
c69f2395
JH
60 clear_mailinfo(&mi);
61
3f0ec068
JH
62 free(msgfile);
63 free(patchfile);
c69f2395 64 return status;
2744b234 65}