@matheusbsbs / matheus-bagliano / commits / 8918b0c9c2
Fork 0

merge-recur: try to merge older merge bases first

It seems to be the only sane way to do it: when a two-head merge is done, and the merge-base and one of the two branches agree, the merge assumes that the other branch has something new. If we start creating virtual commits from newer merge-bases, and go back to older merge-bases, and then merge with newer commits again, chances are that a patch is lost, _because_ the merge-base and the head agree on it. Unlikely, yes, but it happened to me. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Aug 9, 2006 at 22:30 UTC 8918b0c9c2667c5a69461955135c709b09561f72
1 file changed +12 -1
merge-recursive.c
+12 -1
@@ -1191,6 +1191,17 @@ static int merge_trees(struct tree *head,
1191 return clean;
1192 }
1193
1194 +static struct commit_list *reverse_commit_list(struct commit_list *list)
1195 +{
1196 + struct commit_list *next = NULL, *current, *backup;
1197 + for (current = list; current; current = backup) {
1198 + backup = current->next;
1199 + current->next = next;
1200 + next = current;
1201 + }
1202 + return next;
1203 +}
1204 +
1205 /*
1206 * Merge the commits h1 and h2, return the resulting virtual
1207 * commit object and a flag indicating the cleaness of the merge.
@@ -1216,7 +1227,7 @@ int merge(struct commit *h1,
1227 if (ancestor)
1228 commit_list_insert(ancestor, &ca);
1229 else
1219 - ca = get_merge_bases(h1, h2, 1);
1230 + ca = reverse_commit_list(get_merge_bases(h1, h2, 1));
1231
1232 output("found %u common ancestor(s):", commit_list_count(ca));
1233 for (iter = ca; iter; iter = iter->next)