Skip to content

Commit d519082

Browse files
rscharfegitster
authored andcommitted
blame: fix coloring for repeated suspects
The option --ignore-rev passes the blame to an older commit. This can cause adjacent scoreboard entries to blame the same commit. Currently we only look at the present entry when determining whether a line needs to be colored for --color-lines. Check the previous entry as well. Reported-by: Seth McDonald <sethmcmail@pm.me> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f368df4 commit d519082

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

builtin/blame.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ static void determine_line_heat(struct commit_info *ci, const char **dest_color)
461461
*dest_color = colorfield[i].col;
462462
}
463463

464-
static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int opt)
464+
static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent,
465+
int opt, struct blame_entry *prev_ent)
465466
{
466467
int cnt;
467468
const char *cp;
@@ -492,7 +493,10 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
492493
the_hash_algo->hexsz : (size_t) abbrev;
493494

494495
if (opt & OUTPUT_COLOR_LINE) {
495-
if (cnt > 0) {
496+
if (cnt > 0 ||
497+
(prev_ent &&
498+
oideq(&suspect->commit->object.oid,
499+
&prev_ent->suspect->commit->object.oid))) {
496500
color = repeated_meta_color;
497501
reset = GIT_COLOR_RESET;
498502
} else {
@@ -578,7 +582,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
578582

579583
static void output(struct blame_scoreboard *sb, int option)
580584
{
581-
struct blame_entry *ent;
585+
struct blame_entry *ent, *prev_ent = NULL;
582586

583587
if (option & OUTPUT_PORCELAIN) {
584588
for (ent = sb->ent; ent; ent = ent->next) {
@@ -600,7 +604,8 @@ static void output(struct blame_scoreboard *sb, int option)
600604
if (option & OUTPUT_PORCELAIN)
601605
emit_porcelain(sb, ent, option);
602606
else {
603-
emit_other(sb, ent, option);
607+
emit_other(sb, ent, option, prev_ent);
608+
prev_ent = ent;
604609
}
605610
}
606611
}

t/t8012-blame-colors.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ test_expect_success 'colored blame colors contiguous lines' '
2828
test_line_count = 3 H.expect
2929
'
3030

31+
test_expect_success 'color lines becoming contiguous due to --ignore-rev' '
32+
mv hello.c hello.orig &&
33+
sed "s/ / /g" <hello.orig >hello.c &&
34+
git add hello.c &&
35+
git commit -m"tabs to spaces" &&
36+
git -c color.blame.repeatedLines=yellow blame --color-lines --ignore-rev=HEAD hello.c >actual.raw &&
37+
test_decode_color <actual.raw >actual &&
38+
grep "<YELLOW>" <actual >darkened &&
39+
grep "(F" darkened > F.expect &&
40+
grep "(H" darkened > H.expect &&
41+
test_line_count = 2 F.expect &&
42+
test_line_count = 3 H.expect
43+
'
44+
3145
test_expect_success 'color by age consistently colors old code' '
3246
git blame --color-by-age hello.c >actual.raw &&
3347
git -c blame.coloring=highlightRecent blame hello.c >actual.raw.2 &&

0 commit comments

Comments
 (0)