Skip to content

Instantly share code, notes, and snippets.

@bleything
Created September 14, 2010 22:42
Show Gist options
  • Save bleything/579911 to your computer and use it in GitHub Desktop.
Save bleything/579911 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'time'
begin
require 'rubygems'
require 'gruff'
rescue LoadError
$stderr.puts "git-statgraph requires RubyGems and the rmagick and gruff gems"
exit 1
end
# stats = {
# timestamp => [
# { author => '[email protected]', diffstat => '...' }
# ],
#
# timestamp => [ ... ],
# ...
stats = {}
# small helper method to turn the diffstat into a LOC delta
def parse_diffstat( line )
ins, del = line.match( /(\d+) insertions.*?(\d+) deletions/ )[1,2]
return ins.to_i - del.to_i
end
puts "Parsing commit logs..."
IO.popen( 'git log --shortstat --pretty=format:"%aE%%%ad"' ) do |io|
io.each_line do |line|
next if line.strip.empty?
if line =~ /%/ # committer line
components = line.split( /%/,2 )
@author = components.first
@date = Time.parse( components.last )
else # stat line
stats[ @date ] ||= []
stats[ @date ] << { :author => @author, :diffstat => parse_diffstat(line) }
end
end
end
sorted_dates = stats.keys.sort
initial_state = stats[ sorted_dates.first ].pop[ :diffstat ]
current_state = initial_state
states = []
sorted_dates.each_with_index do |date, idx|
states << current_state
stats[date].each do |diffstat|
current_state += diffstat[:diffstat]
end
end
labels = {}
skip_factor = sorted_dates.size / 10
10.times do |idx|
offset = idx * skip_factor
labels[ offset ] = sorted_dates[ offset ].strftime("%m/%y")
end
puts "Generating graph..."
g = Gruff::Line.new( 2500 )
g.title = "#{File.basename Dir.getwd} Size"
g.data "LOC", states
g.labels = labels
g.write('my_fruity_graph.png')
# vim: set ft=ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment