Skip to content

Instantly share code, notes, and snippets.

@fizx
Created February 13, 2009 19:22
Show Gist options
  • Save fizx/64054 to your computer and use it in GitHub Desktop.
Save fizx/64054 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Example:
# $: git log --numstat -w --summary --date=iso | this.rb
# <timestamp> <added> <deleted>
#
require "time"
DATE = /^Date:(.*)/
DIFF = /^(\d+)\s+(\d+)/
def output(ts, add, del)
return unless ts
puts "#{ts}\t#{add}\t#{del}"
end
timestamp = nil
added = 0
deleted = 0
while line = STDIN.gets
if line =~ DATE
output(timestamp, added, deleted)
timestamp = Time.parse($1).to_i
added = 0
deleted = 0
elsif line =~ DIFF
added += $1.to_i
deleted += $2.to_i
end
end
output(timestamp, added, deleted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment