From d519082d4ebf998cd9d10a5ef33544a479e7699c Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sun, 1 Feb 2026 12:47:53 +0100 Subject: blame: fix coloring for repeated suspects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- builtin/blame.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/blame.c b/builtin/blame.c index 944952e30e..4c946d2cf1 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -461,7 +461,8 @@ static void determine_line_heat(struct commit_info *ci, const char **dest_color) *dest_color = colorfield[i].col; } -static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int opt) +static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, + int opt, struct blame_entry *prev_ent) { int cnt; const char *cp; @@ -492,7 +493,10 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int the_hash_algo->hexsz : (size_t) abbrev; if (opt & OUTPUT_COLOR_LINE) { - if (cnt > 0) { + if (cnt > 0 || + (prev_ent && + oideq(&suspect->commit->object.oid, + &prev_ent->suspect->commit->object.oid))) { color = repeated_meta_color; reset = GIT_COLOR_RESET; } else { @@ -578,7 +582,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int static void output(struct blame_scoreboard *sb, int option) { - struct blame_entry *ent; + struct blame_entry *ent, *prev_ent = NULL; if (option & OUTPUT_PORCELAIN) { for (ent = sb->ent; ent; ent = ent->next) { @@ -600,7 +604,8 @@ static void output(struct blame_scoreboard *sb, int option) if (option & OUTPUT_PORCELAIN) emit_porcelain(sb, ent, option); else { - emit_other(sb, ent, option); + emit_other(sb, ent, option, prev_ent); + prev_ent = ent; } } } -- cgit v1.3-5-g9baa