Skip to content

Instantly share code, notes, and snippets.

@rbsgn
Forked from soffes/blame.rb
Created May 13, 2011 14:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rbsgn/970614 to your computer and use it in GitHub Desktop.
Save rbsgn/970614 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
@rafaelfaria
Copy link

Could you do this with js?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment