Skip to content

Commit

Permalink
merge: make collect_parents() auto-generate the merge message
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Apr 29, 2015
1 parent 52fecab commit 1cf32f4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,8 @@ static void prepare_merge_message(struct strbuf *merge_names, struct strbuf *mer

static struct commit_list *collect_parents(struct commit *head_commit,
int *head_subsumed,
int argc, const char **argv)
int argc, const char **argv,
struct strbuf *merge_msg)
{
int i;
struct commit_list *remoteheads = NULL;
Expand All @@ -1108,7 +1109,20 @@ static struct commit_list *collect_parents(struct commit *head_commit,
remotes = &commit_list_insert(commit, remotes)->next;
}

return reduce_parents(head_commit, head_subsumed, remoteheads);
remoteheads = reduce_parents(head_commit, head_subsumed, remoteheads);

if (merge_msg &&
(!have_message || shortlog_len)) {
struct strbuf merge_names = STRBUF_INIT;
struct commit_list *p;

for (p = remoteheads; p; p = p->next)
merge_name(merge_remote_util(p->item)->name, &merge_names);
prepare_merge_message(&merge_names, merge_msg);
strbuf_release(&merge_names);
}

return remoteheads;
}

int cmd_merge(int argc, const char **argv, const char *prefix)
Expand Down Expand Up @@ -1222,7 +1236,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (fast_forward == FF_NO)
die(_("Non-fast-forward commit does not make sense into "
"an empty head"));
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
remoteheads = collect_parents(head_commit, &head_subsumed,
argc, argv, NULL);
remote_head = remoteheads->item;
if (!remote_head)
die(_("%s - not something we can merge"), argv[0]);
Expand All @@ -1248,7 +1263,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
head_arg = argv[1];
argv += 2;
argc -= 2;
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
remoteheads = collect_parents(head_commit, &head_subsumed,
argc, argv, NULL);
} else {
/* We are invoked directly as the first-class UI. */
head_arg = "HEAD";
Expand All @@ -1258,16 +1274,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* the standard merge summary message to be appended
* to the given message.
*/
remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);

if (!have_message || shortlog_len) {
struct strbuf merge_names = STRBUF_INIT;

for (p = remoteheads; p; p = p->next)
merge_name(merge_remote_util(p->item)->name, &merge_names);
prepare_merge_message(&merge_names, &merge_msg);
strbuf_release(&merge_names);
}
remoteheads = collect_parents(head_commit, &head_subsumed,
argc, argv, &merge_msg);
}

if (!head_commit || !argc)
Expand Down

0 comments on commit 1cf32f4

Please sign in to comment.