Add better date filters & bump version.

This commit is contained in:
Glenn Y. Rolland 2015-02-25 17:15:35 +01:00
parent 8dafbeea99
commit c2d9165394
2 changed files with 43 additions and 15 deletions

View file

@ -7,7 +7,9 @@ module TimeCost
:author_filter => ".*?", :author_filter => ".*?",
:date_filter_enable => false, :date_filter_enable => false,
:date_filter => ".*?", :date_filter => [],
:branches_filter_enable => true,
:input_dump => [], :input_dump => [],
:output_dump => nil, :output_dump => nil,
@ -21,7 +23,7 @@ module TimeCost
end end
def parse_cmdline args def parse_cmdline args
opts = OptionParser.new do |opts| options = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename $0} [options]" opts.banner = "Usage: #{File.basename $0} [options]"
opts.on_tail("-v","--verbose", "Run verbosely") do |v| opts.on_tail("-v","--verbose", "Run verbosely") do |v|
@ -33,6 +35,7 @@ module TimeCost
exit 0 exit 0
end end
opts.on("-i","--input FILE", "Set input dump file") do |file| opts.on("-i","--input FILE", "Set input dump file") do |file|
@config[:input_dump] << file @config[:input_dump] << file
end end
@ -41,13 +44,23 @@ module TimeCost
@config[:output_dump] = file @config[:output_dump] = file
end end
opts.on("-d","--date DATE", "Keep only commits since DATE") do |date| opts.on("--before DATE", "Keep only commits before DATE") do |date|
puts "set date filter to #{date}" puts "set date filter to <= #{date}"
@config[:date_filter] = DateTime.parse(date); @config[:date_filter] << lambda { |other|
return (other <= DateTime.parse(date))
}
@config[:date_filter_enable] = true @config[:date_filter_enable] = true
end end
opts.on("-t","--time TIME", "Keep only commits on last TIME datys") do |time| opts.on("--after DATE", "Keep only commits after DATE") do |date|
puts "set date filter to >= #{date}"
@config[:date_filter] << lambda { |other|
return (other >= DateTime.parse(date))
}
@config[:date_filter_enable] = true
end
opts.on("-t","--time TIME", "Keep only commits on last TIME days") do |time|
puts "set time filter to latest #{time} days" puts "set time filter to latest #{time} days"
@config[:date_filter] = DateTime.now - time.to_f; @config[:date_filter] = DateTime.now - time.to_f;
puts "set date filter to date = #{@config[:date_filter]}" puts "set date filter to date = #{@config[:date_filter]}"
@ -60,6 +73,10 @@ module TimeCost
@config[:author_filter_enable] = true @config[:author_filter_enable] = true
end end
opts.on_tail("--all", "Collect from all branches and refs") do
@config[:branches_filter_enable] = false
end
# overlap : # overlap :
# #
opts.on("-s","--scotch GRANULARITY", "Use GRANULARITY (decimal hours) to merge ranges") do |granularity| opts.on("-s","--scotch GRANULARITY", "Use GRANULARITY (decimal hours) to merge ranges") do |granularity|
@ -67,7 +84,7 @@ module TimeCost
@config[:range_granularity] = granularity.to_f @config[:range_granularity] = granularity.to_f
end end
end end
opts.parse! args options.parse! args
end end
@ -75,11 +92,17 @@ module TimeCost
def analyze_git def analyze_git
# git log # git log
# foreach, create time range (before) + logs # foreach, create time range (before) + logs
process = IO.popen ["git", "log",
"--date=iso",
"--no-patch",
"--","."]
cmd = [
"git", "log",
"--date=iso",
"--no-patch"
]
if not @config[:branches_filter_enable] then
cmd << "--all"
end
cmd.concat ["--", "."]
process = IO.popen cmd
@rangelist = {} @rangelist = {}
commit = nil commit = nil
@ -121,10 +144,15 @@ module TimeCost
unless commit.nil? then unless commit.nil? then
commit.date = $1 commit.date = $1
if @config[:date_filter_enable] and # reject if a some filter does not validate date
(DateTime.parse(commit.date) < @config[:date_filter]) then filter_keep = true
filters = @config[:date_filter]
filters.each do |f|
filter_keep &= f.call(DateTime.parse(commit.date))
end
if not filter_keep then
commit = nil commit = nil
# reject
end end
end end

View file

@ -1,3 +1,3 @@
module Timecost module Timecost
VERSION = "0.0.1" VERSION = "0.2.0"
end end