3 #include "fmt-merge-msg.h"
4 #include "parse-options.h"
6 static const char * const fmt_merge_msg_usage
[] = {
7 N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
11 int cmd_fmt_merge_msg(int argc
, const char **argv
, const char *prefix
)
13 const char *inpath
= NULL
;
14 const char *message
= NULL
;
15 int shortlog_len
= -1;
16 struct option options
[] = {
17 { OPTION_INTEGER
, 0, "log", &shortlog_len
, N_("n"),
18 N_("populate log with at most <n> entries from shortlog"),
19 PARSE_OPT_OPTARG
, NULL
, DEFAULT_MERGE_LOG_LEN
},
20 { OPTION_INTEGER
, 0, "summary", &shortlog_len
, N_("n"),
21 N_("alias for --log (deprecated)"),
22 PARSE_OPT_OPTARG
| PARSE_OPT_HIDDEN
, NULL
,
23 DEFAULT_MERGE_LOG_LEN
},
24 OPT_STRING('m', "message", &message
, N_("text"),
25 N_("use <text> as start of message")),
26 OPT_FILENAME('F', "file", &inpath
, N_("file to read from")),
31 struct strbuf input
= STRBUF_INIT
, output
= STRBUF_INIT
;
33 struct fmt_merge_msg_opts opts
;
35 git_config(fmt_merge_msg_config
, NULL
);
36 argc
= parse_options(argc
, argv
, prefix
, options
, fmt_merge_msg_usage
,
39 usage_with_options(fmt_merge_msg_usage
, options
);
41 shortlog_len
= (merge_log_config
> 0) ? merge_log_config
: 0;
43 if (inpath
&& strcmp(inpath
, "-")) {
44 in
= fopen(inpath
, "r");
46 die_errno("cannot open '%s'", inpath
);
49 if (strbuf_read(&input
, fileno(in
), 0) < 0)
50 die_errno("could not read input file");
53 strbuf_addstr(&output
, message
);
55 memset(&opts
, 0, sizeof(opts
));
56 opts
.add_title
= !message
;
57 opts
.credit_people
= 1;
58 opts
.shortlog_len
= shortlog_len
;
60 ret
= fmt_merge_msg(&input
, &output
, &opts
);
63 write_in_full(STDOUT_FILENO
, output
.buf
, output
.len
);