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