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