]>
Commit | Line | Data |
---|---|---|
25f38f06 | 1 | #include "builtin.h" |
b2141fc1 | 2 | #include "config.h" |
898eacd8 | 3 | #include "fmt-merge-msg.h" |
ce6521e4 | 4 | #include "parse-options.h" |
00449f99 | 5 | |
c8ef0383 | 6 | static const char * const fmt_merge_msg_usage[] = { |
9c9b4f2f | 7 | N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"), |
c8ef0383 PH |
8 | NULL |
9 | }; | |
00449f99 | 10 | |
0b9a969e MV |
11 | int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) |
12 | { | |
c8ef0383 | 13 | const char *inpath = NULL; |
2102440c | 14 | const char *message = NULL; |
898eacd8 | 15 | int shortlog_len = -1; |
c8ef0383 | 16 | struct option options[] = { |
93eced6c NTND |
17 | { OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"), |
18 | N_("populate log with at most <n> entries from shortlog"), | |
96e9420c | 19 | PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN }, |
93eced6c NTND |
20 | { OPTION_INTEGER, 0, "summary", &shortlog_len, N_("n"), |
21 | N_("alias for --log (deprecated)"), | |
96e9420c RR |
22 | PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL, |
23 | DEFAULT_MERGE_LOG_LEN }, | |
93eced6c NTND |
24 | OPT_STRING('m', "message", &message, N_("text"), |
25 | N_("use <text> as start of message")), | |
26 | OPT_FILENAME('F', "file", &inpath, N_("file to read from")), | |
c8ef0383 PH |
27 | OPT_END() |
28 | }; | |
29 | ||
0b9a969e | 30 | FILE *in = stdin; |
f285a2d7 | 31 | struct strbuf input = STRBUF_INIT, output = STRBUF_INIT; |
0b9a969e | 32 | int ret; |
cbda121c | 33 | struct fmt_merge_msg_opts opts; |
0b9a969e MV |
34 | |
35 | git_config(fmt_merge_msg_config, NULL); | |
37782920 SB |
36 | argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage, |
37 | 0); | |
c8ef0383 PH |
38 | if (argc > 0) |
39 | usage_with_options(fmt_merge_msg_usage, options); | |
898eacd8 JH |
40 | if (shortlog_len < 0) |
41 | shortlog_len = (merge_log_config > 0) ? merge_log_config : 0; | |
c8ef0383 PH |
42 | |
43 | if (inpath && strcmp(inpath, "-")) { | |
44 | in = fopen(inpath, "r"); | |
45 | if (!in) | |
0721c314 | 46 | die_errno("cannot open '%s'", inpath); |
0b9a969e MV |
47 | } |
48 | ||
0b9a969e | 49 | if (strbuf_read(&input, fileno(in), 0) < 0) |
d824cbba | 50 | die_errno("could not read input file"); |
1876166a RR |
51 | |
52 | if (message) | |
2102440c | 53 | strbuf_addstr(&output, message); |
1876166a | 54 | |
cbda121c JH |
55 | memset(&opts, 0, sizeof(opts)); |
56 | opts.add_title = !message; | |
9bcbb1c2 | 57 | opts.credit_people = 1; |
cbda121c JH |
58 | opts.shortlog_len = shortlog_len; |
59 | ||
60 | ret = fmt_merge_msg(&input, &output, &opts); | |
0b9a969e MV |
61 | if (ret) |
62 | return ret; | |
c8ef0383 | 63 | write_in_full(STDOUT_FILENO, output.buf, output.len); |
00449f99 JS |
64 | return 0; |
65 | } |