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