Determine the current distribution of code by the author

I thought that it would be neat if you could take the Git repository, run some script and make it generate the number of lines in the code base, as well as the share of each author who contributed to it.

Basically, because I'm a kind of competitive encoder, I need a personal metric to find out if there are more lines that I wrote (in the current HEAD) than my partner (s). It would be fun statistics to say: "I wrote% of the current code base."

Has anyone ever thought about this? I was looking for a way, but my shell scripts are not the best, so I could not do this alone.

+7
source share
3 answers

You can use the git log as shown in " Which git commit statistics are easy to pull out ."

Or you can look at the git Lookatgit project, which checks the number of rows changed, as shown in its gitauthor.rb class .

+1
source

You can try to analyze the output of git-blame . This command gives the last person who edited each line of the file.

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

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

This will print the authors email addresses along with the number of lines that they last modified for the file, for example:

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

To run it in the entire 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 a list of files with git ls files, and then run the above snippet in each of the files (using the snippet below here ). If you use this on a large code base, you may want to save intermediate results in temporary files rather than using pipes.

+1
source

You probably need gitdm , it can do exactly what you need. We use it for the Mahara project to create deposit statistics .

Just do what README offers:

A typical command line used to generate β€œwho writes 2.6.x” LWN articles looks like this:

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

You can also customize it for your purposes.

+1
source

All Articles