summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 15:07:38 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 15:07:38 +0000
commit4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (patch)
tree2eff1ce7ac4a58de15b1f5980acfdb22c7b92ac0 /app/models
parentb86f474bf51e20d2db4cf0895d0a8e0894e31c08 (diff)
downloadgitlab-ce-4eea104c69e59f6fa53c7bc15b986c69f29b60c8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb1
-rw-r--r--app/models/compare.rb1
-rw-r--r--app/models/concerns/acts_as_paginated_diff.rb11
-rw-r--r--app/models/merge_request_diff.rb47
4 files changed, 52 insertions, 8 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 01c7991ba2f..460725b2016 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -12,6 +12,7 @@ class Commit
include StaticModel
include Presentable
include ::Gitlab::Utils::StrongMemoize
+ include ActsAsPaginatedDiff
include CacheMarkdownField
attr_mentionable :safe_message, pipeline: :single_line
diff --git a/app/models/compare.rb b/app/models/compare.rb
index f1ed84ab5a5..9b214171f07 100644
--- a/app/models/compare.rb
+++ b/app/models/compare.rb
@@ -4,6 +4,7 @@ require 'set'
class Compare
include Gitlab::Utils::StrongMemoize
+ include ActsAsPaginatedDiff
delegate :same, :head, :base, to: :@compare
diff --git a/app/models/concerns/acts_as_paginated_diff.rb b/app/models/concerns/acts_as_paginated_diff.rb
new file mode 100644
index 00000000000..4ce2f99e63f
--- /dev/null
+++ b/app/models/concerns/acts_as_paginated_diff.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module ActsAsPaginatedDiff
+ # Comparisons going back to the repository will need proper batch
+ # loading (https://gitlab.com/gitlab-org/gitlab/issues/32859).
+ # For now, we're returning all the diffs available with
+ # no pagination data.
+ def diffs_in_batch(_batch_page, _batch_size, diff_options:)
+ diffs(diff_options)
+ end
+end
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