Skip to content

Instantly share code, notes, and snippets.

@corbt
Created January 21, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corbt/633e018bc5636713cca0 to your computer and use it in GitHub Desktop.
Save corbt/633e018bc5636713cca0 to your computer and use it in GitHub Desktop.
# Counts the total number of insertions and deletions in a git repository's lifetime
require 'git'
repo = Git.open('../emberall')
prev = repo.log.first
deletions = 0
insertions = 0
repo.log(count = 5000).each do |commit|
source_file = /.*(rb)|(jsx)|(cljs)|(scss)|(yml)/
stats_files = repo.diff(commit, prev).stats[:files]
.select { |f| f =~ source_file }
deletions += stats_files.inject(0) { |sum, f| sum + f.last[:deletions] }
insertions += stats_files.inject(0) { |sum, f| sum + f.last[:insertions] }
prev = commit
end
puts "Deletions: #{deletions}"
puts "Insertions: #{insertions}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment