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 <gitster@pobox.com>
Junio C Hamano committed
Apr 25, 2015 at 12:00 UTC
34349dbff8632c353f083959881e38e1c853abf8
1 file changed
+25
-16
builtin/merge.c
+25
-16
@@ -1044,23 +1044,11 @@ static int default_edit_option(void)
1044
st_stdin.st_mode == st_stdout.st_mode);
1045
}
1046
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)
1050
{
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;
1052
1053
/*
1054
* Is the current HEAD reachable from another commit being
@@ -1088,6 +1076,27 @@ static struct commit_list *collect_parents(struct commit *head_commit,
1076
return remoteheads;
1077
}
1078
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
+
1100
int cmd_merge(int argc, const char **argv, const char *prefix)
1101
{
1102
unsigned char result_tree[20];