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)













I don't think s...
You shouldn't need wgrep. Does solaris grep not h...