Class Grit::Blame
In: lib/grit/blame.rb
Parent: Object

Methods

Classes and Modules

Class Grit::Blame::BlameLine

Attributes

lines  [R] 

Public Class methods

[Source]

    # File lib/grit/blame.rb, line 7
 7:     def initialize(repo, file, commit)
 8:       @repo = repo
 9:       @file = file
10:       @commit = commit
11:       @lines = []
12:       load_blame
13:     end

Public Instance methods

Pretty object inspection

[Source]

    # File lib/grit/blame.rb, line 45
45:     def inspect
46:       %Q{#<Grit::Blame "#{@file} <#{@commit}>">}
47:     end

[Source]

    # File lib/grit/blame.rb, line 15
15:     def load_blame
16:       output = @repo.git.blame({'p' => true}, @commit, '--', @file)
17:       process_raw_blame(output)
18:     end

[Source]

    # File lib/grit/blame.rb, line 20
20:     def process_raw_blame(output)
21:       lines, final = [], []
22:       info, commits = {}, {}
23: 
24:       # process the output
25:       output.split("\n").each do |line|
26:         if line[0, 1] == "\t"
27:           lines << line[1, line.size]
28:         elsif m = /^(\w{40}) (\d+) (\d+)/.match(line)
29:           if !commits[m[1]]
30:             commits[m[1]] = @repo.commit(m[1])
31:           end
32:           info[m[3].to_i] = [commits[m[1]], m[2].to_i]
33:         end
34:       end
35: 
36:       # get it together
37:       info.sort.each do |lineno, commit|
38:         final << BlameLine.new(lineno, commit[1], commit[0], lines[lineno - 1])
39:       end
40: 
41:       @lines = final
42:     end

[Validate]