Class: Grit::CommitStats
- Inherits:
-
Object
- Object
- Grit::CommitStats
- Defined in:
- lib/grit/commit_stats.rb
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#deletions ⇒ Object
readonly
Returns the value of attribute deletions.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.find_all(repo, ref, options = {}) ⇒ Object
Find all commit stats matching the given criteria.
-
.list_from_string(repo, text) ⇒ Object
Parse out commit information into an array of baked Commit objects
repo
is the Repotext
is the text output from the git command (raw format).
Instance Method Summary collapse
-
#initialize(repo, id, files) ⇒ CommitStats
constructor
Instantiate a new CommitStats
id
is the id of the commitfiles
is an array of : [ [filename, adds, deletes, total], [filename, adds, deletes, total], [filename, adds, deletes, total] ]. -
#inspect ⇒ Object
Pretty object inspection.
-
#to_diffstat ⇒ Object
Convert to an easy-to-traverse structure.
-
#to_hash ⇒ Object
private.
Constructor Details
#initialize(repo, id, files) ⇒ CommitStats
Instantiate a new CommitStats
+id+ is the id of the commit
+files+ is an array of :
[ [filename, adds, deletes, total],
[filename, adds, deletes, total],
[filename, adds, deletes, total] ]
Returns Grit::CommitStats (baked)
15 16 17 18 19 20 21 22 |
# File 'lib/grit/commit_stats.rb', line 15 def initialize(repo, id, files) @repo = repo @id = id @files = files @additions = files.inject(0) { |total, a| total += a[1] } @deletions = files.inject(0) { |total, a| total += a[2] } @total = files.inject(0) { |total, a| total += a[3] } end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
5 6 7 |
# File 'lib/grit/commit_stats.rb', line 5 def additions @additions end |
#deletions ⇒ Object (readonly)
Returns the value of attribute deletions.
5 6 7 |
# File 'lib/grit/commit_stats.rb', line 5 def deletions @deletions end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/grit/commit_stats.rb', line 5 def files @files end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/grit/commit_stats.rb', line 5 def id @id end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
5 6 7 |
# File 'lib/grit/commit_stats.rb', line 5 def total @total end |
Class Method Details
.find_all(repo, ref, options = {}) ⇒ Object
Find all commit stats matching the given criteria.
+repo+ is the Repo
+ref+ is the ref from which to begin (SHA1 or name) or nil for --all
+options+ is a Hash of optional arguments to git
:max_count is the maximum number of commits to fetch
:skip is the number of commits to skip
Returns assoc array [sha, Grit::Commit[] (baked)]
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/grit/commit_stats.rb', line 32 def self.find_all(repo, ref, = {}) = [:max_count, :skip, :since] = {:numstat => true} = .merge() if ref output = repo.git.log(, ref) else output = repo.git.log(.merge(:all => true)) end self.list_from_string(repo, output) end |
.list_from_string(repo, text) ⇒ Object
Parse out commit information into an array of baked Commit objects
+repo+ is the Repo
+text+ is the text output from the git command (raw format)
Returns assoc array [sha, Grit::Commit[] (baked)]
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/grit/commit_stats.rb', line 52 def self.list_from_string(repo, text) lines = text.split("\n") commits = [] while !lines.empty? id = lines.shift.split.last lines.shift lines.shift lines.shift = [] << lines.shift[4..-1] while lines.first =~ /^ {4}/ || lines.first == '' lines.shift while lines.first && lines.first.empty? files = [] while lines.first =~ /^([-\d]+)\s+([-\d]+)\s+(.+)/ (additions, deletions, filename) = lines.shift.split additions = additions.to_i deletions = deletions.to_i total = additions + deletions files << [filename, additions, deletions, total] end lines.shift while lines.first && lines.first.empty? commits << [id, CommitStats.new(repo, id, files)] end commits end |
Instance Method Details
#inspect ⇒ Object
Pretty object inspection
87 88 89 |
# File 'lib/grit/commit_stats.rb', line 87 def inspect %Q{#<Grit::CommitStats "#{@id}">} end |
#to_diffstat ⇒ Object
Convert to an easy-to-traverse structure
92 93 94 95 96 |
# File 'lib/grit/commit_stats.rb', line 92 def to_diffstat files.map do || DiffStat.new(*) end end |
#to_hash ⇒ Object
private
100 101 102 103 104 105 106 107 108 |
# File 'lib/grit/commit_stats.rb', line 100 def to_hash { 'id' => id, 'files' => files, 'additions' => additions, 'deletions' => deletions, 'total' => total } end |