Class: MergeRequestDiffFile

Inherits:
ApplicationRecord show all
Extended by:
SuppressCompositePrimaryKeyWarning
Includes:
BulkInsertSafe, DiffFile, Gitlab::EncodingHelper
Defined in:
app/models/merge_request_diff_file.rb

Constant Summary

Constants included from Gitlab::EncodingHelper

Gitlab::EncodingHelper::BOM_UTF8, Gitlab::EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, Gitlab::EncodingHelper::ESCAPED_CHARS, Gitlab::EncodingHelper::UNICODE_REPLACEMENT_CHARACTER

Constants included from BulkInsertSafe

BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods included from DiffFile

#to_hash

Methods included from Gitlab::EncodingHelper

#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #strip_bom, #unquote_path

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#diffObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/merge_request_diff_file.rb', line 29

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_diffObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/merge_request_diff_file.rb', line 17

def utf8_diff
  fetched_diff = merge_request_diff&.stored_externally? ? diff_export : diff

  return '' if fetched_diff.blank?

  encode_utf8(fetched_diff) if fetched_diff.respond_to?(:encoding)
rescue StandardError => e
  log_exception('Failed fetching merge request diff', e)

  ''
end