Skip to content

Commit fd13a2e

Browse files
committed
Merge branch 'mk/blame-first-parent'
Regression fix for a topic already in master. * mk/blame-first-parent: blame: fix object casting regression
2 parents 43ed382 + 7cb5f7c commit fd13a2e

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

builtin/blame.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,10 +2402,12 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
24022402
return commit;
24032403
}
24042404

2405-
static struct object_array_entry *find_single_final(struct rev_info *revs)
2405+
static struct commit *find_single_final(struct rev_info *revs,
2406+
const char **name_p)
24062407
{
24072408
int i;
2408-
struct object_array_entry *found = NULL;
2409+
struct commit *found = NULL;
2410+
const char *name = NULL;
24092411

24102412
for (i = 0; i < revs->pending.nr; i++) {
24112413
struct object *obj = revs->pending.objects[i].item;
@@ -2417,22 +2419,20 @@ static struct object_array_entry *find_single_final(struct rev_info *revs)
24172419
die("Non commit %s?", revs->pending.objects[i].name);
24182420
if (found)
24192421
die("More than one commit to dig from %s and %s?",
2420-
revs->pending.objects[i].name,
2421-
found->name);
2422-
found = &(revs->pending.objects[i]);
2422+
revs->pending.objects[i].name, name);
2423+
found = (struct commit *)obj;
2424+
name = revs->pending.objects[i].name;
24232425
}
2426+
if (name_p)
2427+
*name_p = name;
24242428
return found;
24252429
}
24262430

24272431
static char *prepare_final(struct scoreboard *sb)
24282432
{
2429-
struct object_array_entry *found = find_single_final(sb->revs);
2430-
if (found) {
2431-
sb->final = (struct commit *) found->item;
2432-
return xstrdup(found->name);
2433-
} else {
2434-
return NULL;
2435-
}
2433+
const char *name;
2434+
sb->final = find_single_final(sb->revs, &name);
2435+
return xstrdup_or_null(name);
24362436
}
24372437

24382438
static char *prepare_initial(struct scoreboard *sb)
@@ -2720,11 +2720,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27202720
die("Cannot use --contents with final commit object name");
27212721

27222722
if (reverse && revs.first_parent_only) {
2723-
struct object_array_entry *entry = find_single_final(sb.revs);
2724-
if (!entry)
2723+
final_commit = find_single_final(sb.revs, NULL);
2724+
if (!final_commit)
27252725
die("--reverse and --first-parent together require specified latest commit");
2726-
else
2727-
final_commit = (struct commit*) entry->item;
27282726
}
27292727

27302728
/*

t/annotate-tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ test_expect_success 'blame 1 author' '
6868
check_count A 2
6969
'
7070

71+
test_expect_success 'blame by tag objects' '
72+
git tag -m "test tag" testTag &&
73+
git tag -m "test tag #2" testTag2 testTag &&
74+
check_count -h testTag A 2 &&
75+
check_count -h testTag2 A 2
76+
'
77+
7178
test_expect_success 'setup B lines' '
7279
echo "2A quick brown fox jumps over the" >>file &&
7380
echo "lazy dog" >>file &&

0 commit comments

Comments
 (0)