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

Re: difflame

From
Jeff King <peff@peff.net>
Date
Jan 28, 2017, 03:53 UTC
Message-ID
<20170128035321.yrcqwkg2fiwadxj4@sigill.intra.peff.net>
In-Reply-To
<CAOc6etaCk=OEyarMNhorM94MBnYRscCkJBM-K08snv1ecmOaPQ@mail.gmail.com>
On Tue, Jan 17, 2017 at 11:24:02PM -0600, Edmundo Carmona Antoranz wrote:
> For a very long time I had wanted to get the output of diff to include
> blame information as well (to see when something was added/removed).

This is something I've wanted, too. The trickiest part, though, is blaming deletions, because git-blame only tracks the origin of content, not the origin of a change.

For example, try this case:
  git init
  for i in $(seq 1 10); do
    echo $i >>file
    git add file
    git commit -m "add $i"
  done
  sed 4d <file >tmp && mv tmp file
  git commit -am "drop 4"
Running "difflame HEAD~5 HEAD" produces this output:
  diff --git a/file b/file
  index b414108..051c298 100644
  --- a/file
  +++ b/file
  @@ -1,6 +1,9 @@
   ^2b028ff (Jeff King 2017-01-27 22:44:10 -0500 1) 1
   ed056366 (Jeff King 2017-01-27 22:44:10 -0500 2) 2
   771030d8 (Jeff King 2017-01-27 22:44:10 -0500 3) 3
  -89c09c82 (Jeff King 2017-01-27 22:44:10 -0500 4) 4
   b619039c (Jeff King 2017-01-27 22:44:10 -0500 4) 5
   6a7aa0e5 (Jeff King 2017-01-27 22:44:10 -0500 5) 6
  +39bc9dc4 (Jeff King 2017-01-27 22:44:10 -0500 6) 7
  +f253cc8f (Jeff King 2017-01-27 22:44:10 -0500 7) 8
  +85c10f46 (Jeff King 2017-01-27 22:44:10 -0500 8) 9
  +89c09c82 (Jeff King 2017-01-27 22:44:10 -0500 9) 10

The last 4 lines are right; they correspond to the addition commits. But the line taking away 4 is wrong. You can see even without looking at its patch, because it is blamed to the same commit that added "10", which is wrong.

Sorry I don't have a solution. I think it's an open problem with git-blame, though you could probably script something around "git blame --reverse". See the commit message of 85af7929e (git-blame --reverse, 2008-04-02) for some discussion.

-Peff
Previous: Edmundo Carmona AntoranzNext: Junio C Hamano
Message 2 of 8 in “difflame”
  1. Edmundo Carmona AntoranzJan 18, 2017
  2. Jeff KingJan 28, 2017
  3. Junio C HamanoJan 30, 2017
  4. Jeff KingJan 30, 2017
  5. Edmundo Carmona AntoranzJan 31, 2017
  6. Edmundo Carmona AntoranzJan 31, 2017
  7. Edmundo Carmona AntoranzFeb 3, 2017
  8. Edmundo Carmona AntoranzFeb 3, 2017

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.