Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Examine files and review git history to determine what percentage of the files was written by a particular author
#!/usr/bin/env ruby
author = ARGV.shift
dir = ARGV.shift || "."
BlamedFile =, :lines, :blamed_lines, :percent)
files = []
all_files = Dir.glob("#{dir}/**/*")
puts "Examining #{all_files.size} files:"
all_files.each do |file|
next if
next unless File.readable?(file)
lines = File.readlines(file).size
next if lines == 0
print "."
blamed_lines = `git blame #{file} | grep "#{author}"`.split("\n").size
files <<, lines, blamed_lines, blamed_lines / lines.to_f)
puts ""
files.sort_by{|f| f.percent}.reverse.each do |f|
next unless f.blamed_lines > 1
next unless f.lines > 10
puts "%3.0f%% of %d lines - %s" % [f.percent * 100, f.lines, f.file]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment