summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-04-25 17:45:24 +0000
committerDouwe Maan <douwe@gitlab.com>2017-04-25 17:45:24 +0000
commit9852cae8d7a8ef6fd5ab30987a126f9bb9ba904b (patch)
treecd303ea07887f20c3894019fc951a323f8eddbf3 /app
parenta34f0e7b36a7413e093bb19fcd76809b02080d02 (diff)
parenta0979c05fd5976cabe3c0633c168848d66320bfa (diff)
downloadgitlab-ce-9852cae8d7a8ef6fd5ab30987a126f9bb9ba904b.tar.gz
Merge branch 'mr-diff-size-overflow' into 'master'
Show correct size when MR diff overflows Closes #26560 See merge request !10827
Diffstat (limited to 'app')
-rw-r--r--app/models/merge_request.rb17
-rw-r--r--app/models/merge_request_diff.rb2
2 files changed, 10 insertions, 9 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 1d4827375d7..9d2288c311e 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -191,22 +191,23 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff ? merge_request_diff.raw_diffs(*args) : compare.raw_diffs(*args)
end
- def diffs(diff_options = nil)
+ def diffs(diff_options = {})
if compare
- compare.diffs(diff_options)
+ # When saving MR diffs, `no_collapse` is implicitly added (because we need
+ # to save the entire contents to the DB), so add that here for
+ # consistency.
+ compare.diffs(diff_options.merge(no_collapse: true))
else
merge_request_diff.diffs(diff_options)
end
end
def diff_size
- # The `#diffs` method ends up at an instance of a class inheriting from
- # `Gitlab::Diff::FileCollection::Base`, so use those options as defaults
- # here too, to get the same diff size without performing highlighting.
- #
- opts = Gitlab::Diff::FileCollection::Base.default_options.merge(diff_options || {})
+ # Calling `merge_request_diff.diffs.real_size` will also perform
+ # highlighting, which we don't need here.
+ return real_size if merge_request_diff
- raw_diffs(opts).size
+ diffs.real_size
end
def diff_base_commit
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb
index 6604af2b47e..f0a3c30ea74 100644
--- a/app/models/merge_request_diff.rb
+++ b/app/models/merge_request_diff.rb
@@ -260,7 +260,7 @@ class MergeRequestDiff < ActiveRecord::Base
new_attributes[:state] = :empty
else
diff_collection = compare.diffs(Commit.max_diff_options)
- new_attributes[:real_size] = compare.diffs.real_size
+ new_attributes[:real_size] = diff_collection.real_size
if diff_collection.any?
new_diffs = dump_diffs(diff_collection)