Skip to content

Commit 0b10b8a

Browse files
committed
merge: clarify collect_parents() logic
Clarify this small function in three ways. - The function initially collects all commits to be merged into a commit_list "remoteheads"; the "remotes" pointer always points at the tail of this list (either the remoteheads variable itself, or the ->next slot of the element at the end of the list) to help elongate the list by repeated calls to commit_list_insert(). Because the new element appended by commit_list_insert() will always have its ->next slot NULLed out, there is no need for us to assign NULL to *remotes to terminate the list at the end. - The variable "head_subsumed" always confused me every time I read this code. What is happening here is that we inspect what the caller told us to merge (including the current HEAD) and come up with the list of parents to be recorded for the resulting merge commit, omitting commits that are ancestor of other commits. This filtering may remove the current HEAD from the resulting parent list---and we signal that fact with this variable, so that we can later record it as the first parent when "--no-ff" is in effect. - The "parents" list is created for this function by reduce_heads() and was not deallocated after its use, even though the loop control was written in such a way to allow us to do so by taking the "next" element in a separate variable so that it can be used in the next-step part of the loop control. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1016658 commit 0b10b8a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

builtin/merge.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,11 +1061,19 @@ static struct commit_list *collect_parents(struct commit *head_commit,
10611061
"not something we can merge");
10621062
remotes = &commit_list_insert(commit, remotes)->next;
10631063
}
1064-
*remotes = NULL;
10651064

1065+
/*
1066+
* Is the current HEAD reachable from another commit being
1067+
* merged? If so we do not want to record it as a parent of
1068+
* the resulting merge, unless --no-ff is given. We will flip
1069+
* this variable to 0 when we find HEAD among the independent
1070+
* tips being merged.
1071+
*/
1072+
*head_subsumed = 1;
1073+
1074+
/* Find what parents to record by checking independent ones. */
10661075
parents = reduce_heads(remoteheads);
10671076

1068-
*head_subsumed = 1; /* we will flip this to 0 when we find it */
10691077
for (remoteheads = NULL, remotes = &remoteheads;
10701078
parents;
10711079
parents = next) {
@@ -1075,6 +1083,7 @@ static struct commit_list *collect_parents(struct commit *head_commit,
10751083
*head_subsumed = 0;
10761084
else
10771085
remotes = &commit_list_insert(commit, remotes)->next;
1086+
free(parents);
10781087
}
10791088
return remoteheads;
10801089
}

0 commit comments

Comments
 (0)