Skip to content

Instantly share code, notes, and snippets.

@grosser
Forked from Aeon/README.markdown
Created May 7, 2010 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosser/393419 to your computer and use it in GitHub Desktop.
Save grosser/393419 to your computer and use it in GitHub Desktop.

Ever wondered how much who adds/removes, its time to find out :D (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

###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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment