Skip to content

Commit beb5af4

Browse files
Adam Simpkinsgitster
authored andcommitted
graph API: fix bug in graph_is_interesting()
Previously, graph_is_interesting() did not behave quite the same way as the code in get_revision(). As a result, it would sometimes think commits were uninteresting, even though get_revision() would return them. This resulted in incorrect lines in the graph output. This change creates a get_commit_action() function, which graph_is_interesting() and simplify_commit() both now use to determine if a commit will be shown. It is identical to the old simplify_commit() behavior, except that it never calls rewrite_parents(). This problem was reported by Santi Béjar. The following command would exhibit the problem before, but now works correctly: git log --graph --simplify-by-decoration --oneline v1.6.3.3 Previously git graph did not display the output for this command correctly between f29ac4f and 66996ec, among other places. Signed-off-by: Adam Simpkins <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83e355a commit beb5af4

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

graph.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
286286
}
287287

288288
/*
289-
* Uninteresting and pruned commits won't be printed
289+
* Otherwise, use get_commit_action() to see if this commit is
290+
* interesting
290291
*/
291-
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
292+
return get_commit_action(graph->revs, commit) == commit_show;
292293
}
293294

294295
static struct commit_list *next_interesting_parent(struct git_graph *graph,

revision.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ static inline int want_ancestry(struct rev_info *revs)
16641664
return (revs->rewrite_parents || revs->children.name);
16651665
}
16661666

1667-
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1667+
enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit)
16681668
{
16691669
if (commit->object.flags & SHOWN)
16701670
return commit_ignore;
@@ -1692,12 +1692,23 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
16921692
if (!commit->parents || !commit->parents->next)
16931693
return commit_ignore;
16941694
}
1695-
if (want_ancestry(revs) && rewrite_parents(revs, commit) < 0)
1696-
return commit_error;
16971695
}
16981696
return commit_show;
16991697
}
17001698

1699+
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1700+
{
1701+
enum commit_action action = get_commit_action(revs, commit);
1702+
1703+
if (action == commit_show &&
1704+
!revs->show_all &&
1705+
revs->prune && revs->dense && want_ancestry(revs)) {
1706+
if (rewrite_parents(revs, commit) < 0)
1707+
return commit_error;
1708+
}
1709+
return action;
1710+
}
1711+
17011712
static struct commit *get_revision_1(struct rev_info *revs)
17021713
{
17031714
if (!revs->commits)

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ enum commit_action {
165165
commit_error
166166
};
167167

168+
extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
168169
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
169170

170171
#endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
test_description='--show-all --parents does not rewrite TREESAME commits'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'set up --show-all --parents test' '
8+
test_commit one foo.txt &&
9+
commit1=`git rev-list -1 HEAD` &&
10+
test_commit two bar.txt &&
11+
commit2=`git rev-list -1 HEAD` &&
12+
test_commit three foo.txt &&
13+
commit3=`git rev-list -1 HEAD`
14+
'
15+
16+
test_expect_success '--parents rewrites TREESAME parents correctly' '
17+
echo $commit3 $commit1 > expected &&
18+
echo $commit1 >> expected &&
19+
git rev-list --parents HEAD -- foo.txt > actual &&
20+
test_cmp expected actual
21+
'
22+
23+
test_expect_success '--parents --show-all does not rewrites TREESAME parents' '
24+
echo $commit3 $commit2 > expected &&
25+
echo $commit2 $commit1 >> expected &&
26+
echo $commit1 >> expected &&
27+
git rev-list --parents --show-all HEAD -- foo.txt > actual &&
28+
test_cmp expected actual
29+
'
30+
31+
test_done

0 commit comments

Comments
 (0)