Last active
August 29, 2015 14:13
-
-
Save benburkert/a2480f51633cbc540cbe to your computer and use it in GitHub Desktop.
track libgit2 implementation
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 | |
# | |
# track-coverage | |
# example: ./track-coverage /path/to/go-libgit2 /path/to/libgit2 /path/to/git2go | |
require 'pp' | |
$go_libgit2_dir = ARGV[0] || File.join(ENV['GOPATH'], 'src/github.com/benburkert/go-libgit2') | |
$libgit2_dir = ARGV[1] || File.join(ENV['GOPATH'], 'src/github.com/libgit2/libgit2') | |
$git2go_dir = ARGV[2] || File.join(ENV['GOPATH'], 'src/github.com/libgit2/git2go') | |
def function_name(line) | |
line[%r{GIT_EXTERN\([^\)]+\) *(git_[^\(]+)\(}, 1] | |
end | |
def exported_functions(header_file) | |
lines = File.readlines(header_file).grep(/GIT_EXTERN/) | |
lines.map {|l| function_name(l) }.compact | |
end | |
def check_for(fn, dir) | |
Dir[File.join(dir, "*.{go,c,h}")].any? do |file| | |
File.readlines(file).grep(/#{fn}/).any? | |
end | |
end | |
def group_finished?(functions) | |
functions.all? do |fn, data| | |
data[:go_libgit2] | |
end | |
end | |
def markdown_line(fn, data) | |
mark = data[:go_libgit2] ? 'x' : ' ' | |
group = fn[/git_([^_]+)_/, 1] | |
link = "[#{fn}](https://libgit2.github.com/libgit2/#HEAD/group/#{group}/#{fn})" | |
link = "**#{link}**" if data[:git2go] | |
" - [#{mark}] #{link}" | |
end | |
$table = Hash.new{|h,k| h[k] = {} } | |
Dir[File.join($libgit2_dir, "include/*/*.h")].each do |header| | |
group = File.basename(header) | |
exported_functions(header).each do |fn| | |
$table[group][fn] = { | |
file: header, | |
git2go: check_for(fn, $git2go_dir), | |
go_libgit2: check_for(fn, $go_libgit2_dir), | |
} | |
end | |
end | |
libgit2_count = 0 | |
git2go_count = 0 | |
go_libgit2_count = 0 | |
$table.each do |_, functions| | |
functions.each do |_, data| | |
libgit2_count += 1 | |
git2go_count += 1 if data[:git2go] | |
go_libgit2_count += 1 if data[:go_libgit2] | |
end | |
end | |
git2go_parity = "%.2f%" % (go_libgit2_count.to_f / git2go_count * 100).to_s | |
libgit2_parity = "%.2f%" % (go_libgit2_count.to_f / libgit2_count * 100).to_s | |
puts "git2go parity: **#{git2go_parity}**" | |
puts "libgit2 parity: **#{libgit2_parity}**" | |
puts | |
puts "---" | |
puts | |
$table.each do |group, functions| | |
next if functions.empty? | |
puts "- [#{group_finished?(functions) ? 'x' : ' '}] #{group}" | |
functions.each do |fn, data| | |
puts markdown_line(fn, data) | |
end | |
end | |
puts | |
puts "bold items are implemented in [git2go](/libgit2/git2go)." | |
puts | |
puts "[script](https://gist.github.com/benburkert/a2480f51633cbc540cbe)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment