What are your git-stats?

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"

2 thoughts on “What are your git-stats?

  1. 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

    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)

    view raw

    README.markdown

    hosted with ❤ by GitHub


    #!/usr/bin/env ruby
    t = Time.now
    #same = [['name-a','name-b'],['mr fred','fred']]
    same = []
    pipe = open('|git log –pretty=format:"A:%an" –shortstat –no-merges')
    author = "unknown"
    stats = {}
    loop do
    line = pipe.readline rescue break
    if line =~ /^A\:(.*)$/
    author = $1
    found = same.detect{|a| a.include?(author)}
    author = found.first if found
    next
    end
    if line =~ /files changed, (\d+) insertions\(\+\), (\d+) deletions/
    stats[author] ||= Hash.new(0)
    stats[author]['+']+=$1.to_i
    stats[author]['-']+=$2.to_i
    print '.'
    end
    end
    puts "\nGit scores (in LOC):"
    puts stats.sort_by{|a,d| –d['+'] }.map{|author, data| "#{author.ljust(20)}: +#{data['+'].to_s.ljust(10)}#{data['-'].to_s.ljust(10)} " } * "\n"

    view raw

    git_stats.rb

    hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s