-
Notifications
You must be signed in to change notification settings - Fork 7
/
api_diff.rb
executable file
·56 lines (42 loc) · 1.19 KB
/
api_diff.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env ruby
require 'optparse'
abort "usage: #{$PROGRAM_NAME} ref1 ref2 [options]" unless ARGV.length >= 2
(ref1, ref2) = ARGV[0..2]
org_output = nil
OptionParser.new do |opts|
opts.banner = "usage: #{$PROGRAM_NAME} ref1 ref2 [options]"
opts.on('-o', '--org', 'Output in org format') do
org_output = true
end
end.parse!
Dir.chdir('mruby')
diff = `git diff #{ref1}...#{ref2}`
change_dict = {}
file_name = ''
diff.lines.map(&:chomp).each do |line|
if line.match(%r{\+\+\+ b/(.*)})
file_name = Regexp.last_match(1)
elsif line.match(/[+-]MRB_API/)
next if file_name.match?(/\.c$/)
puts "#{file_name}: #{line}" unless org_output
func_match = line.match(/(\w+)\(/)
next unless func_match
func_name = func_match[1]
change_dict[file_name] ||= {}
change_dict[file_name][func_name] ||= []
change_dict[file_name][func_name] << line
end
end
exit unless org_output
change_dict.each_pair do |f_name, file|
puts "* TODO #{f_name} [0/#{file.length}]"
file.each_pair do |func_name, func|
puts "** TODO #{func_name}"
puts ' #+begin_src c'
func.each do |func_line|
puts " #{func_line}"
end
puts ' #+end_src'
puts ''
end
end