Also available as Gist
Ever wondered how much who adds/removes, its time to find out 😀
(those are real stats, I just obfuscated the names 😉 )
Results
Git scores (in LOC): mr-add : +482273 -9466 justu : +286250 -159905 grosser : +152384 -323344 another : +121257 -82116 naames : +104577 -13591 justfor : +68716 -72446 example : +7795 -4987 andeven : +5100 -1730 morenow : +4225 -2764 finish : +17 -19
Update: After working 2.5 years on this project my final stats where: +861345 -1115685 = -254340 LOC 😀
Install
Copy init git_stats.rb and ruby git_stats.rb
(you can add the names of people who commit with different users into the ‘same’ array)
#!/usr/bin/env ruby # please add enhancements to http://gist.github.com/234560 require 'optparse' start = Time.now.to_i sort_by = '+' STDOUT.sync = true same = [ ['my name','my-name'] ] # parse options options = {} OptionParser.new do |opts| opts.banner = <<BANNER Show git stats, options are: BANNER opts.on("--limit [LIMIT]", Integer, "Limit"){|x| options[:limit] = x } opts.on("--max-lines [SIZE]", Integer, "Max lines per commit ignore large commits"){|x| options[:max_lines] = x } opts.on("--help", "Show help"){ puts self; exit } end.parse! # parse commits pipe = open('|git log --pretty=format:"A:%an" --shortstat --no-merges') authors = ["unknown"] stats = {} count = 0 loop do count += 1 break if options[:limit] and count/2 > options[:limit] # break if limit was reached (2 lines per commit) line = pipe.readline rescue break if line =~ /^A\:(.*?)$/ authors = $1.strip found = same.detect{|a| a.include?(authors)} authors = found.first if found authors = authors.split('&').map(&:strip) # split up multiple people next end if line =~ /files changed, (\d+) insertions\(\+\), (\d+) deletions/ add = $1.to_i remove = $2.to_i if options[:max_lines] and (add + remove) > options[:max_lines] print 'x' else authors.each do |author| stats[author] ||= Hash.new(0) stats[author]['+'] += add stats[author]['-'] += remove end print '.' end end end longest = stats.map{|a,d|a.length}.max stats = stats.sort_by{|a,d| -d[sort_by] } stats = stats.map do |author, data| "#{author.ljust(longest)}: +#{data['+'].to_s.ljust(10)} -#{data['-'].to_s.ljust(10)} " end puts "\nGit scores (in LOC):" puts stats.join("\n") puts "Took #{Time.now.to_i - start} seconds"
slight improvement (skip merges in log [hence faster]), fix regex to handle people with full names as usernames (capitalized/spaces)
Ever wondered how much who adds/removes, its time to find out 😀
(those are real stats, i just obfuscated the names )
###Results
###Install
Copy init git_stats.rb and ruby git_stats.rb
(you can add the names of people who commit with different users into the ’same’ array)
README.markdown
hosted with ❤ by GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git_stats.rb
hosted with ❤ by GitHub
I hate it when wordpress marks old articles as new in feed readers 😦