Skip to content

Instantly share code, notes, and snippets.

@blowmage
Created June 5, 2012 18:21
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 blowmage/2876698 to your computer and use it in GitHub Desktop.
Save blowmage/2876698 to your computer and use it in GitHub Desktop.
Rake tasks for generating changes made by author
# Taken from http://stackoverflow.com/a/9782550
namespace :git do
desc "Analytics of changes made by author"
task :changes do
git_changes_by_author.sort_by { |a,h| -h[:total] }.each do |author, changes|
puts "#{author}: #{changes[:total]} (#{changes[:insertions]} insertions, #{changes[:deletions]} deletions)"
end
end
end
def git_changes_by_author
changes = {}
IO.popen("git log --pretty=format:\"%an\" --shortstat") do |f|
prev_line = ''
while line = f.gets
matches = /(\d+) insertions.* (\d+) deletions/.match(line)
if matches
changes[prev_line] ||= { :total => 0, :insertions => 0, :deletions => 0 }
changes[prev_line][:total] += matches[1].to_i + matches[2].to_i
changes[prev_line][:insertions] += matches[1].to_i
changes[prev_line][:deletions] += matches[2].to_i
end
# Names are on a line of their own, just before the stats
prev_line = line.strip
end
end
changes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment