Class: MergeRequestDiffFile
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- MergeRequestDiffFile
- Includes:
- BulkInsertSafe, DiffFile, Gitlab::EncodingHelper
- Defined in:
- app/models/merge_request_diff_file.rb
Constant Summary
Constants included from Gitlab::EncodingHelper
Gitlab::EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD
Constants included from BulkInsertSafe
BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError
Instance Method Summary collapse
Methods included from DiffFile
Methods included from Gitlab::EncodingHelper
#binary_io, #detect_binary?, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8
Methods inherited from ApplicationRecord
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order
Instance Method Details
#diff ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/merge_request_diff_file.rb', line 17 def diff content = if merge_request_diff&.stored_externally? merge_request_diff.opening_external_diff do |file| file.seek(external_diff_offset) force_encode_utf8(file.read(external_diff_size)) end else super end return content unless binary? # If the data isn't valid base64, return it as-is, since it's almost certain # to be a valid diff. Parsing it as a diff will fail if it's something else. # # https://gitlab.com/gitlab-org/gitlab/-/issues/240921 begin content.unpack1('m0') rescue ArgumentError content end end |
#utf8_diff ⇒ Object
11 12 13 14 15 |
# File 'app/models/merge_request_diff_file.rb', line 11 def utf8_diff return '' if diff.blank? encode_utf8(diff) if diff.respond_to?(:encoding) end |