Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created July 30, 2013 23:11
Show Gist options
  • Select an option

  • Save baroquebobcat/6117891 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/6117891 to your computer and use it in GitHub Desktop.
Git Project Language Blob Overtime
# calculates language blob values ala github over time
# requires the github-linguist gem
#
# It's how I made this pretty graph http://www.flickr.com/photos/baroquebobcat/9401947827/
require 'rubygems'
require 'linguist'
require 'date'
def each_day start, finish
(start..finish).each do |day|
yield day
end
end
language_list = []
first_date = `git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$" | xargs git log | grep Date:`.split[1..-1].join " "
last_commit = ""
each_day Date.parse(first_date), Date.today do |date|
sha = `git rev-list -n 1 --before=\"#{date}\" master`
next if sha == last_commit
msg =`git checkout #{sha} 2>&1`
if msg.include? 'Abort'
raise msg
end
project = Linguist::Repository.from_directory(".")
language_list << [date, project.languages]
last_commit = sha
end
keys = language_list.map{|date, langs| langs.keys}.flatten.uniq
puts ["date",keys].flatten.join("\t")
language_list.each do |date, langs|
puts [date, keys.map{|k|langs[k]||0}].flatten.join("\t")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment