#!/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.

# How far back in time to examine the svn log.
START_DATE = '2004-03-20'

# The minimum number of commits an author must have
# done for the given timespan to be outputed.
PUTS_COMMIT_THRESHOLD = 30

# Which repos to examine.
SVN_REPOS = { 'GIMP'  => 'http://svn.gnome.org/svn/gimp/trunk',
              'Krita' => 'svn://anonsvn.kde.org/home/kde/trunk/koffice/krita',
              'Inkscape' => 'https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk',
              'Beryl' => 'svn://svn.beryl-project.org/beryl/trunk' }
              
SVN_REPOS.each_pair do | name, repo |

  commits_per_author = {}
  longest_name = 0

  cmd = "svn log -r {%s}:HEAD %s" % [START_DATE, repo]
  `#{cmd}`.each_line do | line |
    next unless author = line[/\| (\w+) \|/, 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 "%s stats:\n=====================\nNumber of commits per author since %s into\n%s\n\n" %
       [name, START_DATE, repo]

  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"
  
end
