2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-18 00:54:41 +05:30
|
|
|
class MergeRequestDiffFile < ApplicationRecord
|
2017-09-10 17:25:29 +05:30
|
|
|
include Gitlab::EncodingHelper
|
2018-11-08 19:23:39 +05:30
|
|
|
include DiffFile
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
belongs_to :merge_request_diff, inverse_of: :merge_request_diff_files
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def utf8_diff
|
|
|
|
return '' if diff.blank?
|
|
|
|
|
|
|
|
encode_utf8(diff) if diff.respond_to?(:encoding)
|
|
|
|
end
|
|
|
|
|
|
|
|
def diff
|
2019-03-02 22:35:43 +05:30
|
|
|
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-05-18 00:54:41 +05:30
|
|
|
binary? ? content.unpack1('m0') : content
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|