mikey@Sun

count svn commits for each author

Saturday May 26, 2007

I came across a requirement of obtaining the list of svn authors along with the number of corresponding commits. My solution to this is as follows...

The first assumption is, the list has to be updated every time a new commit is made to the svn repository. The best solution to this is to use post-commit script that resides in SVNROOT/hooks directory and is executed every time for a successful commit after it has been made.

NOTE: In the following example SVNROOT is located at/svnroot/repos/opensolarispl

$ cat /svnroot/repos/opensolarispl/hooks/post-commit


# update contributor counters
/home/users/mnowak/bin/svnstats.sh

As you can see here, the post-commit script simply calls the svnstats.sh script. And its all the job I need. Let's have a closer look at the svnstats.sh then.

$ cat /home/users/mnowak/bin/svnstats.sh


#!/bin/bash
cat /svnroot/repos/opensolarispl/db/revprops/* |
/home/users/mnowak/bin/wgrep.pl -d -w0:2 svn:author | grep -v
'svn:author' | grep -v 'V ' | sort | uniq -c | sort -gr | awk '{print FNR". " $2 " ("$1")" }' > /home/users/mnowak/public_html/svnstats.txt

Let me explain this one. First of all, script reads every single file in the SVNROOT/db/revprops directory that contains data on every commit (author, date, log). Every single file in that directory represents a separate commit by the respective author. The structure of an example file in question looks like this:


K 10
svn:author
V 9
mnowak
K 8
svn:date
V 27
2006-11-21T16:47:07.791433Z
K 7
svn:log
V 20
a test commit
END

At this point an amazing tool called wgrep comes in handy, as author's nick is two lines after the svn:author tag, and this is how I catch it. The rest of the script cleans up the output a little, counts the number of occurrences for every author (each occurrence is one commit made by an author), and finally writes it to the file in a format we would like to see.

Finally the list would look like this:


1. trochej (58)
2. claudiush (36)
3. mnowak (29)
4. dosiu (21)
5. estibi (15)
6. schism (4)
7. greyer (1)

[3] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

Nice work Mikey!.....However...

I don't think simply counting the number of commits is a sufficient metric for who is doing what. Take this scenerio for instance...

I am a code ninja working 16 hours, modifying 300 lines per commit. The person in the cube next to me, is modifying 3 lines per commit.

I think for a solid aggregate, you should take into account some other variables, lines modded perhaps? etc..

PS. For extra credit, how about piping the results into php, and generating up a page with a dynamic flash graph?

Just my 2 cents.

Nice use of wgrep btw.

Dave

irc://efnet.org:#help

local://"Hey Dave!"

Posted by Evad on May 26, 2007 at 05:19 PM BST #

You shouldn't need wgrep. Does solaris grep not have the -A option? (-A 2)

You may also want to look at the python/perl bindings for svn. The script to do the same thing using the bindings is about 10 lines of code.

Another method that would work is to take one of the usual svn commit hook scripts and remove all of the code after the few lines that pull out the username for the current commit rev. Then, open up your data file(gdbm, plain txt, whatever) and update the count for that user. This way you won't have to compute the commit counts after each commit.

Posted by Justin on May 27, 2007 at 02:34 AM BST #

Justin,
You shouldn't need wgrep. Does solaris grep not have the -A option? (-A 2)
As to my knowledge -A/-B options are available in GNU grep only.
Another method that would work is to take one of the usual svn commit hook scripts and remove all of the code after the few lines that pull out the username for the current commit rev. Then, open up your data file(gdbm, plain txt, whatever) and update the count for that user. This way you won't have to compute the commit counts after each commit.
It would work, if...you start using the script for the very first commit made, would not help much on already existing repository.

Posted by mikey on May 27, 2007 at 07:20 AM BST #

Post a Comment:
  • HTML Syntax: NOT allowed