Skip to content

Instantly share code, notes, and snippets.

@marcandre
Created July 13, 2012 20:17
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 marcandre/3107159 to your computer and use it in GitHub Desktop.
Save marcandre/3107159 to your computer and use it in GitHub Desktop.
Quick stats per user on number of lines added/removed per commit
#!/usr/bin/env ruby
# A simple script to get stats on number of lines added/removed per commit
# Accepts -v option for verbose mode
# Accepts other git options, in particular path.
#
# E.g.:
#
# linestat -v app lib
ARGV.unshift "--author=#{`git config user.email`.strip}" unless ARGV.any?{|a| a.start_with? '--author='}
verbose = ARGV.delete('-v')
data = `git log --oneline --shortstat --reverse --no-merges #{ARGV.join(' ')}`.lines.each_slice(2).map do |commit, changes|
_, plus, minus = *changes.match(/.*changed, (\d+) insertions.* (\d+) deletions/)
[commit, plus.to_i, -minus.to_i]
end
exclude = File.read('tmp/.ignore_commits') rescue ''
errors = exclude.split("\n").map do |skip|
n = data.size
data.delete_if{|commit, _, _| commit.include?(skip)}
case n -= data.size
when 1
when 0
"Didn't find commit '#{skip}'" if ARGV.size <= 1
else
"Commit '#{skip}' matched #{n} commits"
end
end.compact
deltas = data.map do |commit, plus, minus|
puts ("%4d %5d = %5d " % [plus, minus, plus + minus]) + commit if verbose
plus + minus
end
deletions = deltas.select{|d| d < 0}.inject(0, :+)
sum = deltas.inject(0, :+)
#plus, minus = data.transpose.last(2).map{|serie| serie.inject(:+)}
puts "#{sum-deletions} #{deletions} = #{sum}"
puts "Errors: #{errors}" unless errors.empty?
@mathieujobin
Copy link

This didn't work for me...
but I used you git log line and did what I needed with a chain of pipes

https://gist.github.com/mathieujobin/92f6b671abd7d3aa552b

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