diff options
Diffstat (limited to 'app/serializers/diff_file_entity.rb')
-rw-r--r-- | app/serializers/diff_file_entity.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb index 2a5121a2266..af7d1172f17 100644 --- a/app/serializers/diff_file_entity.rb +++ b/app/serializers/diff_file_entity.rb @@ -53,7 +53,7 @@ class DiffFileEntity < DiffFileBaseEntity end # Used for inline diffs - expose :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, _) { diff_file.text? } do |diff_file| + expose :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, options) { inline_diff_view?(options) && diff_file.text? } do |diff_file| diff_file.diff_lines_for_serializer end @@ -62,5 +62,21 @@ class DiffFileEntity < DiffFileBaseEntity end # Used for parallel diffs - expose :parallel_diff_lines, using: DiffLineParallelEntity, if: -> (diff_file, _) { diff_file.text? } + expose :parallel_diff_lines, using: DiffLineParallelEntity, if: -> (diff_file, options) { parallel_diff_view?(options) && diff_file.text? } + + private + + def parallel_diff_view?(options) + return true unless Feature.enabled?(:single_mr_diff_view) + + # If we're not rendering inline, we must be rendering parallel + !inline_diff_view?(options) + end + + def inline_diff_view?(options) + return true unless Feature.enabled?(:single_mr_diff_view) + + # If nothing is present, inline will be the default. + options.fetch(:diff_view, :inline).to_sym == :inline + end end |