diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:07:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-11 18:07:38 +0300 |
commit | 4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (patch) | |
tree | 2eff1ce7ac4a58de15b1f5980acfdb22c7b92ac0 /app/models/merge_request_diff.rb | |
parent | b86f474bf51e20d2db4cf0895d0a8e0894e31c08 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/merge_request_diff.rb')
-rw-r--r-- | app/models/merge_request_diff.rb | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index b8a1575c180..71a344e69e3 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -309,20 +309,25 @@ class MergeRequestDiff < ApplicationRecord end def diffs_in_batch(batch_page, batch_size, diff_options:) - Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(self, - batch_page, - batch_size, - diff_options: diff_options) + fetching_repository_diffs(diff_options) do |comparison| + if comparison + comparison.diffs_in_batch(batch_page, batch_size, diff_options: diff_options) + else + diffs_in_batch_collection(batch_page, batch_size, diff_options: diff_options) + end + end end def diffs(diff_options = nil) - if without_files? && comparison = diff_refs&.compare_in(project) + fetching_repository_diffs(diff_options) do |comparison| # It should fetch the repository when diffs are cleaned by the system. # We don't keep these for storage overload purposes. # See https://gitlab.com/gitlab-org/gitlab-foss/issues/37639 - comparison.diffs(diff_options) - else - diffs_collection(diff_options) + if comparison + comparison.diffs(diff_options) + else + diffs_collection(diff_options) + end end end @@ -430,6 +435,13 @@ class MergeRequestDiff < ApplicationRecord private + def diffs_in_batch_collection(batch_page, batch_size, diff_options:) + Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(self, + batch_page, + batch_size, + diff_options: diff_options) + end + def encode_in_base64?(diff_text) (diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only?) || diff_text.include?("\0") @@ -487,6 +499,25 @@ class MergeRequestDiff < ApplicationRecord end end + # Yields the block with the repository Compare object if it should + # fetch diffs from the repository instead DB. + def fetching_repository_diffs(diff_options) + return unless block_given? + + diff_options ||= {} + + # Can be read as: fetch the persisted diffs if yielded without the + # Compare object. + return yield unless without_files? || diff_options[:ignore_whitespace_change] + return yield unless diff_refs&.complete? + + comparison = diff_refs.compare_in(repository.project) + + return yield unless comparison + + yield(comparison) + end + def use_external_diff? return false unless has_attribute?(:external_diff) return false unless Gitlab.config.external_diffs.enabled |