Skip to content

Instantly share code, notes, and snippets.

@soffes
Created May 12, 2011 17:31
Show Gist options
  • Save soffes/969015 to your computer and use it in GitHub Desktop.
Save soffes/969015 to your computer and use it in GitHub Desktop.
Find the number of lines of code per person in a repository
# Put this file in the root of your git repository then run `ruby blame.rb`.
# You will need gsed. You can install gsed with `brew install gsed`.
# Crazy shell script taken from http://stackoverflow.com/questions/4589731/git-blame-statistics
input = `git ls-tree -r HEAD|gsed -re 's/^.{53}//'|while read filename; do file "$filename"; done|grep -E ': .*text'|gsed -r -e 's/: .*//'|while read filename; do git blame "$filename"; done|gsed -r -e 's/.*\\((.*)[0-9]{4}-[0-9]{2}-[0-9]{2} .*/\\1/' -e 's/ +$//'|sort|uniq -c`
aggregated = {}
input.lines.each do |line|
line.strip!
count = 0
person = "Unknown"
# Extract
if matches = line.match(/^([0-9]+)\s(.*)$/)
count = matches[1].to_i
first_name, last_name = matches[2].split
if first_name and first_name[0].match(/[a-zA-z]/)
person = first_name
if last_name and last_name[0].match(/[a-zA-z]/)
person += " #{last_name}"
end
end
end
# Add to aggregation
unless aggregated[person]
aggregated[person] = 0
end
aggregated[person] += count.to_i
end
aggregated.each do |person, count|
puts "#{person}\t #{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment