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