Fix filtering.
This commit is contained in:
parent
eefdef8d53
commit
af321e9024
1 changed files with 50 additions and 22 deletions
|
@ -21,7 +21,8 @@ class GitExtractor
|
||||||
class Range
|
class Range
|
||||||
attr_accessor :time_start, :time_stop, :commits
|
attr_accessor :time_start, :time_stop, :commits
|
||||||
|
|
||||||
def initialize commit
|
def initialize config, commit
|
||||||
|
@config = config
|
||||||
@time_stop = DateTime.parse(commit.date)
|
@time_stop = DateTime.parse(commit.date)
|
||||||
@time_start = @time_stop - (1.5 / 24.0)
|
@time_start = @time_stop - (1.5 / 24.0)
|
||||||
@commits = [commit]
|
@commits = [commit]
|
||||||
|
@ -109,8 +110,13 @@ class GitExtractor
|
||||||
def to_s
|
def to_s
|
||||||
val = "(%s) %s - %s\n" % [diff, fixed_start, @time_stop]
|
val = "(%s) %s - %s\n" % [diff, fixed_start, @time_stop]
|
||||||
@commits.each do |commit|
|
@commits.each do |commit|
|
||||||
r = "\t* " + commit.author + "\n"
|
lines = []
|
||||||
r += commit.note.split(/\n/).map{ |s| "\t %s" % s }.join "\n"
|
unless @config[:author_filter_enable] then
|
||||||
|
lines.push commit.author
|
||||||
|
end
|
||||||
|
lines.concat commit.note.split(/\n/)
|
||||||
|
r = lines.map{ |s| "\t %s" % s }.join "\n"
|
||||||
|
r[1] = '*'
|
||||||
val += r + "\n"
|
val += r + "\n"
|
||||||
end
|
end
|
||||||
return val
|
return val
|
||||||
|
@ -141,6 +147,12 @@ class GitExtractor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def each
|
||||||
|
@ranges.each do |r|
|
||||||
|
yield r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def sum
|
def sum
|
||||||
result = 0
|
result = 0
|
||||||
@ranges.each do |r|
|
@ranges.each do |r|
|
||||||
|
@ -154,6 +166,7 @@ class GitExtractor
|
||||||
def initialize
|
def initialize
|
||||||
# FIXME: accept multiple authors
|
# FIXME: accept multiple authors
|
||||||
@config = {
|
@config = {
|
||||||
|
:author_filter_enable => false,
|
||||||
:author_filter => ".*?",
|
:author_filter => ".*?",
|
||||||
:verbose => false
|
:verbose => false
|
||||||
}
|
}
|
||||||
|
@ -161,20 +174,30 @@ class GitExtractor
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_cmdline args
|
def parse_cmdline args
|
||||||
OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: #{File.basename $0} [options]"
|
opts.banner = "Usage: #{File.basename $0} [options]"
|
||||||
|
|
||||||
opts.on("-v","--verbose", "Run verbosely") do |v|
|
opts.on_tail("-v","--verbose", "Run verbosely") do |v|
|
||||||
@config[:verbose] = true
|
@config[:verbose] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on("-a","--author AUTHOR", "Only keep commits for AUTHOR") do |author|
|
opts.on_tail("-h","--help", "Show this help") do
|
||||||
@config[:author_filter] = author
|
puts opts
|
||||||
end
|
exit 0
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec
|
opts.on("-a","--author AUTHOR", "Only keep commits for AUTHOR") do |author|
|
||||||
|
puts "set commit author to #{author}"
|
||||||
|
@config[:author_filter] = author
|
||||||
|
@config[:author_filter_enable] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
opts.parse! args
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def analyze
|
||||||
# git log
|
# git log
|
||||||
# foreach, create time range (before) + logs
|
# foreach, create time range (before) + logs
|
||||||
process = IO.popen ["git", "log", "--date=iso"]
|
process = IO.popen ["git", "log", "--date=iso"]
|
||||||
|
@ -191,35 +214,38 @@ class GitExtractor
|
||||||
id = $1
|
id = $1
|
||||||
# merge ranges & push
|
# merge ranges & push
|
||||||
unless commit.nil? then
|
unless commit.nil? then
|
||||||
range = GitExtract::Range.new commit
|
range = Range.new @config, commit
|
||||||
rangelist.add range
|
@rangelist.add range
|
||||||
end
|
end
|
||||||
commit = Commit.new id
|
commit = Commit.new id
|
||||||
#puts "commit #{id}"
|
#puts "commit #{id}"
|
||||||
|
|
||||||
when /^Author:\s*(.*?)\s*$/ then
|
when /^Author:\s*(.*?)\s*$/ then
|
||||||
break if commit.nil?
|
unless commit.nil? then
|
||||||
commit.author = $1
|
commit.author = $1
|
||||||
|
|
||||||
if not commit.author =~ /#{@config[:author_filter]}/ then
|
if not commit.author =~ /#{@config[:author_filter]}/ then
|
||||||
commit = nil
|
commit = nil
|
||||||
# reject
|
# reject
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
when /^Date:\s*(.*?)\s*$/ then
|
when /^Date:\s*(.*?)\s*$/ then
|
||||||
break if commit.nil?
|
unless commit.nil? then
|
||||||
commit.date = $1
|
commit.date = $1
|
||||||
|
end
|
||||||
|
|
||||||
when /^\s*$/ then
|
when /^\s*$/ then
|
||||||
# skip
|
# skip
|
||||||
|
|
||||||
else
|
else
|
||||||
break if commit.nil?
|
|
||||||
# add as note
|
# add as note
|
||||||
|
unless commit.nil? then
|
||||||
commit.note = if commit.note.nil? then line
|
commit.note = if commit.note.nil? then line
|
||||||
else commit.note + "\n" + line
|
else commit.note + "\n" + line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def exec
|
def exec
|
||||||
end
|
end
|
||||||
|
@ -228,8 +254,10 @@ class GitExtractor
|
||||||
end
|
end
|
||||||
|
|
||||||
def report
|
def report
|
||||||
pp @rangelist
|
@rangelist.each do |r|
|
||||||
puts "SUM: %s" % @rangelist.sum
|
puts r.to_s + "\n"
|
||||||
|
end
|
||||||
|
puts "TOTAL: %.2f hours" % @rangelist.sum
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -237,6 +265,6 @@ end
|
||||||
|
|
||||||
app = GitExtractor.new
|
app = GitExtractor.new
|
||||||
app.parse_cmdline ARGV
|
app.parse_cmdline ARGV
|
||||||
app.exec
|
app.analyze
|
||||||
app.report
|
app.report
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue