diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index c7c291516fc63420c5d0762cf0d674b5442ee9e0..eb57516247db444de262a6edf3139f72504ff929 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -89,6 +89,8 @@ module DiffHelper end def commit_for_diff(diff_file) + return diff_file.content_commit if diff_file.content_commit + if diff_file.deleted_file @base_commit || @commit.parent || @commit else @@ -97,7 +99,7 @@ module DiffHelper end def diff_file_html_data(project, diff_file) - commit = diff_file.content_commit || commit_for_diff(diff_file) + commit = commit_for_diff(diff_file) { blob_diff_path: namespace_project_blob_diff_path(project.namespace, project, tree_join(commit.id, diff_file.file_path)) diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb index 6d8b9b76c847afbc10729e96cfb8cb98b961990e..2785fbb21c9966a2028cf42199e4973c2a32edc7 100644 --- a/app/models/concerns/note_on_diff.rb +++ b/app/models/concerns/note_on_diff.rb @@ -33,13 +33,11 @@ module NoteOnDiff # Returns an array of at most 16 highlighted lines above a diff note def truncated_diff_lines - prev_match_line = nil prev_lines = [] highlighted_diff_lines.each do |line| if line.meta? prev_lines.clear - prev_match_line = line else prev_lines << line diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ed99142902e6b11a745d6f1f834019e635c61fda..083e93f1ee7596414f326dec40e6607e4be05c9b 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -164,10 +164,6 @@ class MergeRequest < ActiveRecord::Base merge_request_diff ? merge_request_diff.first_commit : compare_commits.first end - def last_commit - merge_request_diff ? merge_request_diff.last_commit : compare_commits.last - end - def diff_size merge_request_diff.size end @@ -246,7 +242,7 @@ class MergeRequest < ActiveRecord::Base end def diff_refs - return nil unless diff_start_commit || diff_base_commit + return unless diff_start_commit || diff_base_commit Gitlab::Diff::DiffRefs.new( base_sha: diff_base_sha, diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index 8f25228269241e3c8e8064ce22f6ec1d52b0c595..1975287faee0aac7b928008d40f458832090cbc3 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -23,7 +23,7 @@ .files - diff_files.each_with_index do |diff_file, index| - - diff_commit = diff_file.content_commit || commit_for_diff(diff_file) + - diff_commit = commit_for_diff(diff_file) - blob = diff_file.blob(diff_commit) - next unless blob - blob.load_all_data!(project.repository) unless blob.only_display_raw? diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 3941e963c03b12e73820303f2aafcf09bea97e77..b0c50edba59642975157000039c07753361018ca 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -21,9 +21,7 @@ module Gitlab new_path: new_path, old_line: line.old_line, new_line: line.new_line, - base_sha: diff_refs.base_sha, - start_sha: diff_refs.start_sha, - head_sha: diff_refs.head_sha + diff_refs: diff_refs ) end @@ -53,7 +51,7 @@ module Gitlab def content_commit return unless diff_refs - + repository.commit(deleted_file ? old_ref : new_ref) end @@ -121,6 +119,7 @@ module Gitlab def blob(commit = content_commit) return unless commit + repository.blob_at(commit.id, file_path) end end diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb index 44ea6bf61022342b5926be665d60f4867d0b723a..649a265a02c34e5130aeafd70617d80141dfeb9d 100644 --- a/lib/gitlab/diff/highlight.rb +++ b/lib/gitlab/diff/highlight.rb @@ -42,11 +42,12 @@ module Gitlab line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' ' - if diff_line.unchanged? || diff_line.added? - rich_line = new_lines[diff_line.new_pos - 1] - elsif diff_line.removed? - rich_line = old_lines[diff_line.old_pos - 1] - end + rich_line = + if diff_line.unchanged? || diff_line.added? + new_lines[diff_line.new_pos - 1] + elsif diff_line.removed? + old_lines[diff_line.old_pos - 1] + end # Only update text if line is found. This will prevent # issues with submodules given the line only exists in diff content.