Commit d64c15c5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add code improvements to merge request version feature

* Add MergeRequestDiff#latest?
* Remove unnecessary variable assignment
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 03671c30
...@@ -93,7 +93,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -93,7 +93,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html { define_discussion_vars } format.html { define_discussion_vars }
format.json do format.json do
if @merge_request_diff != @merge_request.merge_request_diff unless @merge_request_diff.latest?
# Disable comments if browsing older version of the diff # Disable comments if browsing older version of the diff
@diff_notes_disabled = true @diff_notes_disabled = true
end end
......
...@@ -79,14 +79,10 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -79,14 +79,10 @@ class MergeRequestDiff < ActiveRecord::Base
def raw_diffs(options = {}) def raw_diffs(options = {})
if options[:ignore_whitespace_change] if options[:ignore_whitespace_change]
@diffs_no_whitespace ||= @diffs_no_whitespace ||=
begin Gitlab::Git::Compare.new(
compare = Gitlab::Git::Compare.new( repository.raw_repository,
repository.raw_repository, safe_start_commit_sha,
safe_start_commit_sha, safe_head_commit_sha).diffs(options)
safe_head_commit_sha
)
compare.diffs(options)
end
else else
@raw_diffs ||= {} @raw_diffs ||= {}
@raw_diffs[options] ||= load_diffs(st_diffs, options) @raw_diffs[options] ||= load_diffs(st_diffs, options)
...@@ -164,6 +160,10 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -164,6 +160,10 @@ class MergeRequestDiff < ActiveRecord::Base
end end
end end
def latest?
self == merge_request.merge_request_diff
end
private private
def dump_commits(commits) def dump_commits(commits)
......
- merge_request_diffs = @merge_request.merge_request_diffs.select_without_diff - merge_request_diffs = @merge_request.merge_request_diffs.select_without_diff
- latest_diff = merge_request_diffs.first
- if merge_request_diffs.size > 1 - if merge_request_diffs.size > 1
.mr-version-switch .mr-version-switch
...@@ -7,7 +6,7 @@ ...@@ -7,7 +6,7 @@
%span.dropdown.inline %span.dropdown.inline
%a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} } %a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} }
%strong.monospace< %strong.monospace<
- if latest_diff == @merge_request_diff - if @merge_request_diff.latest?
#{"latest"} #{"latest"}
- else - else
#{@merge_request_diff.head_commit.short_id} #{@merge_request_diff.head_commit.short_id}
......
...@@ -13,6 +13,15 @@ describe MergeRequestDiff, models: true do ...@@ -13,6 +13,15 @@ describe MergeRequestDiff, models: true do
it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') } it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') }
end end
describe '#latest' do
let!(:mr) { create(:merge_request, :with_diffs) }
let!(:first_diff) { mr.merge_request_diff }
let!(:last_diff) { mr.create_merge_request_diff }
it { expect(last_diff.latest?).to be_truthy }
it { expect(first_diff.latest?).to be_falsey }
end
describe '#diffs' do describe '#diffs' do
let(:mr) { create(:merge_request, :with_diffs) } let(:mr) { create(:merge_request, :with_diffs) }
let(:mr_diff) { mr.merge_request_diff } let(:mr_diff) { mr.merge_request_diff }
......
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