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