Commit 409e3a62 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix_build_after_5401' into 'ce-to-ee'

Use raw_diffs for internal git diff

With the merge of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5401 into EE, we need to update the usage of diffs, and instead use raw_diffs which is the previous behaviour.

See merge request !617
parents f933199a 58bfcb0a
......@@ -170,7 +170,7 @@ class MergeRequest < ActiveRecord::Base
end
def raw_diffs(*args)
merge_request_diff ? merge_request_diff.diffs(*args) : compare.raw_diffs(*args)
merge_request_diff ? merge_request_diff.raw_diffs(*args) : compare.raw_diffs(*args)
end
def diffs(diff_options = nil)
......
......@@ -33,12 +33,12 @@ class MergeRequestDiff < ActiveRecord::Base
end
def size
real_size.presence || diffs.size
real_size.presence || raw_diffs.size
end
def diffs(options={})
def raw_diffs(options={})
if options[:ignore_whitespace_change]
@diffs_no_whitespace ||= begin
@raw_diffs_no_whitespace ||= begin
compare = Gitlab::Git::Compare.new(
repository.raw_repository,
self.start_commit_sha || self.target_branch_sha,
......@@ -47,8 +47,8 @@ class MergeRequestDiff < ActiveRecord::Base
compare.diffs(options)
end
else
@diffs ||= {}
@diffs[options] ||= load_diffs(st_diffs, options)
@raw_diffs ||= {}
@raw_diffs[options] ||= load_diffs(st_diffs, options)
end
end
......
......@@ -32,7 +32,7 @@ module Gitlab
diffable = [@merge_request.compare, @merge_request.merge_request_diff].compact
return [] if diffable.empty?
compare_diffs = diffable.first.diffs
compare_diffs = diffable.first.raw_diffs
return [] unless compare_diffs.present?
......
......@@ -143,7 +143,7 @@ module Gitlab
commits(@oldrev).each do |commit|
next if commit_from_annex_sync?(commit.safe_message)
commit.diffs.each do |diff|
commit.raw_diffs.each do |diff|
path = diff.new_path || diff.old_path
lock_info = project.find_path_lock(path)
......@@ -195,7 +195,7 @@ module Gitlab
def check_commit_diff(commit, push_rule)
if push_rule.file_name_regex.present?
commit.diffs.each do |diff|
commit.raw_diffs.each do |diff|
if (diff.renamed_file || diff.new_file) && diff.new_path =~ Regexp.new(push_rule.file_name_regex)
return "File name #{diff.new_path.inspect} is prohibited by the pattern '#{push_rule.file_name_regex}'"
end
......@@ -203,7 +203,7 @@ module Gitlab
end
if push_rule.max_file_size > 0
commit.diffs.each do |diff|
commit.raw_diffs.each do |diff|
next if diff.deleted_file
blob = project.repository.blob_at(commit.id, diff.new_path)
......
......@@ -170,7 +170,7 @@ module Gitlab
def check_commit_diff(commit, push_rule)
if push_rule.file_name_regex.present?
commit.diffs.each do |diff|
commit.raw_diffs.each do |diff|
if (diff.renamed_file || diff.new_file) && diff.new_path =~ Regexp.new(push_rule.file_name_regex)
return build_status_object(false, "File name #{diff.new_path.inspect} is prohibited by the pattern '#{push_rule.file_name_regex}'")
end
......@@ -178,7 +178,7 @@ module Gitlab
end
if push_rule.max_file_size > 0
commit.diffs.each do |diff|
commit.raw_diffs.each do |diff|
next if diff.deleted_file
blob = project.repository.blob_at(commit.id, diff.new_path)
......
......@@ -22,7 +22,7 @@ describe Gitlab::AuthorityAnalyzer, lib: true do
let(:approvers) { Gitlab::AuthorityAnalyzer.new(merge_request).calculate(number_of_approvers) }
before do
merge_request.compare = double(:compare, diffs: files)
merge_request.compare = double(:compare, raw_diffs: files)
allow(merge_request.target_project.repository).to receive(:commits).and_return(commits)
end
......
......@@ -10,7 +10,7 @@ describe MergeRequestDiff, models: true do
expect(mr_diff).not_to receive(:load_diffs)
expect(Gitlab::Git::Compare).to receive(:new).and_call_original
mr_diff.diffs(ignore_whitespace_change: true)
mr_diff.raw_diffs(ignore_whitespace_change: true)
end
end
......@@ -18,19 +18,19 @@ describe MergeRequestDiff, models: true do
before { mr_diff.update_attributes(st_diffs: '') }
it 'returns an empty DiffCollection' do
expect(mr_diff.diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.diffs).to be_empty
expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.raw_diffs).to be_empty
end
end
context 'when the raw diffs exist' do
it 'returns the diffs' do
expect(mr_diff.diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.diffs).not_to be_empty
expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.raw_diffs).not_to be_empty
end
context 'when the :paths option is set' do
let(:diffs) { mr_diff.diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) }
let(:diffs) { mr_diff.raw_diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) }
it 'only returns diffs that match the (old path, new path) given' do
expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb')
......
......@@ -136,7 +136,7 @@ describe MergeRequest, models: true do
it 'delegates to the MR diffs' do
merge_request.merge_request_diff = MergeRequestDiff.new
expect(merge_request.merge_request_diff).to receive(:diffs).with(options)
expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(options)
merge_request.raw_diffs(options)
end
......@@ -161,7 +161,7 @@ describe MergeRequest, models: true do
it 'delegates to the MR diffs' do
merge_request.merge_request_diff = MergeRequestDiff.new
expect(merge_request.merge_request_diff).to receive(:diffs).with(hash_including(options))
expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(hash_including(options))
merge_request.diffs(options)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment