Commit 22ca5634 authored by Kerri Miller's avatar Kerri Miller

Expose unhighlighted diff_files

parent f39b4463
......@@ -31,7 +31,11 @@ module Gitlab
end
def diff_files
@diff_files ||= diffs.decorate! { |diff| decorate_diff!(diff) }
raw_diff_files
end
def raw_diff_files
@raw_diff_files ||= diffs.decorate! { |diff| decorate_diff!(diff) }
end
def diff_file_paths
......
......@@ -16,15 +16,13 @@ module Gitlab
fallback_diff_refs: merge_request_diff.fallback_diff_refs)
end
def diff_files(decorate_diff_files: true)
files = super()
def diff_files
strong_memoize(:diff_files) do
diff_files = super
return files unless decorate_diff_files
diff_files.each { |diff_file| cache.decorate(diff_file) }
strong_memoize(:decorated_diff_files) do
files.each { |diff_file| cache.decorate(diff_file) }
files
diff_files
end
end
......
......@@ -145,7 +145,10 @@ module Gitlab
end
def diff_files
@diff_collection.diff_files(decorate_diff_files: false)
# We access the raw, undecorated diff_files here, as decorating refers
# back into this class and leads to a circular reference.
#
@diff_collection.raw_diff_files
end
end
end
......
......@@ -9,14 +9,6 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let(:diff_files) { subject.diff_files }
describe '#diff_files' do
context 'when decorate_diff_files is false' do
it 'does not attempt to decorate diff files' do
expect_any_instance_of(Gitlab::Diff::HighlightCache).not_to receive(:decorate)
subject.diff_files(decorate_diff_files: false)
end
end
it 'does not highlight binary files' do
allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:text?).and_return(false)
......
......@@ -98,7 +98,7 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
describe '#write_if_empty' do
it_behaves_like 'caches missing entries' do
let(:paths) { merge_request.diffs.diff_files.select(&:text?).map(&:file_path) }
let(:paths) { merge_request.diffs.raw_diff_files.select(&:text?).map(&:file_path) }
end
context 'different diff_collections for the same diffable' do
......@@ -125,7 +125,7 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
it_behaves_like 'caches missing entries' do
let(:cache) { described_class.new(merge_request_diff_batch) }
let(:paths) { merge_request_diff_batch.diff_files.select(&:text?).map(&:file_path) }
let(:paths) { merge_request_diff_batch.raw_diff_files.select(&:text?).map(&:file_path) }
end
end
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