diff --git a/revision.c b/revision.c index 33cb207f28..3536635a88 100644 --- a/revision.c +++ b/revision.c @@ -1424,6 +1424,22 @@ static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, return st; } +static void remove_treesame_parents(struct commit *commit) +{ + struct commit_list **pp, *p; + + pp = &commit->parents; + while ((p = *pp) != NULL) { + struct commit *parent = p->item; + if (parent->object.flags & TREESAME) { + *pp = p->next; + free(p); + continue; + } + pp = &p->next; + } +} + static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail) { struct commit_list *p; @@ -1469,6 +1485,13 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c pst = locate_simplify_state(revs, p->item); p->item = pst->simplified; } + + /* + * A merge with a tree-same parent is useless + */ + if (commit->parents && commit->parents->next) + remove_treesame_parents(commit); + cnt = remove_duplicate_parents(commit); /* diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh index 510bb9679f..d6d79c467f 100755 --- a/t/t6012-rev-list-simplify.sh +++ b/t/t6012-rev-list-simplify.sh @@ -59,7 +59,23 @@ test_expect_success setup ' echo "Final change" >file && test_tick && git commit -a -m "Final change" && - note I + note I && + + git symbolic-ref HEAD refs/heads/unrelated && + git rm -f "*" && + echo "Unrelated branch" >side && + git add side && + test_tick && git commit -m "Side root" && + note J && + + git checkout master && + test_tick && git merge -m "Coolest" unrelated && + note K && + + echo "Immaterial" >elif && + git add elif && + test_tick && git commit -m "Last" && + note L ' FMT='tformat:%P %H | %s' @@ -82,10 +98,10 @@ check_result () { ' } -check_result 'I H G F E D C B A' --full-history -check_result 'I H E C B A' --full-history -- file -check_result 'I H E C B A' --full-history --topo-order -- file -check_result 'I H E C B A' --full-history --date-order -- file +check_result 'L K J I H G F E D C B A' --full-history +check_result 'K I H E C B A' --full-history -- file +check_result 'K I H E C B A' --full-history --topo-order -- file +check_result 'K I H E C B A' --full-history --date-order -- file check_result 'I E C B A' --simplify-merges -- file check_result 'I B A' -- file check_result 'I B A' --topo-order -- file