10

I thought it would be neat if it were possible to take a Git repository, run some script, and have it generate the number of lines in the code base, and the proportion of each author that contributed to it.

Basically, because I am kind of a competitive coder, I would like a personal metric to see if the number of lines that I've written (in the current HEAD) are greater than my partner(s). It would be a fun statistic to say "I wrote % of the current codebase".

Has anyone ever thought to do this? I've looked for a way, but my shell scripting is not the best, so I couldn't do it alone.

Sean Freitag
  • 930
  • 1
  • 6
  • 15
  • 5
    I'm sure you've heard this one before: "Measuring programming progress by lines of code is like measuring aircraft building progress by weight." – Etaoin Apr 20 '12 at 05:10
  • @Etaoin: wish I could +1000 that. :-) – torek Apr 20 '12 at 06:12

3 Answers3

1

You can use git log, as illustrated in "Which Git commit stats are easy to pull".

Or you can have a look at Git Lookatgit project, which does inspect the number of lines changed, as seen in its gitauthor.rb class.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

You could try to parse the output of git-blame. This command gives the last person that edited each line of a file.

This example is not exactly what you want but I think it gives you the idea:

git blame -e the/file | awk -F '<|>' '{print $2}' | sort | uniq -c

This will print the e-mail addresses of the authors together with the number of lines they modified lastly for a file, for example:

     47 foo@bar.com
  34712 blah@baz.com

To make it run on the whole repository, you can do something like this:

git ls-files | while read f; do git blame -e $f; done | awk -F '<|>' '{print $2}' | sort | uniq -c

The idea here is to first generate the list of files with git ls-files, and then run the above snippet on each of the files (using the snippet mentioned here). If you're running this on a large codebase, you may want to store intermediate results in temporary files rather than use pipes.

Community
  • 1
  • 1
mtvec
  • 17,846
  • 5
  • 52
  • 83
1

You probably need gitdm, it can do exactly what you need. We use it for Mahara project to produce contribution statistics.

Just do what README suggests:

A typical command line used to generate the "who write 2.6.x" LWN articles looks like:

git log -p -M v2.6.19..v2.6.20 |  gitdm -u -s -a -o results -h results.html

You can also customise it for your own purposes.

Ruslan Kabalin
  • 6,580
  • 2
  • 28
  • 20