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 ...@@ -89,6 +89,8 @@ module DiffHelper
end end
def commit_for_diff(diff_file) def commit_for_diff(diff_file)
return diff_file.content_commit if diff_file.content_commit
if diff_file.deleted_file if diff_file.deleted_file
@base_commit || @commit.parent || @commit @base_commit || @commit.parent || @commit
else else
...@@ -97,7 +99,7 @@ module DiffHelper ...@@ -97,7 +99,7 @@ module DiffHelper
end end
def diff_file_html_data(project, diff_file) 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, blob_diff_path: namespace_project_blob_diff_path(project.namespace, project,
tree_join(commit.id, diff_file.file_path)) tree_join(commit.id, diff_file.file_path))
......
...@@ -33,13 +33,11 @@ module NoteOnDiff ...@@ -33,13 +33,11 @@ module NoteOnDiff
# Returns an array of at most 16 highlighted lines above a diff note # Returns an array of at most 16 highlighted lines above a diff note
def truncated_diff_lines def truncated_diff_lines
prev_match_line = nil
prev_lines = [] prev_lines = []
highlighted_diff_lines.each do |line| highlighted_diff_lines.each do |line|
if line.meta? if line.meta?
prev_lines.clear prev_lines.clear
prev_match_line = line
else else
prev_lines << line prev_lines << line
......
...@@ -164,10 +164,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -164,10 +164,6 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff ? merge_request_diff.first_commit : compare_commits.first merge_request_diff ? merge_request_diff.first_commit : compare_commits.first
end end
def last_commit
merge_request_diff ? merge_request_diff.last_commit : compare_commits.last
end
def diff_size def diff_size
merge_request_diff.size merge_request_diff.size
end end
...@@ -246,7 +242,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -246,7 +242,7 @@ class MergeRequest < ActiveRecord::Base
end end
def diff_refs def diff_refs
return nil unless diff_start_commit || diff_base_commit return unless diff_start_commit || diff_base_commit
Gitlab::Diff::DiffRefs.new( Gitlab::Diff::DiffRefs.new(
base_sha: diff_base_sha, base_sha: diff_base_sha,
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
.files .files
- diff_files.each_with_index do |diff_file, index| - 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) - blob = diff_file.blob(diff_commit)
- next unless blob - next unless blob
- blob.load_all_data!(project.repository) unless blob.only_display_raw? - blob.load_all_data!(project.repository) unless blob.only_display_raw?
......
...@@ -21,9 +21,7 @@ module Gitlab ...@@ -21,9 +21,7 @@ module Gitlab
new_path: new_path, new_path: new_path,
old_line: line.old_line, old_line: line.old_line,
new_line: line.new_line, new_line: line.new_line,
base_sha: diff_refs.base_sha, diff_refs: diff_refs
start_sha: diff_refs.start_sha,
head_sha: diff_refs.head_sha
) )
end end
...@@ -53,7 +51,7 @@ module Gitlab ...@@ -53,7 +51,7 @@ module Gitlab
def content_commit def content_commit
return unless diff_refs return unless diff_refs
repository.commit(deleted_file ? old_ref : new_ref) repository.commit(deleted_file ? old_ref : new_ref)
end end
...@@ -121,6 +119,7 @@ module Gitlab ...@@ -121,6 +119,7 @@ module Gitlab
def blob(commit = content_commit) def blob(commit = content_commit)
return unless commit return unless commit
repository.blob_at(commit.id, file_path) repository.blob_at(commit.id, file_path)
end end
end end
......
...@@ -42,11 +42,12 @@ module Gitlab ...@@ -42,11 +42,12 @@ module Gitlab
line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' ' line_prefix = diff_line.text.match(/\A(.)/) ? $1 : ' '
if diff_line.unchanged? || diff_line.added? rich_line =
rich_line = new_lines[diff_line.new_pos - 1] if diff_line.unchanged? || diff_line.added?
elsif diff_line.removed? new_lines[diff_line.new_pos - 1]
rich_line = old_lines[diff_line.old_pos - 1] elsif diff_line.removed?
end old_lines[diff_line.old_pos - 1]
end
# Only update text if line is found. This will prevent # Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content. # 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