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

Re: `git blame` Line Number Off-by-one

From
Jeff King <peff@peff.net>
Date
Aug 7, 2020, 21:45 UTC
Message-ID
<20200807214533.GC1871940@coredump.intra.peff.net>
In-Reply-To
<20200807213349.GB1871940@coredump.intra.peff.net>
On Fri, Aug 07, 2020 at 05:33:49PM -0400, Jeff King wrote:
Show 15 quoted lines
> Dropping it entirely, as below, doesn't break any tests. Junio, do you
> know of a case this is meant to improve?
> [...]
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 94ef57c1cc..ce564a5916 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -1143,8 +1143,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
>  
>  	blame_sort_final(&sb);
>  
> -	blame_coalesce(&sb);
> -
>  	if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
>  		output_option |= coloring_mode;

I wondered also whether this sort was necessary (obviously it is for coalescing, but is it otherwise?). But there are definitely tests that break if it's removed (e.g. t8011-blame-split-file). And it's sorting on "lno", which implies that yes, in some cases we may end up with a contiguous block of final-result lines that was broken up and shuffled around.

I'm not sure if that implies a case where source-coalescing could help. Would you ever have such a case where they end up blaming to the same commit?

I'm not sure. If so, then it would probably make sense for blame_coalesce() to make sure that the ent->lno and next->lno blocks are contiguous (as well as the s_lno ones).

But even if that's true, I'm not sure that this coalescing is really all that beneficial. It doesn't impact the normal blame output at all (which is line oriented anyway, and repeats information). It doesn't make --porcelain more efficient, because we omit repeated commit details even for non-contiguous blocks. It would let a consumer of --porcelain see bigger blocks which could be useful for coloring, etc.

So I dunno. I'd still be curious to see a concrete case where this code triggers and does something useful.

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 4 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.