提交 beb5af43 编写于 作者: A Adam Simpkins 提交者: Junio C Hamano

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 f29ac4f1 and 66996ecc, among other places.
Signed-off-by: NAdam Simpkins <simpkins@facebook.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 83e355a6
...@@ -286,9 +286,10 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit) ...@@ -286,9 +286,10 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
} }
/* /*
* Uninteresting and pruned commits won't be printed * Otherwise, use get_commit_action() to see if this commit is
* interesting
*/ */
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1; return get_commit_action(graph->revs, commit) == commit_show;
} }
static struct commit_list *next_interesting_parent(struct git_graph *graph, static struct commit_list *next_interesting_parent(struct git_graph *graph,
......
...@@ -1664,7 +1664,7 @@ static inline int want_ancestry(struct rev_info *revs) ...@@ -1664,7 +1664,7 @@ static inline int want_ancestry(struct rev_info *revs)
return (revs->rewrite_parents || revs->children.name); return (revs->rewrite_parents || revs->children.name);
} }
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit)
{ {
if (commit->object.flags & SHOWN) if (commit->object.flags & SHOWN)
return commit_ignore; return commit_ignore;
...@@ -1692,12 +1692,23 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) ...@@ -1692,12 +1692,23 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
if (!commit->parents || !commit->parents->next) if (!commit->parents || !commit->parents->next)
return commit_ignore; return commit_ignore;
} }
if (want_ancestry(revs) && rewrite_parents(revs, commit) < 0)
return commit_error;
} }
return commit_show; return commit_show;
} }
enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
{
enum commit_action action = get_commit_action(revs, commit);
if (action == commit_show &&
!revs->show_all &&
revs->prune && revs->dense && want_ancestry(revs)) {
if (rewrite_parents(revs, commit) < 0)
return commit_error;
}
return action;
}
static struct commit *get_revision_1(struct rev_info *revs) static struct commit *get_revision_1(struct rev_info *revs)
{ {
if (!revs->commits) if (!revs->commits)
......
...@@ -165,6 +165,7 @@ enum commit_action { ...@@ -165,6 +165,7 @@ enum commit_action {
commit_error commit_error
}; };
extern enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit);
extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit); extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
#endif #endif
#!/bin/sh
test_description='--show-all --parents does not rewrite TREESAME commits'
. ./test-lib.sh
test_expect_success 'set up --show-all --parents test' '
test_commit one foo.txt &&
commit1=`git rev-list -1 HEAD` &&
test_commit two bar.txt &&
commit2=`git rev-list -1 HEAD` &&
test_commit three foo.txt &&
commit3=`git rev-list -1 HEAD`
'
test_expect_success '--parents rewrites TREESAME parents correctly' '
echo $commit3 $commit1 > expected &&
echo $commit1 >> expected &&
git rev-list --parents HEAD -- foo.txt > actual &&
test_cmp expected actual
'
test_expect_success '--parents --show-all does not rewrites TREESAME parents' '
echo $commit3 $commit2 > expected &&
echo $commit2 $commit1 >> expected &&
echo $commit1 >> expected &&
git rev-list --parents --show-all HEAD -- foo.txt > actual &&
test_cmp expected actual
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册