Skip to content

Commit

Permalink
Blame loads all commits in single Repo#batch call
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Dec 23, 2010
1 parent 9a4fc90 commit a9c027c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/grit/blame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ def process_raw_blame(output)
if line[0, 1] == "\t"
lines << line[1, line.size]
elsif m = /^(\w{40}) (\d+) (\d+)/.match(line)
if !commits[m[1]]
commits[m[1]] = @repo.commit(m[1])
end
info[m[3].to_i] = [commits[m[1]], m[2].to_i]
commit_id, old_lineno, lineno = m[1], m[2].to_i, m[3].to_i
commits[commit_id] = nil if !commits.key?(commit_id)
info[lineno] = [commit_id, old_lineno]
end
end

# load all commits in single call
@repo.batch(*commits.keys).each do |commit|
commits[commit.id] = commit
end

# get it together
info.sort.each do |lineno, commit|
final << BlameLine.new(lineno, commit[1], commit[0], lines[lineno - 1])
info.sort.each do |lineno, (commit_id, old_lineno)|
commit = commits[commit_id]
final << BlameLine.new(lineno, old_lineno, commit, lines[lineno - 1])
end

@lines = final
Expand All @@ -58,4 +63,4 @@ def initialize(lineno, oldlineno, commit, line)

end # Blame

end # Grit
end # Grit

0 comments on commit a9c027c

Please sign in to comment.