librelist archives

« back to archive

Blame

Blame

From:
Ignacio Casal Quinteiro
Date:
2013-01-29 @ 12:32
Hi,

do any of you know what would be the best way to implement the blame for a
file?

Regards.

-- 
Ignacio Casal Quinteiro

Re: [libgit2] Blame

From:
Carlos Martin Nieto
Date:
2013-02-02 @ 13:45
Ignacio Casal Quinteiro <nacho.resa@gmail.com> writes:

> Hi,
>
> do any of you know what would be the best way to implement the blame
> for a file?

Hey,

First of all, blame is going be somwhat painful to implement. In its
basic/naïve form, you can put each line in the file in a list and go
down the history, asking for a diff for each commit until all of its
lines are blamed. When you look at a diff, you take at the '+' lines and
blame the . You'd need to remember to update the line numbers in your
list with the information from the chunk header, so you don't
missatribute lines that are all the same, next to each other and
added in different commits (think braces, for loops etc).

Once that works, you can try to implement copy/move detection. I believe
support for this is either in the current diff code or will soon
come, so you'll be spared much of this uglyness. Once you decide that
a block has been copied, you need adjust the data structures to blame
those lines in their original location.

Hopefully that helps.

   cmn

Re: [libgit2] Blame

From:
Thomas Rast
Date:
2013-03-05 @ 09:00
Carlos Martin Nieto <cmn@dwim.me> writes:

> Ignacio Casal Quinteiro <nacho.resa@gmail.com> writes:
>
>> Hi,
>>
>> do any of you know what would be the best way to implement the blame
>> for a file?
>
> Hey,
>
> First of all, blame is going be somwhat painful to implement. In its
> basic/naïve form, you can put each line in the file in a list and go
> down the history, asking for a diff for each commit until all of its
> lines are blamed. When you look at a diff, you take at the '+' lines and
> blame the . You'd need to remember to update the line numbers in your
> list with the information from the chunk header, so you don't
> missatribute lines that are all the same, next to each other and
> added in different commits (think braces, for loops etc).
>
> Once that works, you can try to implement copy/move detection. I believe
> support for this is either in the current diff code or will soon
> come, so you'll be spared much of this uglyness. Once you decide that
> a block has been copied, you need adjust the data structures to blame
> those lines in their original location.

Note that there are actually two parts to the copy/move detection.
git-blame also looks for other blame opportunities *within* the file if
you specify at least -M, as you can easily test by rearranging the order
of functions.

IIRC you can achieve this by running a diff between the added parts
(which would otherwise be blamed to the current commit) and the
preimage, and applying some heuristics to look for consecutive runs and
such.  In any case it's a mess.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch