git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] blame: only coalesce lines that are adjacent in result

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 13, 2020, 16:59 UTC
Message-ID
<xmqq8sei4h40.fsf@gitster.c.googlers.com>
In-Reply-To
<20200813052531.GC2514880@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 12 quoted lines
> diff --git a/blame.c b/blame.c
> index 82fa16d658..1be1cd82a2 100644
> --- a/blame.c
> +++ b/blame.c
> @@ -1184,6 +1184,7 @@ void blame_coalesce(struct blame_scoreboard *sb)
>  	for (ent = sb->ent; ent && (next = ent->next); ent = next) {
>  		if (ent->suspect == next->suspect &&
>  		    ent->s_lno + ent->num_lines == next->s_lno &&
> +		    ent->lno + ent->num_lines == next->lno &&
>  		    ent->ignored == next->ignored &&
>  		    ent->unblamable == next->unblamable) {
>  			ent->num_lines += next->num_lines;

When laid out like this, the correctness of the fix is quite obvious and it is surprising that this bug has survived for all these years, as it dates back to cee7f245 (git-pickaxe: blame rewritten., 2006-10-19), the inception of the current "git blame".

Thanks.
Show 18 quoted lines
> diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
> index 7f39a84289..ba8013b002 100755
> --- a/t/t8003-blame-corner-cases.sh
> +++ b/t/t8003-blame-corner-cases.sh
> @@ -310,4 +310,13 @@ test_expect_success 'blame coalesce' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'blame does not coalesce non-adjacent result lines' '
> +	cat >expect <<-EOF &&
> +	$orig 1) ABC
> +	$orig 3) DEF
> +	EOF
> +	git blame --no-abbrev -s -L1,1 -L3,3 $split giraffe >actual &&
> +	test_cmp expect actual
> +'
> +
>  test_done
Previous: Jeff KingNext: Junio C Hamano
Message 14 of 16 in “`git blame` Line Number Off-by-one”
  1. Nuthan MunaiahAug 7, 2020
  2. Jeff KingAug 7, 2020
  3. Jeff KingAug 7, 2020
  4. Jeff KingAug 7, 2020
  5. Junio C HamanoAug 7, 2020
  6. Jeff KingAug 7, 2020
  7. Jeff KingAug 7, 2020
  8. 0/3 blame: fix bug in coalescing non-adjacent "-L" chunksJeff King, Aug 13, 2020
  9. 1/3 t8003: check output of coalesced blameJeff King, Aug 13, 2020
  10. Junio C HamanoAug 13, 2020
  11. Jeff KingAug 13, 2020
  12. 2/3 t8003: factor setup out of coalesce testJeff King, Aug 13, 2020
  13. 3/3 blame: only coalesce lines that are adjacent in resultJeff King, Aug 13, 2020
  14. Junio C HamanoAug 13, 2020
  15. Junio C HamanoAug 13, 2020
  16. Barret RhodenAug 13, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.