Skip to content

Commit 34349db

Browse files
committed
merge: split reduce_parents() out of collect_parents()
The latter does two separate things: - Parse the list of commits on the command line, and formulate the list of commits to be merged (including the current HEAD); - Compute the list of parents to be recorded in the resulting merge commit. Split the latter into a separate helper function, so that we can later supply the list commits to be merged from a different source (namely, FETCH_HEAD). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b10b8a commit 34349db

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

builtin/merge.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,23 +1044,11 @@ static int default_edit_option(void)
10441044
st_stdin.st_mode == st_stdout.st_mode);
10451045
}
10461046

1047-
static struct commit_list *collect_parents(struct commit *head_commit,
1048-
int *head_subsumed,
1049-
int argc, const char **argv)
1047+
static struct commit_list *reduce_parents(struct commit *head_commit,
1048+
int *head_subsumed,
1049+
struct commit_list *remoteheads)
10501050
{
1051-
int i;
1052-
struct commit_list *remoteheads = NULL, *parents, *next;
1053-
struct commit_list **remotes = &remoteheads;
1054-
1055-
if (head_commit)
1056-
remotes = &commit_list_insert(head_commit, remotes)->next;
1057-
for (i = 0; i < argc; i++) {
1058-
struct commit *commit = get_merge_parent(argv[i]);
1059-
if (!commit)
1060-
help_unknown_ref(argv[i], "merge",
1061-
"not something we can merge");
1062-
remotes = &commit_list_insert(commit, remotes)->next;
1063-
}
1051+
struct commit_list *parents, *next, **remotes = &remoteheads;
10641052

10651053
/*
10661054
* Is the current HEAD reachable from another commit being
@@ -1088,6 +1076,27 @@ static struct commit_list *collect_parents(struct commit *head_commit,
10881076
return remoteheads;
10891077
}
10901078

1079+
static struct commit_list *collect_parents(struct commit *head_commit,
1080+
int *head_subsumed,
1081+
int argc, const char **argv)
1082+
{
1083+
int i;
1084+
struct commit_list *remoteheads = NULL;
1085+
struct commit_list **remotes = &remoteheads;
1086+
1087+
if (head_commit)
1088+
remotes = &commit_list_insert(head_commit, remotes)->next;
1089+
for (i = 0; i < argc; i++) {
1090+
struct commit *commit = get_merge_parent(argv[i]);
1091+
if (!commit)
1092+
help_unknown_ref(argv[i], "merge",
1093+
"not something we can merge");
1094+
remotes = &commit_list_insert(commit, remotes)->next;
1095+
}
1096+
1097+
return reduce_parents(head_commit, head_subsumed, remoteheads);
1098+
}
1099+
10911100
int cmd_merge(int argc, const char **argv, const char *prefix)
10921101
{
10931102
unsigned char result_tree[20];

0 commit comments

Comments
 (0)