Created
June 5, 2012 18:21
-
-
Save blowmage/2876698 to your computer and use it in GitHub Desktop.
Rake tasks for generating changes made by author
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
# 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