Class Grit::CommitStats
In: lib/grit/commit_stats.rb
Parent: Object

Methods

Attributes

additions  [R] 
deletions  [R] 
files  [R] 
id  [R] 
total  [R] 

Public Class methods

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)]

[Source]

    # File lib/grit/commit_stats.rb, line 32
32:     def self.find_all(repo, ref, options = {})
33:       allowed_options = [:max_count, :skip, :since]
34:             
35:       default_options = {:numstat => true}
36:       actual_options = default_options.merge(options)
37:       
38:       if ref
39:         output = repo.git.log(actual_options, ref)
40:       else
41:         output = repo.git.log(actual_options.merge(:all => true))
42:       end
43:       
44:       self.list_from_string(repo, output)
45:     end

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)]

[Source]

    # File lib/grit/commit_stats.rb, line 52
52:     def self.list_from_string(repo, text)
53:       lines = text.split("\n")
54:       
55:       commits = []
56: 
57:       while !lines.empty?
58:         id = lines.shift.split.last
59:         
60:         lines.shift
61:         lines.shift
62:         lines.shift
63:         
64:         message_lines = []
65:         message_lines << lines.shift[4..-1] while lines.first =~ /^ {4}/ || lines.first == ''
66:         
67:         lines.shift while lines.first && lines.first.empty?
68: 
69:         files = []
70:         while lines.first =~ /^([-\d]+)\s+([-\d]+)\s+(.+)/
71:           (additions, deletions, filename) = lines.shift.split
72:           additions = additions.to_i
73:           deletions = deletions.to_i
74:           total = additions + deletions
75:           files << [filename, additions, deletions, total]
76:         end
77:         
78:         lines.shift while lines.first && lines.first.empty?
79:         
80:         commits << [id, CommitStats.new(repo, id, files)]
81:       end
82:       
83:       commits
84:     end

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)

[Source]

    # File lib/grit/commit_stats.rb, line 15
15:     def initialize(repo, id, files)
16:       @repo = repo
17:       @id = id
18:       @files = files
19:       @additions  = files.inject(0) { |total, a| total += a[1] } 
20:       @deletions  = files.inject(0) { |total, a| total += a[2] } 
21:       @total  = files.inject(0) { |total, a| total += a[3] } 
22:     end

Public Instance methods

Pretty object inspection

[Source]

    # File lib/grit/commit_stats.rb, line 87
87:     def inspect
88:       %Q{#<Grit::CommitStats "#{@id}">}
89:     end

Convert to an easy-to-traverse structure

[Source]

    # File lib/grit/commit_stats.rb, line 92
92:     def to_diffstat
93:       files.map do |metadata|
94:         DiffStat.new(*metadata)
95:       end
96:     end

private

[Source]

     # File lib/grit/commit_stats.rb, line 100
100:     def to_hash
101:       {
102:         'id'        => id,
103:         'files'     => files,
104:         'additions' => additions,
105:         'deletions' => deletions,
106:         'total'     => total
107:       }
108:     end

[Validate]