Skip to content

Instantly share code, notes, and snippets.

@manhole
Last active November 4, 2015 09:06
Show Gist options
  • Save manhole/791896763285da54b118 to your computer and use it in GitHub Desktop.
Save manhole/791896763285da54b118 to your computer and use it in GitHub Desktop.
gitへ変更した行数をカウントするスクリプト
# gitへ変更した行数をカウントするスクリプト
#
# example:
# git log --since=2014-11-01 --committer=manhole --shortstat --ignore-all-space --no-merges | ruby git_count_changes.rb
# => commits=175, insertions=10350, deletions=1253
# 各行の形式は...
# 10 files changed, 210 insertions(+), 19 deletions(-)
# 1 file changed, 5 insertions(+)
# 1 file changed, 50 deletions(-)
commits = 0
insertions = 0
deletions = 0
ARGF.each_line { |line|
if !(line =~ / files? changed, /)
next
end
#puts line
commits += 1
if line =~ /(\d+) insertion/
#puts $1
insertions += $1.to_i
else
#puts 0
end
if line =~ / (\d+) deletion/
#puts $1
deletions += $1.to_i
else
#puts 0
end
}
puts %Q|commits=#{commits}, insertions=#{insertions}, deletions=#{deletions}|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment