Skip to content

Instantly share code, notes, and snippets.

@jeremywrowe
Created February 4, 2011 04:37
Show Gist options
  • Save jeremywrowe/810741 to your computer and use it in GitHub Desktop.
Save jeremywrowe/810741 to your computer and use it in GitHub Desktop.
summarize git commits.. (relies on git extra's being installed)
#!/usr/bin/ruby
require 'fileutils'
include FileUtils
$here = File.expand_path(File.dirname("."))
git_dirs = Dir.glob("#{$here}/*/.git").reject{|x| x == "." || x == ".." }
@total = {}
def translate(user)
case user
# Put name mappings here
when "FOO" : return "BAR"
end
user
end
def git_summary(path)
FileUtils.cd path do
`git summary`.split("\n").each do |output|
if output =~ /^\s*(\d+)\s*(.*?)\s+(\d+\.\d+)%$/x
user = "%-20s" % translate($2.strip.upcase)
commits = $1.strip
if @total.has_key? user
@total[user] = @total[user] + commits.to_i
else
@total[user] = commits.to_i unless commits.nil?
end
end
end
end
end
git_dirs.each do |git_dir|
path = git_dir.sub!(/\.git/, "")
git_summary(path)
end
@total.keys.sort.map do |k|
amount = "%5s" % @total[k].to_s
puts "#{k} #{amount} commits"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment