Skip to content

Commit 06cef76

Browse files
committed
Merge branch 'rs/blame-ignore-colors-fix'
"git blame --ignore-revs=... --color-lines" did not account for ignored revisions passing blame to the same commit an adjacent line gets blamed for. * rs/blame-ignore-colors-fix: blame: fix coloring for repeated suspects
2 parents ea03b35 + d519082 commit 06cef76

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
@@ -454,7 +454,8 @@ static void determine_line_heat(struct commit_info *ci, const char **dest_color)
454454
*dest_color = colorfield[i].col;
455455
}
456456

457-
static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int opt)
457+
static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent,
458+
int opt, struct blame_entry *prev_ent)
458459
{
459460
int cnt;
460461
const char *cp;
@@ -485,7 +486,10 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
485486
the_hash_algo->hexsz : (size_t) abbrev;
486487

487488
if (opt & OUTPUT_COLOR_LINE) {
488-
if (cnt > 0) {
489+
if (cnt > 0 ||
490+
(prev_ent &&
491+
oideq(&suspect->commit->object.oid,
492+
&prev_ent->suspect->commit->object.oid))) {
489493
color = repeated_meta_color;
490494
reset = GIT_COLOR_RESET;
491495
} else {
@@ -571,7 +575,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
571575

572576
static void output(struct blame_scoreboard *sb, int option)
573577
{
574-
struct blame_entry *ent;
578+
struct blame_entry *ent, *prev_ent = NULL;
575579

576580
if (option & OUTPUT_PORCELAIN) {
577581
for (ent = sb->ent; ent; ent = ent->next) {
@@ -593,7 +597,8 @@ static void output(struct blame_scoreboard *sb, int option)
593597
if (option & OUTPUT_PORCELAIN)
594598
emit_porcelain(sb, ent, option);
595599
else {
596-
emit_other(sb, ent, option);
600+
emit_other(sb, ent, option, prev_ent);
601+
prev_ent = ent;
597602
}
598603
}
599604
}

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)