Created
June 1, 2013 09:57
-
-
Save glebtv/5689875 to your computer and use it in GitHub Desktop.
worklog from git
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 | |
require 'date' | |
data = `git log --shortstat --no-merges` | |
logs = data.split("commit ") | |
class Hash | |
def self.recursive | |
new { |hash, key| hash[key] = recursive } | |
end | |
end | |
edits = Hash.recursive | |
logs.each do |log| | |
next if log.strip == '' | |
l = log.split("\n") | |
commit = l.shift | |
author = l.shift.to_s.split("Author: ")[1].strip[0..5] | |
date = l.shift.to_s.split("Date: ")[1].to_s.strip | |
d = Date.parse(date) | |
im = log.match(/ (\d+) insertions/) | |
dm = log.match(/ (\d+) deletions/) | |
if im.nil? | |
ins = 0 | |
else | |
ins = im[1].to_i | |
end | |
if dm.nil? | |
del = 0 | |
else | |
del = dm[1].to_i | |
end | |
if edits[d.to_s][author] == {} | |
edits[d.to_s][author] = {cmt: 0, ins: 0, del: 0} | |
end | |
edits[d.to_s][author][:cmt] += 1 | |
edits[d.to_s][author][:ins] += ins | |
edits[d.to_s][author][:del] += del | |
end | |
ret = [] | |
edits.each_pair do |k, v| | |
ret << "#{Date.parse(k).strftime('%a')} #{k} #{v}" | |
end | |
puts ret.reverse.join("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment