3
#include "fmt-merge-msg.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>]"),
12
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
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")),
35
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
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,
43
usage_with_options(fmt_merge_msg_usage, options);
45
shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
47
if (inpath && strcmp(inpath, "-")) {
48
in = fopen(inpath, "r");
50
die_errno("cannot open '%s'", inpath);
53
if (strbuf_read(&input, fileno(in), 0) < 0)
54
die_errno("could not read input file");
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);
68
write_in_full(STDOUT_FILENO, output.buf, output.len);