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 char *into_name
= NULL
;
16 int shortlog_len
= -1;
17 struct option options
[] = {
18 { OPTION_INTEGER
, 0, "log", &shortlog_len
, N_("n"),
19 N_("populate log with at most <n> entries from shortlog"),
20 PARSE_OPT_OPTARG
, NULL
, DEFAULT_MERGE_LOG_LEN
},
21 { OPTION_INTEGER
, 0, "summary", &shortlog_len
, N_("n"),
22 N_("alias for --log (deprecated)"),
23 PARSE_OPT_OPTARG
| PARSE_OPT_HIDDEN
, NULL
,
24 DEFAULT_MERGE_LOG_LEN
},
25 OPT_STRING('m', "message", &message
, N_("text"),
26 N_("use <text> as start of message")),
27 OPT_STRING(0, "into-name", &into_name
, N_("name"),
28 N_("use <name> instead of the real target branch")),
29 OPT_FILENAME('F', "file", &inpath
, N_("file to read from")),
34 struct strbuf input
= STRBUF_INIT
, output
= STRBUF_INIT
;
36 struct fmt_merge_msg_opts opts
;
38 git_config(fmt_merge_msg_config
, NULL
);
39 argc
= parse_options(argc
, argv
, prefix
, options
, fmt_merge_msg_usage
,
42 usage_with_options(fmt_merge_msg_usage
, options
);
44 shortlog_len
= (merge_log_config
> 0) ? merge_log_config
: 0;
46 if (inpath
&& strcmp(inpath
, "-")) {
47 in
= fopen(inpath
, "r");
49 die_errno("cannot open '%s'", inpath
);
52 if (strbuf_read(&input
, fileno(in
), 0) < 0)
53 die_errno("could not read input file");
56 strbuf_addstr(&output
, message
);
58 memset(&opts
, 0, sizeof(opts
));
59 opts
.add_title
= !message
;
60 opts
.credit_people
= 1;
61 opts
.shortlog_len
= shortlog_len
;
62 opts
.into_name
= into_name
;
64 ret
= fmt_merge_msg(&input
, &output
, &opts
);
67 write_in_full(STDOUT_FILENO
, output
.buf
, output
.len
);