From 2d38d07e9f8f1a5f482503fc3ac0a7bf59258310 Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Sat, 13 Oct 2012 17:57:15 +0200 Subject: [PATCH] lines_count speed up --- lib/git_stats/cli.rb | 2 +- lib/git_stats/git_data/command.rb | 5 +++-- lib/git_stats/git_data/commit.rb | 4 +++- templates/index.haml | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/git_stats/cli.rb b/lib/git_stats/cli.rb index af2a54afb..ccca9a3fb 100644 --- a/lib/git_stats/cli.rb +++ b/lib/git_stats/cli.rb @@ -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 diff --git a/lib/git_stats/git_data/command.rb b/lib/git_stats/git_data/command.rb index 40f6c0f22..b185e5e1e 100644 --- a/lib/git_stats/git_data/command.rb +++ b/lib/git_stats/git_data/command.rb @@ -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 diff --git a/lib/git_stats/git_data/commit.rb b/lib/git_stats/git_data/commit.rb index 7a4a85d7c..5b4540efb 100644 --- a/lib/git_stats/git_data/commit.rb +++ b/lib/git_stats/git_data/commit.rb @@ -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 diff --git a/templates/index.haml b/templates/index.haml index de8737e78..f53d70eee 100644 --- a/templates/index.haml +++ b/templates/index.haml @@ -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