1 #define USE_THE_REPOSITORY_VARIABLE
4 #include "fmt-merge-msg.h"
6 #include "parse-options.h"
8 static const char * const fmt_merge_msg_usage
[] = {
9 N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
13 int cmd_fmt_merge_msg(int argc
,
16 struct repository
*repo UNUSED
)
19 const char *message
= NULL
;
20 char *into_name
= NULL
;
21 int shortlog_len
= -1;
22 struct option options
[] = {
23 { OPTION_INTEGER
, 0, "log", &shortlog_len
, N_("n"),
24 N_("populate log with at most <n> entries from shortlog"),
25 PARSE_OPT_OPTARG
, NULL
, DEFAULT_MERGE_LOG_LEN
},
26 { OPTION_INTEGER
, 0, "summary", &shortlog_len
, N_("n"),
27 N_("alias for --log (deprecated)"),
28 PARSE_OPT_OPTARG
| PARSE_OPT_HIDDEN
, NULL
,
29 DEFAULT_MERGE_LOG_LEN
},
30 OPT_STRING('m', "message", &message
, N_("text"),
31 N_("use <text> as start of message")),
32 OPT_STRING(0, "into-name", &into_name
, N_("name"),
33 N_("use <name> instead of the real target branch")),
34 OPT_FILENAME('F', "file", &inpath
, N_("file to read from")),
39 struct strbuf input
= STRBUF_INIT
, output
= STRBUF_INIT
;
41 struct fmt_merge_msg_opts opts
;
43 git_config(fmt_merge_msg_config
, NULL
);
44 argc
= parse_options(argc
, argv
, prefix
, options
, fmt_merge_msg_usage
,
47 usage_with_options(fmt_merge_msg_usage
, options
);
49 shortlog_len
= (merge_log_config
> 0) ? merge_log_config
: 0;
51 if (inpath
&& strcmp(inpath
, "-")) {
52 in
= fopen(inpath
, "r");
54 die_errno("cannot open '%s'", inpath
);
57 if (strbuf_read(&input
, fileno(in
), 0) < 0)
58 die_errno("could not read input file");
61 strbuf_addstr(&output
, message
);
63 memset(&opts
, 0, sizeof(opts
));
64 opts
.add_title
= !message
;
65 opts
.credit_people
= 1;
66 opts
.shortlog_len
= shortlog_len
;
67 opts
.into_name
= into_name
;
69 ret
= fmt_merge_msg(&input
, &output
, &opts
);
72 write_in_full(STDOUT_FILENO
, output
.buf
, output
.len
);
74 strbuf_release(&input
);
75 strbuf_release(&output
);