lines_count speed up

This commit is contained in:
Tomasz Gieniusz 2012-10-13 17:57:15 +02:00
parent 9f6fab8232
commit 2d38d07e9f
4 changed files with 8 additions and 5 deletions

View File

@ -7,7 +7,7 @@ class GitStats::CLI
repo_path, out_path = args
GitStats::Generator.new(repo_path, out_path) { |g|
g.git_command_observer { |command| puts command }
g.git_command_observer { |command, result| puts "#{command}" }
}.generate
end

View File

@ -9,8 +9,9 @@ module GitStats
end
def run
repo.git_command_observer.try(:call, @command)
in_repo { %x[#@command] }
result = in_repo { %x[#@command] }
repo.git_command_observer.try(:call, @command, result)
result
end
def in_repo

View File

@ -20,7 +20,9 @@ module GitStats
end
def lines_count
@lines_count ||= files.map(&:lines_count).sum
@lines_count ||= Command.new(repo, "git diff --shortstat `git hash-object -t tree /dev/null` #{self.hash}").run.lines.map do |line|
line[/(\d+) insertions?/, 1].to_i
end.sum
end
def short_stat

View File

@ -19,7 +19,7 @@
%td= repo.commits.last.files_count
%tr
%td Total lines
%td= "#{repo.commits.last.files.map(&:lines_count).sum} lines (#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions)"
%td= "#{repo.commits.last.lines_count} lines (#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions)"
%tr
%td Total commits
%td= repo.commits.size