Given a range of commits, say HEAD~1
and HEAD
(i.e., just HEAD
), I want to find previous authors of the lines that were changed in that range and how many lines they changed.
More precisely: for each line that was changed in the range, I want to get the previous author (using git blame
, for example). Then I want to group by these authors summing up the changed lines.
For example, consider the file X that was changed by these people before HEAD
(I marked the people that changed the lines at the beginning of the line, comparable to git blame
's output):
Adam: Lorem ipsum dolor
Adam: sit amet, consectetur
Adam: adipiscing elit.
Bob: Praesent efficitur urna
Bob: ac volutpat lacinia.
Bob: Sed sagittis, metus non
Adam: maximus tristique, leo
Adam: augue venenatis enim,
Adam: ac rutrum nulla odio
Adam: id urna.
Now, author Carl
changes the file as follows (note that this is a pseudocode mixture of git blame
and git diff
):
Adam: Lorem ipsum dolor
Adam: sit amet, consectetur
- Adam: adipiscing elit.
+ Carl: adipiscing elit I love cats.
- Bob: Praesent efficitur urna
+ Carl: Praesent efficitur urna :D
- Bob: ac volutpat lacinia.
+ Carl: ac volutpat lacinia YOLO.
+ Carl: Added extra line, lol!
- Bob: Sed sagittis, metus non
Adam: maximus tristique, leo
Adam: augue venenatis enim,
Adam: ac rutrum nulla odio
Adam: id urna.
So Carl changed 2 lines from Bob, deleted one line from Bob, and changed one line from Adam. Thus, the output of my script should be:
Bob: 3 Adam: 1
My overall solution would be:
- Find changed line ranges
- Pass these ranges with the
-L
parameter togit blame
to query for the previous author - Do the final grouping myself by parsing
git blame
s output and summing up.
I am currently struggling with 1.: getting the line range that were changed by the diff (In this case one range 3,6). Once I have these ranges, I can pass them to git blame -L
to get the previous authors of these lines. So how can I make git diff
or another git tool return the line ranges as numerical start,end
pairs?