summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-07-06 19:29:41 -0400
committerDouwe Maan <douwe@selenight.nl>2016-07-06 19:29:41 -0400
commitac26b23712963b0471db9742fc340ea4fb8935a9 (patch)
tree3eb3eea43ed5ffe83b453807ceef00488a0fe2e5
parent2db75f8debd96c48c6cb8548824dd72bd71fb176 (diff)
downloadgitlab-ce-ac26b23712963b0471db9742fc340ea4fb8935a9.tar.gz
Remove duplication, unused methods, and some other style things
-rw-r--r--app/helpers/diff_helper.rb4
-rw-r--r--app/models/concerns/note_on_diff.rb2
-rw-r--r--app/models/merge_request.rb6
-rw-r--r--app/views/projects/diffs/_diffs.html.haml2
-rw-r--r--lib/gitlab/diff/file.rb7
-rw-r--r--lib/gitlab/diff/highlight.rb11
6 files changed, 14 insertions, 18 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index c7c291516fc..eb57516247d 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 6d8b9b76c84..2785fbb21c9 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 ed99142902e..083e93f1ee7 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 8f252282692..1975287faee 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 3941e963c03..b0c50edba59 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 44ea6bf6102..649a265a02c 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.