ref-cache: rename `find_ref()` to `find_ref_entry()`
[git/debian.git] / builtin / mailinfo.c
blobe3b62f2fc744d340de5e3d9efad12b5de93cd55c
1 /*
2 * Another stupid program, this one parsing the headers of an
3 * email to figure out authorship and subject
4 */
5 #include "cache.h"
6 #include "builtin.h"
7 #include "utf8.h"
8 #include "strbuf.h"
9 #include "mailinfo.h"
11 static const char mailinfo_usage[] =
12 "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
14 static char *prefix_copy(const char *prefix, const char *filename)
16 if (!prefix || is_absolute_path(filename))
17 return xstrdup(filename);
18 return xstrdup(prefix_filename(prefix, strlen(prefix), filename));
21 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
23 const char *def_charset;
24 struct mailinfo mi;
25 int status;
26 char *msgfile, *patchfile;
28 setup_mailinfo(&mi);
30 def_charset = get_commit_output_encoding();
31 mi.metainfo_charset = def_charset;
33 while (1 < argc && argv[1][0] == '-') {
34 if (!strcmp(argv[1], "-k"))
35 mi.keep_subject = 1;
36 else if (!strcmp(argv[1], "-b"))
37 mi.keep_non_patch_brackets_in_subject = 1;
38 else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id"))
39 mi.add_message_id = 1;
40 else if (!strcmp(argv[1], "-u"))
41 mi.metainfo_charset = def_charset;
42 else if (!strcmp(argv[1], "-n"))
43 mi.metainfo_charset = NULL;
44 else if (starts_with(argv[1], "--encoding="))
45 mi.metainfo_charset = argv[1] + 11;
46 else if (!strcmp(argv[1], "--scissors"))
47 mi.use_scissors = 1;
48 else if (!strcmp(argv[1], "--no-scissors"))
49 mi.use_scissors = 0;
50 else if (!strcmp(argv[1], "--no-inbody-headers"))
51 mi.use_inbody_headers = 0;
52 else
53 usage(mailinfo_usage);
54 argc--; argv++;
57 if (argc != 3)
58 usage(mailinfo_usage);
60 mi.input = stdin;
61 mi.output = stdout;
63 msgfile = prefix_copy(prefix, argv[1]);
64 patchfile = prefix_copy(prefix, argv[2]);
66 status = !!mailinfo(&mi, msgfile, patchfile);
67 clear_mailinfo(&mi);
69 free(msgfile);
70 free(patchfile);
71 return status;