diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-06-06 16:24:32 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-06-08 09:32:57 -0500 |
commit | ffbbd4112eb5a0a927925e70644128bf25145414 (patch) | |
tree | 110e91e2a110d02018451fc9a5639c8249336f21 /lib | |
parent | ba564a09d73dce3a6696dfeb55e78648ae23e627 (diff) | |
download | gitlab-ce-ffbbd4112eb5a0a927925e70644128bf25145414.tar.gz |
Move diffable? method from Repository to Diff::Filedm-diff-file-diffable
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/file.rb | 50 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 5 |
3 files changed, 38 insertions, 22 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 2aef7fdaa35..4212a0dbe2e 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -58,19 +58,19 @@ module Gitlab diff_refs&.head_sha end - def content_sha - return old_content_sha if deleted_file? - return @content_sha if defined?(@content_sha) + def new_content_sha + return if deleted_file? + return @new_content_sha if defined?(@new_content_sha) refs = diff_refs || fallback_diff_refs - @content_sha = refs&.head_sha + @new_content_sha = refs&.head_sha end - def content_commit - return @content_commit if defined?(@content_commit) + def new_content_commit + return @new_content_commit if defined?(@new_content_commit) - sha = content_sha - @content_commit = repository.commit(sha) if sha + sha = new_content_commit + @new_content_commit = repository.commit(sha) if sha end def old_content_sha @@ -88,13 +88,13 @@ module Gitlab @old_content_commit = repository.commit(sha) if sha end - def blob - return @blob if defined?(@blob) + def new_blob + return @new_blob if defined?(@new_blob) - sha = content_sha - return @blob = nil unless sha + sha = new_content_sha + return @new_blob = nil unless sha - repository.blob_at(sha, file_path) + @new_blob = repository.blob_at(sha, file_path) end def old_blob @@ -106,6 +106,18 @@ module Gitlab @old_blob = repository.blob_at(sha, old_path) end + def content_sha + new_content_sha || old_content_sha + end + + def content_commit + new_content_commit || old_content_commit + end + + def blob + new_blob || old_blob + end + attr_writer :highlighted_diff_lines # Array of Gitlab::Diff::Line objects @@ -153,6 +165,18 @@ module Gitlab def file_identifier "#{file_path}-#{new_file?}-#{deleted_file?}-#{renamed_file?}" end + + def diffable? + repository.attributes(file_path).fetch('diff') { true } + end + + def binary? + old_blob&.binary? || new_blob&.binary? + end + + def text? + !binary? + end end end end diff --git a/lib/gitlab/diff/file_collection/merge_request_diff.rb b/lib/gitlab/diff/file_collection/merge_request_diff.rb index 9a58b500a2c..fcda1fe2233 100644 --- a/lib/gitlab/diff/file_collection/merge_request_diff.rb +++ b/lib/gitlab/diff/file_collection/merge_request_diff.rb @@ -66,10 +66,7 @@ module Gitlab end def cacheable?(diff_file) - @merge_request_diff.present? && - diff_file.blob && - diff_file.blob.text? && - @project.repository.diffable?(diff_file.blob) + @merge_request_diff.present? && diff_file.text? && diff_file.diffable? end def cache_key diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 9d6adbdb4ac..85695d0a4df 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -962,11 +962,6 @@ module Gitlab end end - # Checks if the blob should be diffable according to its attributes - def diffable?(blob) - attributes(blob.path).fetch('diff') { blob.text? } - end - # Returns the Git attributes for the given file path. # # See `Gitlab::Git::Attributes` for more information. |