| Class | Grit::Blob |
| In: |
lib/grit/blob.rb
|
| Parent: | Object |
| DEFAULT_MIME_TYPE | = | "text/plain" |
| id | [R] | |
| mode | [R] | |
| name | [R] |
The blame information for the given file at the given commit
Returns Array: [Grit::Commit, Array: [<line>]]
# File lib/grit/blob.rb, line 57
57: def self.blame(repo, commit, file)
58: data = repo.git.blame({:p => true}, commit, '--', file)
59:
60: commits = {}
61: blames = []
62: info = nil
63:
64: data.split("\n").each do |line|
65: parts = line.split(/\s+/, 2)
66: case parts.first
67: when /^[0-9A-Fa-f]{40}$/
68: case line
69: when /^([0-9A-Fa-f]{40}) (\d+) (\d+) (\d+)$/
70: _, id, origin_line, final_line, group_lines = *line.match(/^([0-9A-Fa-f]{40}) (\d+) (\d+) (\d+)$/)
71: info = {:id => id}
72: blames << [nil, []]
73: when /^([0-9A-Fa-f]{40}) (\d+) (\d+)$/
74: _, id, origin_line, final_line = *line.match(/^([0-9A-Fa-f]{40}) (\d+) (\d+)$/)
75: info = {:id => id}
76: end
77: when /^(author|committer)/
78: case parts.first
79: when /^(.+)-mail$/
80: info["#{$1}_email".intern] = parts.last
81: when /^(.+)-time$/
82: info["#{$1}_date".intern] = Time.at(parts.last.to_i)
83: when /^(author|committer)$/
84: info[$1.intern] = parts.last
85: end
86: when /^filename/
87: info[:filename] = parts.last
88: when /^summary/
89: info[:summary] = parts.last
90: when ''
91: c = commits[info[:id]]
92: unless c
93: c = Commit.create(repo, :id => info[:id],
94: :author => Actor.from_string(info[:author] + ' ' + info[:author_email]),
95: :authored_date => info[:author_date],
96: :committer => Actor.from_string(info[:committer] + ' ' + info[:committer_email]),
97: :committed_date => info[:committer_date],
98: :message => info[:summary])
99: commits[info[:id]] = c
100: end
101: _, text = *line.match(/^\t(.*)$/)
102: blames.last[0] = c
103: blames.last[1] << text
104: info = nil
105: end
106: end
107:
108: blames
109: end
Create an unbaked Blob containing just the specified attributes
+repo+ is the Repo +atts+ is a Hash of instance variable data
Returns Grit::Blob (unbaked)
# File lib/grit/blob.rb, line 15
15: def self.create(repo, atts)
16: self.allocate.create_initialize(repo, atts)
17: end
Compares blobs by name
# File lib/grit/blob.rb, line 121
121: def <=>(other)
122: name <=> other.name
123: end
Initializer for Blob.create
+repo+ is the Repo +atts+ is a Hash of instance variable data
Returns Grit::Blob (unbaked)
# File lib/grit/blob.rb, line 24
24: def create_initialize(repo, atts)
25: @repo = repo
26: atts.each do |k, v|
27: instance_variable_set("@#{k}".to_sym, v)
28: end
29: self
30: end
Pretty object inspection
# File lib/grit/blob.rb, line 116
116: def inspect
117: %Q{#<Grit::Blob "#{@id}">}
118: end