Skip to content

Commit 6440fdb

Browse files
committed
in_merge_bases(): use paint_down_to_common()
With paint_down_to_common(), we can tell if "commit" is reachable from "reference" by simply looking at its object flag, instead of iterating over the merge bases. Signed-off-by: Junio C Hamano <[email protected]>
1 parent da1f515 commit 6440fdb

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

commit.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,20 +786,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
786786
*/
787787
int in_merge_bases(struct commit *commit, struct commit *reference)
788788
{
789-
struct commit_list *bases, *b;
789+
struct commit_list *bases;
790790
int ret = 0;
791791

792-
bases = merge_bases_many(commit, 1, &reference);
792+
if (parse_commit(commit) || parse_commit(reference))
793+
return ret;
794+
795+
bases = paint_down_to_common(commit, 1, &reference);
796+
if (commit->object.flags & PARENT2)
797+
ret = 1;
793798
clear_commit_marks(commit, all_flags);
794799
clear_commit_marks(reference, all_flags);
795-
796-
for (b = bases; b; b = b->next) {
797-
if (!hashcmp(commit->object.sha1, b->item->object.sha1)) {
798-
ret = 1;
799-
break;
800-
}
801-
}
802-
803800
free_commit_list(bases);
804801
return ret;
805802
}

0 commit comments

Comments
 (0)