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, 22:35 UTC
Message-ID
<20200807223522.GB3750245@coredump.intra.peff.net>
In-Reply-To
<20200807222630.GA3750245@coredump.intra.peff.net>
On Fri, Aug 07, 2020 at 06:26:30PM -0400, Jeff King wrote:
Show 17 quoted lines
> On Fri, Aug 07, 2020 at 03:05:27PM -0700, Junio C Hamano wrote:
> 
> > Jeff King <peff@peff.net> writes:
> > 
> > > Dropping it entirely, as below, doesn't break any tests. Junio, do you
> > > know of a case this is meant to improve?
> > 
> > I think the only conceivable case is that in the middle of a single
> > block of text in an ancient version, another block of lines gets
> > inserted during the evolution of the file, but in the end these
> > intermediate edits all go away and the same original text remains.
> > 
> > In such a case, without coalescing, we would not treat the original
> > single block of text as a single unit.
> 
> Yeah, that makes sense, and it should be possible to construct a case
> based on that.
It was even easier than I expected. :)
Try this:
  git init repo
  cd repo
  
  seq 20 >file
  git add file
  git commit -m base
  
  { seq 10; echo foo; seq 11 20; } >file
  git commit -am cruft
  
  seq 20 >file
  git commit -am revert
  git blame --root --porcelain file
With the coalescing, we get a single 20-line block:
  25d93ad4c4b27570ccd4b6412ccaa549ae6f9ff7 1 1 20
  author Jeff King
  ...
          1
  ...
  25d93ad4c4b27570ccd4b6412ccaa549ae6f9ff7 11 11
          11
and without it, we get two 10-line blocks:
  25d93ad4c4b27570ccd4b6412ccaa549ae6f9ff7 1 1 10
  author Jeff King
  ...
          1
  ...
  25d93ad4c4b27570ccd4b6412ccaa549ae6f9ff7 11 11 10
          11

I doubt it really matters all that much in practice, but it's possible some consumer of --porcelain relies on us giving minimal blocks.

So that argues for fixing blame_coalesce() to make sure that we coalesce only when the blocks are adjacent in both the source and the result. Otherwise we're losing information.

-Peff
Previous: Jeff KingNext: Jeff King
Message 7 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.