Commit ac26b237 authored by Douwe Maan's avatar Douwe Maan

Remove duplication, unused methods, and some other style things

parent 2db75f8d
......@@ -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))
......
......@@ -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
......
......@@ -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,
......
......@@ -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?
......
......@@ -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
......
......@@ -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.
......
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