提交 95a4fb0e 编写于 作者: J Jeff King 提交者: Junio C Hamano

blame: handle --first-parent

The revision.c options-parser will parse "--first-parent"
for us, but the blame code does not actually respect it, as
we simply iterate over the whole list returned by
first_scapegoat(). We can fix this by returning a
truncated parent list.

Note that we could technically also do so by limiting the
return value of num_scapegoats(), but that is less robust.
We would rely on nobody ever looking at the "next" pointer
from the returned list.

Combining "--reverse" with "--first-parent" is more
complicated, and will probably involve cooperation from
revision.c. Since the desired semantics are not even clear,
let's punt on this for now, but explicitly disallow it to
avoid confusing users (this is not really a regression,
since it did something nonsensical before).
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 27ea6f85
......@@ -1365,8 +1365,15 @@ static void pass_whole_blame(struct scoreboard *sb,
*/
static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit)
{
if (!reverse)
if (!reverse) {
if (revs->first_parent_only &&
commit->parents &&
commit->parents->next) {
free_commit_list(commit->parents->next);
commit->parents->next = NULL;
}
return commit->parents;
}
return lookup_decoration(&revs->children, &commit->object);
}
......@@ -2677,6 +2684,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
}
else if (contents_from)
die("--contents and --children do not blend well.");
else if (revs.first_parent_only)
die("combining --first-parent and --reverse is not supported");
else {
final_commit_name = prepare_initial(&sb);
sb.commits.compare = compare_commits_by_reverse_commit_date;
......
......@@ -111,6 +111,10 @@ test_expect_success 'blame 2 authors + 2 merged-in authors' '
check_count A 2 B 1 B1 2 B2 1
'
test_expect_success 'blame --first-parent blames merge for branch1' '
check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
'
test_expect_success 'blame ancestor' '
check_count -h master A 2 B 2
'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册