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
respond_to do |format|
format.html { define_discussion_vars }
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
@diff_notes_disabled = true
end
......
......@@ -79,14 +79,10 @@ class MergeRequestDiff < ActiveRecord::Base
def raw_diffs(options = {})
if options[:ignore_whitespace_change]
@diffs_no_whitespace ||=
begin
compare = Gitlab::Git::Compare.new(
repository.raw_repository,
safe_start_commit_sha,
safe_head_commit_sha
)
compare.diffs(options)
end
Gitlab::Git::Compare.new(
repository.raw_repository,
safe_start_commit_sha,
safe_head_commit_sha).diffs(options)
else
@raw_diffs ||= {}
@raw_diffs[options] ||= load_diffs(st_diffs, options)
......@@ -164,6 +160,10 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
def latest?
self == merge_request.merge_request_diff
end
private
def dump_commits(commits)
......
- merge_request_diffs = @merge_request.merge_request_diffs.select_without_diff
- latest_diff = merge_request_diffs.first
- if merge_request_diffs.size > 1
.mr-version-switch
......@@ -7,7 +6,7 @@
%span.dropdown.inline
%a.btn-link.dropdown-toggle{ data: {toggle: :dropdown} }
%strong.monospace<
- if latest_diff == @merge_request_diff
- if @merge_request_diff.latest?
#{"latest"}
- else
#{@merge_request_diff.head_commit.short_id}
......
......@@ -13,6 +13,15 @@ describe MergeRequestDiff, models: true do
it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') }
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
let(:mr) { create(:merge_request, :with_diffs) }
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