Created
February 28, 2012 18:20
-
-
Save loganlinn/1934121 to your computer and use it in GitHub Desktop.
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
#require 'awesome_print' | |
require 'json' | |
module OMGWidgets ; end | |
module OMGWidgets::ActivityPartition | |
class DirCounter | |
attr_accessor :parent, :name, :hits, :children, :files | |
def initialize(parent=nil) | |
@hits = 0 | |
@parent = parent | |
@children = Hash.new do |h, k| | |
h[k] = DirCounter.new self | |
end | |
end | |
def hit(*segments) | |
next_seg = segments.shift | |
@name ||= next_seg | |
if segments.length < 2 | |
@hits += 1 | |
else | |
# chain it down | |
children[next_seg].hit *segments | |
end | |
end | |
def to_hash | |
hash = { | |
:name => @name | |
} | |
hash[:hits] = @hits if @hits > 0 | |
hash[:children] = [] unless @children.empty? | |
@children.each do |cname, counter| | |
hash[:children] << counter.to_hash | |
end | |
hash | |
end | |
end | |
repo_path = ARGV[0] || Dir.pwd | |
limit = ARGV[1] || '--since="3 week ago"' | |
commits = %x[cd #{repo_path} && git log --all --no-merges --pretty="%H" #{limit}].split("\n") | |
root_dir = DirCounter.new | |
root_dir.name = :/ | |
commits.each do |commit| | |
files = %x[cd #{repo_path} && git show --pretty="format:" --name-only #{commit}].split("\n") | |
files.each do |file| | |
segments = file.split(File::SEPARATOR) | |
root_dir.hit *segments | |
end | |
end | |
puts JSON.dump root_dir.to_hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment