fmt-merge-msg: package options into a structure

This way new features can be added more easily

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2011-11-04 17:35:42 -07:00
Родитель 4c0ea82da3
Коммит cbda121c99
3 изменённых файлов: 27 добавлений и 18 удалений

Просмотреть файл

@ -14,8 +14,14 @@ extern const char git_usage_string[];
extern const char git_more_info_string[]; extern const char git_more_info_string[];
extern void prune_packed_objects(int); extern void prune_packed_objects(int);
struct fmt_merge_msg_opts {
unsigned add_title:1;
int shortlog_len;
};
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out, extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
int merge_title, int shortlog_len); struct fmt_merge_msg_opts *);
extern void commit_notes(struct notes_tree *t, const char *msg); extern void commit_notes(struct notes_tree *t, const char *msg);
struct notes_rewrite_cfg { struct notes_rewrite_cfg {

Просмотреть файл

@ -209,7 +209,7 @@ static void shortlog(const char *name, unsigned char *sha1,
string_list_clear(&subjects, 0); string_list_clear(&subjects, 0);
} }
static void do_fmt_merge_msg_title(struct strbuf *out, static void fmt_merge_msg_title(struct strbuf *out,
const char *current_branch) { const char *current_branch) {
int i = 0; int i = 0;
char *sep = ""; char *sep = "";
@ -262,8 +262,9 @@ static void do_fmt_merge_msg_title(struct strbuf *out,
strbuf_addf(out, " into %s\n", current_branch); strbuf_addf(out, " into %s\n", current_branch);
} }
static int do_fmt_merge_msg(int merge_title, struct strbuf *in, int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct strbuf *out, int shortlog_len) { struct fmt_merge_msg_opts *opts)
{
int i = 0, pos = 0; int i = 0, pos = 0;
unsigned char head_sha1[20]; unsigned char head_sha1[20];
const char *current_branch; const char *current_branch;
@ -289,10 +290,10 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
die ("Error in line %d: %.*s", i, len, p); die ("Error in line %d: %.*s", i, len, p);
} }
if (merge_title && srcs.nr) if (opts->add_title && srcs.nr)
do_fmt_merge_msg_title(out, current_branch); fmt_merge_msg_title(out, current_branch);
if (shortlog_len) { if (opts->shortlog_len) {
struct commit *head; struct commit *head;
struct rev_info rev; struct rev_info rev;
@ -307,18 +308,13 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
for (i = 0; i < origins.nr; i++) for (i = 0; i < origins.nr; i++)
shortlog(origins.items[i].string, origins.items[i].util, shortlog(origins.items[i].string, origins.items[i].util,
head, &rev, shortlog_len, out); head, &rev, opts->shortlog_len, out);
} }
if (out->len && out->buf[out->len-1] != '\n') if (out->len && out->buf[out->len-1] != '\n')
strbuf_addch(out, '\n'); strbuf_addch(out, '\n');
return 0; return 0;
} }
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
int merge_title, int shortlog_len) {
return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
}
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
{ {
const char *inpath = NULL; const char *inpath = NULL;
@ -340,6 +336,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
FILE *in = stdin; FILE *in = stdin;
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT; struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
int ret; int ret;
struct fmt_merge_msg_opts opts;
git_config(fmt_merge_msg_config, NULL); git_config(fmt_merge_msg_config, NULL);
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage, argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
@ -361,10 +358,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
if (message) if (message)
strbuf_addstr(&output, message); strbuf_addstr(&output, message);
ret = fmt_merge_msg(&input, &output,
message ? 0 : 1,
shortlog_len);
memset(&opts, 0, sizeof(opts));
opts.add_title = !message;
opts.shortlog_len = shortlog_len;
ret = fmt_merge_msg(&input, &output, &opts);
if (ret) if (ret)
return ret; return ret;
write_in_full(STDOUT_FILENO, output.buf, output.len); write_in_full(STDOUT_FILENO, output.buf, output.len);

Просмотреть файл

@ -1229,8 +1229,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
merge_name(argv[i], &merge_names); merge_name(argv[i], &merge_names);
if (!have_message || shortlog_len) { if (!have_message || shortlog_len) {
fmt_merge_msg(&merge_names, &merge_msg, !have_message, struct fmt_merge_msg_opts opts;
shortlog_len); memset(&opts, 0, sizeof(opts));
opts.add_title = !have_message;
opts.shortlog_len = shortlog_len;
fmt_merge_msg(&merge_names, &merge_msg, &opts);
if (merge_msg.len) if (merge_msg.len)
strbuf_setlen(&merge_msg, merge_msg.len - 1); strbuf_setlen(&merge_msg, merge_msg.len - 1);
} }