merge_request_diff_file.rb 629 Bytes
Newer Older
1 2
# frozen_string_literal: true

3 4
class MergeRequestDiffFile < ActiveRecord::Base
  include Gitlab::EncodingHelper
5
  include DiffFile
6

7
  belongs_to :merge_request_diff, inverse_of: :merge_request_diff_files
8 9 10 11 12 13

  def utf8_diff
    return '' if diff.blank?

    encode_utf8(diff) if diff.respond_to?(:encoding)
  end
14 15

  def diff
16 17 18 19 20 21 22 23 24 25
    content =
      if merge_request_diff&.stored_externally?
        merge_request_diff.opening_external_diff do |file|
          file.seek(external_diff_offset)
          file.read(external_diff_size)
        end
      else
        super
      end

Nick Thomas's avatar
Nick Thomas committed
26
    binary? ? content.unpack1('m0') : content
27
  end
28
end