#!/usr/bin/ruby

# Copyright 2007 Martin Nordholts
# This script is so nifty I just have to put a copyright notice.
# Do whatever you like with this script but please keep the copyright notice.

START_DATE            = '2004-03-20'
PUTS_COMMIT_THRESHOLD = 30
SVN_REPOS             = { 'GIMP' => 'http://svn.gnome.org/svn/gimp/trunk',
                          'Krita' => 'svn://anonsvn.kde.org/home/kde/trunk/koffice/krita',
                          'Beryl' => 'svn://svn.beryl-project.org/beryl/trunk' }
              
SVN_REPOS.each_pair do | name, repo |

  commits_per_author = Hash.new
  longest_name = 0

  `svn log -r {#{START_DATE}}:HEAD #{repo}`.each_line do | line |
    if /^r\d+ \| (\w+)/ !~ line
      next
    end
  
    author = $~[1]
    
    longest_name = author.length if longest_name < author.length
  
    commits_per_author[author] = 0 if commits_per_author[author] == nil
    commits_per_author[author] += 1
  end

  puts name + " stats:\n=====================\nNumber of commits per author since #{START_DATE} into\n" +
       repo + "\n\n"

  sorted_commits_per_author = commits_per_author.sort { | a, b | b[1] <=> a[1] }
  
  sorted_commits_per_author.each do | key, value |
    puts key.ljust( longest_name ) + ': ' + value.to_s if value > PUTS_COMMIT_THRESHOLD
  end
  
  puts "\n\n\n"
  
end
