2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class MergeRequestDiffFile < ApplicationRecord
|
2017-06-09 07:48:25 -04:00
|
|
|
include Gitlab::EncodingHelper
|
2018-05-16 11:46:18 -04:00
|
|
|
include DiffFile
|
2017-06-09 07:48:25 -04:00
|
|
|
|
2019-01-09 12:01:28 -05:00
|
|
|
belongs_to :merge_request_diff, inverse_of: :merge_request_diff_files
|
2017-06-09 07:48:25 -04:00
|
|
|
|
|
|
|
def utf8_diff
|
|
|
|
return '' if diff.blank?
|
|
|
|
|
|
|
|
encode_utf8(diff) if diff.respond_to?(:encoding)
|
|
|
|
end
|
2017-07-25 12:57:02 -04:00
|
|
|
|
|
|
|
def diff
|
2019-01-09 12:01:28 -05:00
|
|
|
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
|
|
|
|
|
2019-03-13 09:42:43 -04:00
|
|
|
binary? ? content.unpack1('m0') : content
|
2017-07-25 12:57:02 -04:00
|
|
|
end
|
2017-06-09 07:48:25 -04:00
|
|
|
end
|