]> git.ipfire.org Git - thirdparty/git.git/blob - builtin/fmt-merge-msg.c
cocci: apply the "commit.h" part of "the_repository.pending"
[thirdparty/git.git] / builtin / fmt-merge-msg.c
1 #include "builtin.h"
2 #include "config.h"
3 #include "fmt-merge-msg.h"
4 #include "parse-options.h"
5
6 static const char * const fmt_merge_msg_usage[] = {
7 N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
8 NULL
9 };
10
11 int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
12 {
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")),
30 OPT_END()
31 };
32
33 FILE *in = stdin;
34 struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
35 int ret;
36 struct fmt_merge_msg_opts opts;
37
38 git_config(fmt_merge_msg_config, NULL);
39 argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
40 0);
41 if (argc > 0)
42 usage_with_options(fmt_merge_msg_usage, options);
43 if (shortlog_len < 0)
44 shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
45
46 if (inpath && strcmp(inpath, "-")) {
47 in = fopen(inpath, "r");
48 if (!in)
49 die_errno("cannot open '%s'", inpath);
50 }
51
52 if (strbuf_read(&input, fileno(in), 0) < 0)
53 die_errno("could not read input file");
54
55 if (message)
56 strbuf_addstr(&output, message);
57
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;
63
64 ret = fmt_merge_msg(&input, &output, &opts);
65 if (ret)
66 return ret;
67 write_in_full(STDOUT_FILENO, output.buf, output.len);
68 return 0;
69 }