git

Форк
0
/
fmt-merge-msg.c 
72 строки · 2.0 Кб
1
#include "builtin.h"
2
#include "config.h"
3
#include "fmt-merge-msg.h"
4
#include "gettext.h"
5
#include "parse-options.h"
6

7
static const char * const fmt_merge_msg_usage[] = {
8
	N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
9
	NULL
10
};
11

12
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
13
{
14
	char *inpath = NULL;
15
	const char *message = NULL;
16
	char *into_name = NULL;
17
	int shortlog_len = -1;
18
	struct option options[] = {
19
		{ OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
20
		  N_("populate log with at most <n> entries from shortlog"),
21
		  PARSE_OPT_OPTARG, NULL, DEFAULT_MERGE_LOG_LEN },
22
		{ OPTION_INTEGER, 0, "summary", &shortlog_len, N_("n"),
23
		  N_("alias for --log (deprecated)"),
24
		  PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, NULL,
25
		  DEFAULT_MERGE_LOG_LEN },
26
		OPT_STRING('m', "message", &message, N_("text"),
27
			N_("use <text> as start of message")),
28
		OPT_STRING(0, "into-name", &into_name, N_("name"),
29
			   N_("use <name> instead of the real target branch")),
30
		OPT_FILENAME('F', "file", &inpath, N_("file to read from")),
31
		OPT_END()
32
	};
33

34
	FILE *in = stdin;
35
	struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
36
	int ret;
37
	struct fmt_merge_msg_opts opts;
38

39
	git_config(fmt_merge_msg_config, NULL);
40
	argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
41
			     0);
42
	if (argc > 0)
43
		usage_with_options(fmt_merge_msg_usage, options);
44
	if (shortlog_len < 0)
45
		shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
46

47
	if (inpath && strcmp(inpath, "-")) {
48
		in = fopen(inpath, "r");
49
		if (!in)
50
			die_errno("cannot open '%s'", inpath);
51
	}
52

53
	if (strbuf_read(&input, fileno(in), 0) < 0)
54
		die_errno("could not read input file");
55

56
	if (message)
57
		strbuf_addstr(&output, message);
58

59
	memset(&opts, 0, sizeof(opts));
60
	opts.add_title = !message;
61
	opts.credit_people = 1;
62
	opts.shortlog_len = shortlog_len;
63
	opts.into_name = into_name;
64

65
	ret = fmt_merge_msg(&input, &output, &opts);
66
	if (ret)
67
		return ret;
68
	write_in_full(STDOUT_FILENO, output.buf, output.len);
69

70
	free(inpath);
71
	return 0;
72
}
73

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.