gitlab-org--gitlab-foss/app/models/merge_request_diff_file.rb

29 lines
647 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class MergeRequestDiffFile < ApplicationRecord
include Gitlab::EncodingHelper
include DiffFile
belongs_to :merge_request_diff, inverse_of: :merge_request_diff_files
def utf8_diff
return '' if diff.blank?
encode_utf8(diff) if diff.respond_to?(:encoding)
end
def diff
content =
if merge_request_diff&.stored_externally?
merge_request_diff.opening_external_diff do |file|
file.seek(external_diff_offset)
2019-09-10 03:33:03 -04:00
force_encode_utf8(file.read(external_diff_size))
end
else
super
end
2019-03-13 09:42:43 -04:00
binary? ? content.unpack1('m0') : content
end
end