Skip to content

Commit

Permalink
Move #blame to Patch from Line
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Sep 10, 2014
1 parent 064f42f commit 27ed09e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 31 deletions.
11 changes: 2 additions & 9 deletions lib/pronto/git/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def commit_sha

def commit_line
@commit_line ||= begin
patches = repo.show_commit(commit_sha)
patches = patch.repo.show_commit(commit_sha)

commit_patch = patches.find do |p|
patch.new_file_full_path == p.new_file_full_path
Expand All @@ -60,15 +60,8 @@ def ==(other)

private

def repo
patch.repo
end

def blame
@blame ||= Rugged::Blame.new(repo.rugged, patch.delta.new_file[:path],
min_line: new_lineno, max_line: new_lineno,
track_copies_same_file: true,
track_copies_any_commit_copies: true)[0]
@blame ||= patch.blame(new_lineno)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pronto/git/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def deletions
patch.stat[1]
end

def blame(lineno)
repo.blame(self, lineno)
end

def lines
@lines ||= begin
patch.map do |hunk|
Expand Down
7 changes: 5 additions & 2 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def path
@repo.path
end

def rugged
@repo
def blame(patch, lineno)
Rugged::Blame.new(@repo, patch.delta.new_file[:path],
min_line: lineno, max_line: lineno,
track_copies_same_file: true,
track_copies_any_commit_copies: true)[0]
end

private
Expand Down
1 change: 1 addition & 0 deletions spec/pronto/formatter/github_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Formatter
describe '#format' do
subject { github_formatter.format(messages, repository) }
let(:messages) { [message, message] }
let(:repository) { Pronto::Git::Repository.new('.') }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { OpenStruct.new(new_lineno: 1) }
before { line.stub(:commit_line).and_return(line) }
Expand Down
16 changes: 0 additions & 16 deletions spec/pronto/git/line_spec.rb

This file was deleted.

4 changes: 0 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
config.mock_with(:rspec) { |c| c.syntax = :should }
end

def repository
Pronto::Git::Repository.new('.')
end

def load_fixture(fixture_name)
path = File.join(%w(spec support files), fixture_name)
File.read(path).strip
Expand Down

0 comments on commit 27ed09e

Please sign in to comment.