mirror of https://github.com/tomgi/git_stats.git
calculating lines of code from commit content
This commit is contained in:
parent
9ca2ece131
commit
290618b167
|
@ -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'
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) } }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue