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