Created
July 13, 2012 20:17
-
-
Save marcandre/3107159 to your computer and use it in GitHub Desktop.
Quick stats per user on number of lines added/removed per commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This didn't work for me...
but I used you
git log
line and did what I needed with a chain of pipeshttps://gist.github.com/mathieujobin/92f6b671abd7d3aa552b