diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-01-05 18:22:07 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-01-05 18:22:07 +0000 |
commit | 2a31a850c41c53a7f00899757ffc2fa78f30e8ac (patch) | |
tree | 520cb0b2e0326f835e539921b8b4b18c086ab87b /lib/gitlab/diff/file.rb | |
parent | 088de7237ac20739bec189ac701510cdfa01386f (diff) | |
parent | 3d162d192ba2a57776de62b553a2a0a9a9245f8a (diff) | |
download | gitlab-ce-2a31a850c41c53a7f00899757ffc2fa78f30e8ac.tar.gz |
Merge branch 'master' into 34312-eslint-vue-plugin
* master: (78 commits)
Use --left-right and --max-count for counting diverging commits
API: get participants from merge_requests & issues
Copy Mermaid graphs as GFM
Rephrase paragraph about e2e tests in merge requests in docs
Remove EE only sections from docs
Update redis-rack to 2.0.4
Refactor matchers for background migrations
Add id to modal.vue to support data-toggle="modal"
Allow local tests to use a modified Gitaly
Fix specs
Use computed prop in expand button
Update check.md
add deprecation and removal issue to docs
Add status attribute to runner api entity
Fix typos in a code comment
Refactor RelativePositioning so that it can be used by other classes
Backport 'Rebase' feature from EE to CE
Just try to detect and assign once
Fix custom name in branch creation for issue in Firefox
Modify `LDAP::Person` to return username value based on attributes
...
Diffstat (limited to 'lib/gitlab/diff/file.rb')
-rw-r--r-- | lib/gitlab/diff/file.rb | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index cd490aaa291..34b070dd375 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -116,8 +116,10 @@ module Gitlab new_content_sha || old_content_sha end + # Use #itself to check the value wrapped by a BatchLoader instance, rather + # than if the BatchLoader instance itself is falsey. def blob - new_blob || old_blob + new_blob&.itself || old_blob&.itself end attr_writer :highlighted_diff_lines @@ -173,7 +175,7 @@ module Gitlab end def binary? - has_binary_notice? || old_blob&.binary? || new_blob&.binary? + has_binary_notice? || try_blobs(:binary?) end def text? @@ -181,15 +183,15 @@ module Gitlab end def external_storage_error? - old_blob&.external_storage_error? || new_blob&.external_storage_error? + try_blobs(:external_storage_error?) end def stored_externally? - old_blob&.stored_externally? || new_blob&.stored_externally? + try_blobs(:stored_externally?) end def external_storage - old_blob&.external_storage || new_blob&.external_storage + try_blobs(:external_storage) end def content_changed? @@ -204,15 +206,15 @@ module Gitlab end def size - [old_blob&.size, new_blob&.size].compact.sum + valid_blobs.map(&:size).sum end def raw_size - [old_blob&.raw_size, new_blob&.raw_size].compact.sum + valid_blobs.map(&:raw_size).sum end def raw_binary? - old_blob&.raw_binary? || new_blob&.raw_binary? + try_blobs(:raw_binary?) end def raw_text? @@ -235,6 +237,19 @@ module Gitlab private + # The blob instances are instances of BatchLoader, which means calling + # &. directly on them won't work. Object#try also won't work, because Blob + # doesn't inherit from Object, but from BasicObject (via SimpleDelegator). + def try_blobs(meth) + old_blob&.itself&.public_send(meth) || new_blob&.itself&.public_send(meth) + end + + # We can't use #compact for the same reason we can't use &., but calling + # #nil? explicitly does work because it is proxied to the blob itself. + def valid_blobs + [old_blob, new_blob].reject(&:nil?) + end + def text_position_properties(line) { old_line: line.old_line, new_line: line.new_line } end |