Skip to content

Commit 95a4fb0

Browse files
peffgitster
authored andcommitted
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: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27ea6f8 commit 95a4fb0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

builtin/blame.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,15 @@ static void pass_whole_blame(struct scoreboard *sb,
13651365
*/
13661366
static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit)
13671367
{
1368-
if (!reverse)
1368+
if (!reverse) {
1369+
if (revs->first_parent_only &&
1370+
commit->parents &&
1371+
commit->parents->next) {
1372+
free_commit_list(commit->parents->next);
1373+
commit->parents->next = NULL;
1374+
}
13691375
return commit->parents;
1376+
}
13701377
return lookup_decoration(&revs->children, &commit->object);
13711378
}
13721379

@@ -2677,6 +2684,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26772684
}
26782685
else if (contents_from)
26792686
die("--contents and --children do not blend well.");
2687+
else if (revs.first_parent_only)
2688+
die("combining --first-parent and --reverse is not supported");
26802689
else {
26812690
final_commit_name = prepare_initial(&sb);
26822691
sb.commits.compare = compare_commits_by_reverse_commit_date;

t/annotate-tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ test_expect_success 'blame 2 authors + 2 merged-in authors' '
111111
check_count A 2 B 1 B1 2 B2 1
112112
'
113113

114+
test_expect_success 'blame --first-parent blames merge for branch1' '
115+
check_count --first-parent A 2 B 1 "A U Thor" 2 B2 1
116+
'
117+
114118
test_expect_success 'blame ancestor' '
115119
check_count -h master A 2 B 2
116120
'

0 commit comments

Comments
 (0)