diff --git a/lib/git_stats.rb b/lib/git_stats.rb index 8b1572f5d..ea51f0e76 100644 --- a/lib/git_stats.rb +++ b/lib/git_stats.rb @@ -5,7 +5,6 @@ require 'active_support/all' require 'action_pack' require 'action_view' require 'fileutils' -require 'pathname' require 'tilt' require 'lazy_high_charts' require 'launchy' diff --git a/lib/git_stats/git_data/blob.rb b/lib/git_stats/git_data/blob.rb new file mode 100644 index 000000000..3e4f55254 --- /dev/null +++ b/lib/git_stats/git_data/blob.rb @@ -0,0 +1,28 @@ +require 'git_stats/hash_initializable' + +module GitStats + module GitData + class Blob + include HashInitializable + + attr_reader :repo, :hash, :filename + + def lines_count + @lines ||= Command.new(repo, "git cat-file blob #{self.hash} | wc -l").run.to_i + end + + def content + @content ||= Command.new(repo, "git cat-file blob #{self.hash}").run + end + + def to_s + "#{self.class} #@hash #@filename" + end + + def ==(other) + [self.repo, self.hash, self.filename] == [other.repo, other.hash, other.filename] + end + + end + end +end \ No newline at end of file diff --git a/lib/git_stats/git_data/commit.rb b/lib/git_stats/git_data/commit.rb index b1e948d45..8b1a0c07b 100644 --- a/lib/git_stats/git_data/commit.rb +++ b/lib/git_stats/git_data/commit.rb @@ -7,6 +7,14 @@ module GitStats attr_reader :repo, :hash, :stamp, :date, :author + def files + @files ||= Command.new(repo, "git ls-tree -r #{self.hash}").run.lines.map do |line| + hash = line.split("\t")[0].split.last.strip + filename = line.split("\t")[1].strip + Blob.new(repo: repo, filename: filename, hash: hash) + end + end + def files_count @files_count ||= Command.new(repo, "git ls-tree -r --name-only #{self.hash} | wc -l").run.to_i end diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 960eabf37..3cdc168bd 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -4,7 +4,7 @@ module GitStats attr_reader :path def initialize(path) - @path = path + @path = File.expand_path(path) end def authors @@ -37,7 +37,7 @@ module GitStats end def project_name - @project_name ||= Pathname(path).basename.to_s + @project_name ||= File.basename(path) end def to_s diff --git a/spec/author_spec.rb b/spec/author_spec.rb index d57234eee..168cafdfb 100644 --- a/spec/author_spec.rb +++ b/spec/author_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe GitStats::GitData::Author do - let(:repo) { GitStats::GitData::Repo.new(path: "repo_path") } + let(:repo) { GitStats::GitData::Repo.new("repo_path") } let(:author) { GitStats::GitData::Author.new(repo: repo, name: "author1", email: "author1@gmail.com") } let(:other_author) { GitStats::GitData::Author.new(repo: repo, name: "author2", email: "author2@gmail.com") } let(:my_commits) { 10.times.map { |i| double("my_commit #{i}", :author => author) } } diff --git a/templates/index.haml b/templates/index.haml index 8ad743d04..de8737e78 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.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions" + %td= "#{repo.commits.last.files.map(&:lines_count).sum} lines (#{repo.short_stats.map(&:insertions).sum} insertions, #{repo.short_stats.map(&:deletions).sum} deletions)" %tr %td Total commits %td= repo.commits.size