From c2d9165394b068dc28c9aff15fcd3c0ea4a14984 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 25 Feb 2015 17:15:35 +0100 Subject: [PATCH] Add better date filters & bump version. --- lib/timecost/cli.rb | 56 ++++++++++++++++++++++++++++++----------- lib/timecost/version.rb | 2 +- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/timecost/cli.rb b/lib/timecost/cli.rb index 6a8b28b..c2e96c3 100644 --- a/lib/timecost/cli.rb +++ b/lib/timecost/cli.rb @@ -7,7 +7,9 @@ module TimeCost :author_filter => ".*?", :date_filter_enable => false, - :date_filter => ".*?", + :date_filter => [], + + :branches_filter_enable => true, :input_dump => [], :output_dump => nil, @@ -21,7 +23,7 @@ module TimeCost end def parse_cmdline args - opts = OptionParser.new do |opts| + options = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename $0} [options]" opts.on_tail("-v","--verbose", "Run verbosely") do |v| @@ -33,6 +35,7 @@ module TimeCost exit 0 end + opts.on("-i","--input FILE", "Set input dump file") do |file| @config[:input_dump] << file end @@ -41,13 +44,23 @@ module TimeCost @config[:output_dump] = file end - opts.on("-d","--date DATE", "Keep only commits since DATE") do |date| - puts "set date filter to #{date}" - @config[:date_filter] = DateTime.parse(date); + opts.on("--before DATE", "Keep only commits before 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 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" @config[:date_filter] = DateTime.now - time.to_f; puts "set date filter to date = #{@config[:date_filter]}" @@ -60,6 +73,10 @@ module TimeCost @config[:author_filter_enable] = true end + opts.on_tail("--all", "Collect from all branches and refs") do + @config[:branches_filter_enable] = false + end + # overlap : # 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 end end - opts.parse! args + options.parse! args end @@ -75,11 +92,17 @@ module TimeCost def analyze_git # git log # 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 = {} commit = nil @@ -121,10 +144,15 @@ module TimeCost unless commit.nil? then commit.date = $1 - if @config[:date_filter_enable] and - (DateTime.parse(commit.date) < @config[:date_filter]) then + # reject if a some filter does not validate date + 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 - # reject end end diff --git a/lib/timecost/version.rb b/lib/timecost/version.rb index 4eec771..9d672f4 100644 --- a/lib/timecost/version.rb +++ b/lib/timecost/version.rb @@ -1,3 +1,3 @@ module Timecost - VERSION = "0.0.1" + VERSION = "0.2.0" end