Commit d9a0188d authored by Douwe Maan's avatar Douwe Maan

Add question mark to Gitlab::Diff::File predicate methods

parent 52527be4
...@@ -120,8 +120,8 @@ module DiffHelper ...@@ -120,8 +120,8 @@ module DiffHelper
} }
end end
def editable_diff?(diff) def editable_diff?(diff_file)
!diff.deleted_file && @merge_request && @merge_request.source_project !diff_file.deleted_file? && @merge_request && @merge_request.source_project
end end
private private
......
...@@ -26,28 +26,28 @@ ...@@ -26,28 +26,28 @@
%h4 #{pluralize @message.diffs_count, "changed file"}: %h4 #{pluralize @message.diffs_count, "changed file"}:
- diff_files = @message.diffs
%ul %ul
- @message.diffs.each do |diff| - diff_files.each do |diff_file|
%li.file-stats %li.file-stats
%a{ href: "#{@message.target_url if @message.disable_diffs?}##{hexdigest(diff.file_path)}" } %a{ href: "#{@message.target_url if @message.disable_diffs?}##{hexdigest(diff_file.file_path)}" }
- if diff.deleted_file - if diff_file.deleted_file?
%span.deleted-file %span.deleted-file
− −
= diff.old_path = diff_file.old_path
- elsif diff.renamed_file - elsif diff_file.renamed_file?
= diff.old_path = diff_file.old_path
→ →
= diff.new_path = diff_file.new_path
- elsif diff.new_file - elsif diff_file.new_file?
%span.new-file %span.new-file
+ +
= diff.new_path = diff_file.new_path
- else - else
= diff.new_path = diff_file.new_path
- unless @message.disable_diffs? - unless @message.disable_diffs?
- diff_files = @message.diffs
- if @message.compare_timeout - if @message.compare_timeout
%h5 The diff was not included because it is too large. %h5 The diff was not included because it is too large.
- else - else
...@@ -56,11 +56,11 @@ ...@@ -56,11 +56,11 @@
- file_hash = hexdigest(diff_file.file_path) - file_hash = hexdigest(diff_file.file_path)
%li{ id: file_hash } %li{ id: file_hash }
%a{ href: @message.target_url + "##{file_hash}" }< %a{ href: @message.target_url + "##{file_hash}" }<
- if diff_file.deleted_file - if diff_file.deleted_file?
%strong< %strong<
= diff_file.old_path = diff_file.old_path
deleted deleted
- elsif diff_file.renamed_file - elsif diff_file.renamed_file?
%strong< %strong<
= diff_file.old_path = diff_file.old_path
&rarr; &rarr;
......
...@@ -15,15 +15,15 @@ ...@@ -15,15 +15,15 @@
\ \
#{pluralize @message.diffs_count, "changed file"}: #{pluralize @message.diffs_count, "changed file"}:
\ \
- @message.diffs.each do |diff| - @message.diffs.each do |diff_file|
- if diff.deleted_file - if diff_file.deleted_file?
\- − #{diff.old_path} \- − #{diff_file.old_path}
- elsif diff.renamed_file - elsif diff_file.renamed_file?
\- #{diff.old_path}#{diff.new_path} \- #{diff_file.old_path}#{diff_file.new_path}
- elsif diff.new_file - elsif diff_file.new_file?
\- + #{diff.new_path} \- + #{diff_file.new_path}
- else - else
\- #{diff.new_path} \- #{diff_file.new_path}
- unless @message.disable_diffs? - unless @message.disable_diffs?
- if @message.compare_timeout - if @message.compare_timeout
\ \
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
- @message.diffs.each do |diff_file| - @message.diffs.each do |diff_file|
\ \
\===================================== \=====================================
- if diff_file.deleted_file - if diff_file.deleted_file?
#{diff_file.old_path} deleted #{diff_file.old_path} deleted
- elsif diff_file.renamed_file - elsif diff_file.renamed_file?
#{diff_file.old_path}#{diff_file.new_path} #{diff_file.old_path}#{diff_file.new_path}
- else - else
= diff_file.new_path = diff_file.new_path
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
- else - else
- if diff_file.mode_changed? - if diff_file.mode_changed?
.nothing-here-block File mode changed .nothing-here-block File mode changed
- elsif diff_file.renamed_file - elsif diff_file.renamed_file?
.nothing-here-block File moved .nothing-here-block File moved
- elsif blob.image? - elsif blob.image?
- old_blob = diff_file.old_blob(diff_file.old_content_commit || @base_commit) - old_blob = diff_file.old_blob(diff_file.old_content_commit || @base_commit)
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
- if discussions_left || discussions_right - if discussions_left || discussions_right
= render "discussions/parallel_diff_discussion", discussions_left: discussions_left, discussions_right: discussions_right = render "discussions/parallel_diff_discussion", discussions_left: discussions_left, discussions_right: discussions_right
- if !diff_file.new_file && !diff_file.deleted_file && diff_file.diff_lines.any? - if !diff_file.new_file? && !diff_file.deleted_file? && diff_file.diff_lines.any?
- last_line = diff_file.diff_lines.last - last_line = diff_file.diff_lines.last
- if last_line.new_pos < total_lines - if last_line.new_pos < total_lines
%tr.line_holder.parallel %tr.line_holder.parallel
......
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
- diff_files.each do |diff_file| - diff_files.each do |diff_file|
- file_hash = hexdigest(diff_file.file_path) - file_hash = hexdigest(diff_file.file_path)
%li %li
- if diff_file.deleted_file - if diff_file.deleted_file?
%span.deleted-file %span.deleted-file
%a{ href: "##{file_hash}" } %a{ href: "##{file_hash}" }
%i.fa.fa-minus %i.fa.fa-minus
= diff_file.old_path = diff_file.old_path
- elsif diff_file.renamed_file - elsif diff_file.renamed_file?
%span.renamed-file %span.renamed-file
%a{ href: "##{file_hash}" } %a{ href: "##{file_hash}" }
%i.fa.fa-minus %i.fa.fa-minus
= diff_file.old_path = diff_file.old_path
&rarr; &rarr;
= diff_file.new_path = diff_file.new_path
- elsif diff_file.new_file - elsif diff_file.new_file?
%span.new-file %span.new-file
%a{ href: "##{file_hash}" } %a{ href: "##{file_hash}" }
%i.fa.fa-plus %i.fa.fa-plus
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
as: :line, as: :line,
locals: { diff_file: diff_file, discussions: @grouped_diff_discussions } locals: { diff_file: diff_file, discussions: @grouped_diff_discussions }
- if !diff_file.new_file && !diff_file.deleted_file && diff_file.highlighted_diff_lines.any? - if !diff_file.new_file? && !diff_file.deleted_file? && diff_file.highlighted_diff_lines.any?
- last_line = diff_file.highlighted_diff_lines.last - last_line = diff_file.highlighted_diff_lines.last
- if last_line.new_pos < total_lines - if last_line.new_pos < total_lines
%tr.line_holder %tr.line_holder
......
...@@ -252,7 +252,9 @@ module API ...@@ -252,7 +252,9 @@ module API
class RepoDiff < Grape::Entity class RepoDiff < Grape::Entity
expose :old_path, :new_path, :a_mode, :b_mode, :diff expose :old_path, :new_path, :a_mode, :b_mode, :diff
expose :new_file, :renamed_file, :deleted_file expose :new_file?, as: :new_file
expose :renamed_file?, as: :renamed_file
expose :deleted_file?, as: :deleted_file
end end
class Milestone < ProjectEntity class Milestone < ProjectEntity
......
...@@ -3,8 +3,8 @@ module Gitlab ...@@ -3,8 +3,8 @@ module Gitlab
class File class File
attr_reader :diff, :repository, :diff_refs attr_reader :diff, :repository, :diff_refs
delegate :new_file, :deleted_file, :renamed_file, delegate :new_file?, :deleted_file?, :renamed_file?,
:old_path, :new_path, :a_mode, :b_mode, :old_path, :new_path, :a_mode, :b_mode, :mode_changed?,
:submodule?, :too_large?, :collapsed?, to: :diff, prefix: false :submodule?, :too_large?, :collapsed?, to: :diff, prefix: false
def initialize(diff, repository:, diff_refs: nil) def initialize(diff, repository:, diff_refs: nil)
...@@ -85,10 +85,6 @@ module Gitlab ...@@ -85,10 +85,6 @@ module Gitlab
@parallel_diff_lines ||= Gitlab::Diff::ParallelDiff.new(self).parallelize @parallel_diff_lines ||= Gitlab::Diff::ParallelDiff.new(self).parallelize
end end
def mode_changed?
a_mode && b_mode && a_mode != b_mode
end
def raw_diff def raw_diff
diff.diff.to_s diff.diff.to_s
end end
...@@ -119,6 +115,7 @@ module Gitlab ...@@ -119,6 +115,7 @@ module Gitlab
def old_blob(commit = old_content_commit) def old_blob(commit = old_content_commit)
return unless commit return unless commit
return if new_file?
repository.blob_at(commit.id, old_path) repository.blob_at(commit.id, old_path)
end end
...@@ -130,7 +127,7 @@ module Gitlab ...@@ -130,7 +127,7 @@ module Gitlab
end end
def file_identifier def file_identifier
"#{file_path}-#{new_file}-#{deleted_file}-#{renamed_file}" "#{file_path}-#{new_file?}-#{deleted_file?}-#{renamed_file?}"
end end
end end
end end
......
...@@ -11,6 +11,10 @@ module Gitlab ...@@ -11,6 +11,10 @@ module Gitlab
# Stats properties # Stats properties
attr_accessor :new_file, :renamed_file, :deleted_file attr_accessor :new_file, :renamed_file, :deleted_file
alias_method :new_file?, :new_file
alias_method :deleted_file?, :deleted_file
alias_method :renamed_file?, :renamed_file
attr_accessor :too_large attr_accessor :too_large
# The maximum size of a diff to display. # The maximum size of a diff to display.
...@@ -208,6 +212,10 @@ module Gitlab ...@@ -208,6 +212,10 @@ module Gitlab
hash hash
end end
def mode_changed?
a_mode && b_mode && a_mode != b_mode
end
def submodule? def submodule?
a_mode == '160000' || b_mode == '160000' a_mode == '160000' || b_mode == '160000'
end end
......
...@@ -22,7 +22,7 @@ describe Gitlab::Diff::Position, lib: true do ...@@ -22,7 +22,7 @@ describe Gitlab::Diff::Position, lib: true do
it "returns the correct diff file" do it "returns the correct diff file" do
diff_file = subject.diff_file(project.repository) diff_file = subject.diff_file(project.repository)
expect(diff_file.new_file).to be true expect(diff_file.new_file?).to be true
expect(diff_file.new_path).to eq(subject.new_path) expect(diff_file.new_path).to eq(subject.new_path)
expect(diff_file.diff_refs).to eq(subject.diff_refs) expect(diff_file.diff_refs).to eq(subject.diff_refs)
end end
...@@ -314,7 +314,7 @@ describe Gitlab::Diff::Position, lib: true do ...@@ -314,7 +314,7 @@ describe Gitlab::Diff::Position, lib: true do
it "returns the correct diff file" do it "returns the correct diff file" do
diff_file = subject.diff_file(project.repository) diff_file = subject.diff_file(project.repository)
expect(diff_file.deleted_file).to be true expect(diff_file.deleted_file?).to be true
expect(diff_file.old_path).to eq(subject.old_path) expect(diff_file.old_path).to eq(subject.old_path)
expect(diff_file.diff_refs).to eq(subject.diff_refs) expect(diff_file.diff_refs).to eq(subject.diff_refs)
end end
...@@ -356,7 +356,7 @@ describe Gitlab::Diff::Position, lib: true do ...@@ -356,7 +356,7 @@ describe Gitlab::Diff::Position, lib: true do
it "returns the correct diff file" do it "returns the correct diff file" do
diff_file = subject.diff_file(project.repository) diff_file = subject.diff_file(project.repository)
expect(diff_file.new_file).to be true expect(diff_file.new_file?).to be true
expect(diff_file.new_path).to eq(subject.new_path) expect(diff_file.new_path).to eq(subject.new_path)
expect(diff_file.diff_refs).to eq(subject.diff_refs) expect(diff_file.diff_refs).to eq(subject.diff_refs)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment