merge: extract prepare_merge_message() logic out

Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 25, 2015 at 18:29 UTC 52fecab20cf28f4b5621e502a265ba551a26877e
1 file changed +15 -11
builtin/merge.c
+15 -11
@@ -1076,6 +1076,20 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
1076 return remoteheads;
1077 }
1078
1079 +static void prepare_merge_message(struct strbuf *merge_names, struct strbuf *merge_msg)
1080 +{
1081 + struct fmt_merge_msg_opts opts;
1082 +
1083 + memset(&opts, 0, sizeof(opts));
1084 + opts.add_title = !have_message;
1085 + opts.shortlog_len = shortlog_len;
1086 + opts.credit_people = (0 < option_edit);
1087 +
1088 + fmt_merge_msg(merge_names, merge_msg, &opts);
1089 + if (merge_msg->len)
1090 + strbuf_setlen(merge_msg, merge_msg->len - 1);
1091 +}
1092 +
1093 static struct commit_list *collect_parents(struct commit *head_commit,
1094 int *head_subsumed,
1095 int argc, const char **argv)
@@ -1248,20 +1262,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1262
1263 if (!have_message || shortlog_len) {
1264 struct strbuf merge_names = STRBUF_INIT;
1251 - struct fmt_merge_msg_opts opts;
1265
1266 for (p = remoteheads; p; p = p->next)
1267 merge_name(merge_remote_util(p->item)->name, &merge_names);
1255 -
1256 - memset(&opts, 0, sizeof(opts));
1257 - opts.add_title = !have_message;
1258 - opts.shortlog_len = shortlog_len;
1259 - opts.credit_people = (0 < option_edit);
1260 -
1261 - fmt_merge_msg(&merge_names, &merge_msg, &opts);
1262 - if (merge_msg.len)
1263 - strbuf_setlen(&merge_msg, merge_msg.len - 1);
1264 -
1268 + prepare_merge_message(&merge_names, &merge_msg);
1269 strbuf_release(&merge_names);
1270 }
1271 }