Skip to content

Instantly share code, notes, and snippets.

@anewusername1
Created June 27, 2011 16:02
Show Gist options
  • Save anewusername1/1049152 to your computer and use it in GitHub Desktop.
Save anewusername1/1049152 to your computer and use it in GitHub Desktop.
line commit breakdown
class Breakdown
def gather_files(start_dir)
files = []
Dir["#{start_dir}/*"].each do |file|
if(File.directory?(file))
files += gather_files(file)
else
files << file
end
end
files
end
def gather_stats(directory)
users = {}
files_scanned = []
all_files = gather_files(directory)
files = all_files.each do |file|
next if(File.extname(file) == '.log')
begin
blamed = `git blame #{file}`
split_blame = blamed.split("\n")
split_blame.each do |line|
name = line.scan(/\(([\w\s]+) [\d]+-/).flatten[0].strip
users[name].nil? ? users[name] = 1 : users[name] += 1
end
files_scanned << file
rescue
next
end
end
Hash[*users.sort_by {|key,value| value}.reverse.flatten]
end
def is_git_repo?(dir)
`cd #{dir} && git status` =~ /\# On branch/
end
end
bd = Breakdown.new
puts bd.gather_stats('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment