diff --git a/bin/bugspots b/bin/bugspots index 24d95a0..26e24df 100755 --- a/bin/bugspots +++ b/bin/bugspots @@ -12,6 +12,11 @@ options = {} OptionParser.new do |opts| opts.banner = "Usage: bugspots /path/to/git/repo" + # Option: Set Branch + opts.on('-b', '--branch [name]', 'branch to crawl') do |b| + options[:branch] = b.to_s + end + # Option: Set Depth opts.on('-d', '--depth [depth]', 'depth of log crawl (integer)') do |d| options[:depth] = d.to_i @@ -28,12 +33,15 @@ OptionParser.new do |opts| end end.parse! -# Set a reasonable default of depth +# Set a reasonable default of depth options[:depth] ||= 500 +# Set master as the default branch +options[:branch] ||= "master" + puts "Scanning #{ARGV[0]} repo".foreground(:green) -fixes, spots = Bugspots.scan(ARGV[0], options[:depth], options[:words]) +fixes, spots = Bugspots.scan(ARGV[0], options[:branch], options[:depth], options[:words]) puts "\tFound #{fixes.size} bugfix commits, with #{spots.size} hotspots:".foreground(:yellow) puts diff --git a/lib/bugspots/scanner.rb b/lib/bugspots/scanner.rb index 5278fa1..3c4380f 100644 --- a/lib/bugspots/scanner.rb +++ b/lib/bugspots/scanner.rb @@ -5,7 +5,7 @@ module Bugspots Fix = Struct.new(:message, :date, :files) Spot = Struct.new(:file, :score) - def self.scan(repo, depth = 500, words = nil) + def self.scan(repo, branch = "master", depth = 500, words = nil) repo = Grit::Repo.new(repo) fixes = [] @@ -15,7 +15,7 @@ def self.scan(repo, depth = 500, words = nil) message_matchers = /fix(es|ed)|close(s|d)/ end - repo.commits('master', depth).each do |commit| + repo.commits(branch, depth).each do |commit| if commit.message =~ message_matchers files = commit.stats.files.map {|s| s.first} fixes << Fix.new(commit.short_message, commit.date, files)