2006-08-03 01:52:00 +04:00
|
|
|
#include "builtin.h"
|
2017-06-14 21:07:36 +03:00
|
|
|
#include "config.h"
|
2011-10-07 10:12:09 +04:00
|
|
|
#include "fmt-merge-msg.h"
|
2020-03-24 04:07:51 +03:00
|
|
|
#include "parse-options.h"
|
2006-07-03 19:18:43 +04:00
|
|
|
|
2008-10-02 16:59:18 +04:00
|
|
|
static const char * const fmt_merge_msg_usage[] = {
|
2015-01-13 10:44:47 +03:00
|
|
|
N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
|
2008-10-02 16:59:18 +04:00
|
|
|
NULL
|
|
|
|
};
|
2006-07-03 19:18:43 +04:00
|
|
|
|
2008-06-27 20:21:59 +04:00
|
|
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2008-10-02 16:59:18 +04:00
|
|
|
const char *inpath = NULL;
|
2010-08-18 03:00:34 +04:00
|
|
|
const char *message = NULL;
|
2011-10-07 10:12:09 +04:00
|
|
|
int shortlog_len = -1;
|
2008-10-02 16:59:18 +04:00
|
|
|
struct option options[] = {
|
2012-08-20 16:32:10 +04:00
|
|
|
{ OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
|
|
|
|
N_("populate log with at most <n> entries from shortlog"),
|
2010-09-08 21:59:54 +04:00
|
|
|
PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
|
2012-08-20 16:32:10 +04:00
|
|
|
{ OPTION_INTEGER, 0, "summary", &shortlog_len, N_("n"),
|
|
|
|
N_("alias for --log (deprecated)"),
|
2010-09-08 21:59:54 +04:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
|
|
|
|
DEFAULT_MERGE_LOG_LEN },
|
2012-08-20 16:32:10 +04:00
|
|
|
OPT_STRING('m', "message", &message, N_("text"),
|
|
|
|
N_("use <text> as start of message")),
|
|
|
|
OPT_FILENAME('F', "file", &inpath, N_("file to read from")),
|
2008-10-02 16:59:18 +04:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2008-06-27 20:21:59 +04:00
|
|
|
FILE *in = stdin;
|
2008-10-09 23:12:12 +04:00
|
|
|
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
|
2008-06-27 20:21:59 +04:00
|
|
|
int ret;
|
2011-11-05 04:35:42 +04:00
|
|
|
struct fmt_merge_msg_opts opts;
|
2008-06-27 20:21:59 +04:00
|
|
|
|
|
|
|
git_config(fmt_merge_msg_config, NULL);
|
2009-05-23 22:53:12 +04:00
|
|
|
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
|
|
|
|
0);
|
2008-10-02 16:59:18 +04:00
|
|
|
if (argc > 0)
|
|
|
|
usage_with_options(fmt_merge_msg_usage, options);
|
2011-10-07 10:12:09 +04:00
|
|
|
if (shortlog_len < 0)
|
|
|
|
shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
|
2008-10-02 16:59:18 +04:00
|
|
|
|
|
|
|
if (inpath && strcmp(inpath, "-")) {
|
|
|
|
in = fopen(inpath, "r");
|
|
|
|
if (!in)
|
2009-06-27 19:58:47 +04:00
|
|
|
die_errno("cannot open '%s'", inpath);
|
2008-06-27 20:21:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
2009-06-27 19:58:46 +04:00
|
|
|
die_errno("could not read input file");
|
2010-09-08 21:59:53 +04:00
|
|
|
|
|
|
|
if (message)
|
2010-08-18 03:00:34 +04:00
|
|
|
strbuf_addstr(&output, message);
|
2010-09-08 21:59:53 +04:00
|
|
|
|
2011-11-05 04:35:42 +04:00
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.add_title = !message;
|
2012-12-29 03:29:31 +04:00
|
|
|
opts.credit_people = 1;
|
2011-11-05 04:35:42 +04:00
|
|
|
opts.shortlog_len = shortlog_len;
|
|
|
|
|
|
|
|
ret = fmt_merge_msg(&input, &output, &opts);
|
2008-06-27 20:21:59 +04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-10-02 16:59:18 +04:00
|
|
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
2006-07-03 19:18:43 +04:00
|
|
|
return 0;
|
|
|
|
}
|