Skip to content

Commit 436b60c

Browse files
committed
Merge branch 'jc/remove-treesame-parent-in-simplify-merges'
The --simplify-merges logic did not cull irrelevant parents from a merge that is otherwise not interesting with respect to the paths we are following. This touches a fairly core part of the revision traversal infrastructure; even though I think this change is correct, please report immediately if you find any unintended side effect. * jc/remove-treesame-parent-in-simplify-merges: simplify-merges: drop merge from irrelevant side branch
2 parents 39c5835 + 4b7f53d commit 436b60c

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

revision.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,22 @@ static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs,
19701970
return st;
19711971
}
19721972

1973+
static void remove_treesame_parents(struct commit *commit)
1974+
{
1975+
struct commit_list **pp, *p;
1976+
1977+
pp = &commit->parents;
1978+
while ((p = *pp) != NULL) {
1979+
struct commit *parent = p->item;
1980+
if (parent->object.flags & TREESAME) {
1981+
*pp = p->next;
1982+
free(p);
1983+
continue;
1984+
}
1985+
pp = &p->next;
1986+
}
1987+
}
1988+
19731989
static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail)
19741990
{
19751991
struct commit_list *p;
@@ -2022,10 +2038,18 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
20222038
if (revs->first_parent_only)
20232039
break;
20242040
}
2025-
if (!revs->first_parent_only)
2026-
cnt = remove_duplicate_parents(commit);
2027-
else
2041+
2042+
if (revs->first_parent_only) {
20282043
cnt = 1;
2044+
} else {
2045+
/*
2046+
* A merge with a tree-same parent is useless
2047+
*/
2048+
if (commit->parents && commit->parents->next)
2049+
remove_treesame_parents(commit);
2050+
2051+
cnt = remove_duplicate_parents(commit);
2052+
}
20292053

20302054
/*
20312055
* It is possible that we are a merge and one side branch

t/t6012-rev-list-simplify.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,23 @@ test_expect_success setup '
5656
5757
echo "Final change" >file &&
5858
test_tick && git commit -a -m "Final change" &&
59-
note I
59+
note I &&
60+
61+
git symbolic-ref HEAD refs/heads/unrelated &&
62+
git rm -f "*" &&
63+
echo "Unrelated branch" >side &&
64+
git add side &&
65+
test_tick && git commit -m "Side root" &&
66+
note J &&
67+
68+
git checkout master &&
69+
test_tick && git merge -m "Coolest" unrelated &&
70+
note K &&
71+
72+
echo "Immaterial" >elif &&
73+
git add elif &&
74+
test_tick && git commit -m "Last" &&
75+
note L
6076
'
6177

6278
FMT='tformat:%P %H | %s'
@@ -79,10 +95,10 @@ check_result () {
7995
'
8096
}
8197

82-
check_result 'I H G F E D C B A' --full-history
83-
check_result 'I H E C B A' --full-history -- file
84-
check_result 'I H E C B A' --full-history --topo-order -- file
85-
check_result 'I H E C B A' --full-history --date-order -- file
98+
check_result 'L K J I H G F E D C B A' --full-history
99+
check_result 'K I H E C B A' --full-history -- file
100+
check_result 'K I H E C B A' --full-history --topo-order -- file
101+
check_result 'K I H E C B A' --full-history --date-order -- file
86102
check_result 'I E C B A' --simplify-merges -- file
87103
check_result 'I B A' -- file
88104
check_result 'I B A' --topo-order -- file

0 commit comments

Comments
 (0)