|  | def authors_from_commit(commit) | 
        
          |  | authors = [] | 
        
          |  | commit.chomp.split(' and ').map{|a| authors.push a} | 
        
          |  | authors | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def authors_from_commits(commits) | 
        
          |  | authors = [] | 
        
          |  | commits.each do |commit| | 
        
          |  | authors += authors_from_commit(commit) | 
        
          |  | end | 
        
          |  | return authors | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def group_by_author(authors) | 
        
          |  | stats = Hash.new(0) | 
        
          |  | authors.map do |author| | 
        
          |  | stats[author] += 1 | 
        
          |  | end | 
        
          |  | stats | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def by_value(hash) | 
        
          |  | out = "" | 
        
          |  | hash.sort{|a,b| b[1]<=>a[1]}.each do |elem| | 
        
          |  | out += "#{elem[0]} (#{elem[1]})\n" | 
        
          |  | end | 
        
          |  | out | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def assertEqual(expected, actual) | 
        
          |  | if expected == actual | 
        
          |  | print '.' | 
        
          |  | else | 
        
          |  | puts "\nFAIL: #{expected} expected, but got #{actual}" | 
        
          |  | end | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def test | 
        
          |  | # Split paired authors into names | 
        
          |  | authors = authors_from_commit("Bob Test and Charles Code") | 
        
          |  | assertEqual("Bob Test", authors[0]) | 
        
          |  | assertEqual("Charles Code", authors[1]) | 
        
          |  | # Respect single authors too | 
        
          |  | assertEqual("Derek Driven", authors_from_commit("Derek Driven")[0]) | 
        
          |  | # Count authors up | 
        
          |  | commits = ['Bob Test', 'Charles and Bob Test'] | 
        
          |  | stats = group_by_author(authors_from_commits(commits)) | 
        
          |  | assertEqual(2, stats['Bob Test']) | 
        
          |  | assertEqual(1, stats['Charles']) | 
        
          |  | # Print out by descending commit order | 
        
          |  | output = by_value(group_by_author(authors_from_commits(commits))) | 
        
          |  | assertEqual(output, "Bob Test (2)\nCharles (1)\n") | 
        
          |  | puts "\nTest Run Finished" | 
        
          |  | end | 
        
          |  |  | 
        
          |  | def run | 
        
          |  | committers = `git log --pretty=format:%an` | 
        
          |  | puts by_value(group_by_author(authors_from_commits(committers))) | 
        
          |  | end | 
        
          |  | ARGV[0] == '-t' ? test : run | 
        
          |  |  | 
        
          |  |  | 
  
Fully tested now with a made up test 'framework'. Run with -t to run tests.