summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff/file_collection
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-07-27 13:09:52 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-08-03 07:00:20 +0200
commit1d0c7b74920a94e488e6a2c090abb3e525438053 (patch)
tree746321bd5aa1d580f8df0337389fb92bb64ca1eb /lib/gitlab/diff/file_collection
parent8f359ea9170b984ad43d126e17628c31ac3a1f14 (diff)
downloadgitlab-ce-1d0c7b74920a94e488e6a2c090abb3e525438053.tar.gz
Introduce Compare model in the codebase.
This object will manage Gitlab::Git::Compare instances
Diffstat (limited to 'lib/gitlab/diff/file_collection')
-rw-r--r--lib/gitlab/diff/file_collection/base.rb2
-rw-r--r--lib/gitlab/diff/file_collection/commit.rb3
-rw-r--r--lib/gitlab/diff/file_collection/compare.rb3
-rw-r--r--lib/gitlab/diff/file_collection/merge_request.rb10
4 files changed, 10 insertions, 8 deletions
diff --git a/lib/gitlab/diff/file_collection/base.rb b/lib/gitlab/diff/file_collection/base.rb
index 20562773c14..a0c88265c45 100644
--- a/lib/gitlab/diff/file_collection/base.rb
+++ b/lib/gitlab/diff/file_collection/base.rb
@@ -7,7 +7,7 @@ module Gitlab
delegate :count, :size, :real_size, to: :diff_files
- def initialize(diffs, project:, diff_options:, diff_refs: nil)
+ def initialize(diffs, project:, diff_options: nil, diff_refs: nil)
@diffs = diffs
@project = project
@diff_options = diff_options
diff --git a/lib/gitlab/diff/file_collection/commit.rb b/lib/gitlab/diff/file_collection/commit.rb
index 2a46109ad99..19def300b74 100644
--- a/lib/gitlab/diff/file_collection/commit.rb
+++ b/lib/gitlab/diff/file_collection/commit.rb
@@ -3,6 +3,9 @@ module Gitlab
module FileCollection
class Commit < Base
def initialize(commit, diff_options:)
+ # Not merge just set defaults
+ diff_options = diff_options || Gitlab::Diff::FileCollection.default_options
+
super(commit.diffs(diff_options),
project: commit.project,
diff_options: diff_options,
diff --git a/lib/gitlab/diff/file_collection/compare.rb b/lib/gitlab/diff/file_collection/compare.rb
index 1bcda145f15..aba5a28b51f 100644
--- a/lib/gitlab/diff/file_collection/compare.rb
+++ b/lib/gitlab/diff/file_collection/compare.rb
@@ -3,6 +3,9 @@ module Gitlab
module FileCollection
class Compare < Base
def initialize(compare, project:, diff_options:, diff_refs: nil)
+ # Not merge just set defaults
+ diff_options = diff_options || Gitlab::Diff::FileCollection.default_options
+
super(compare.diffs(diff_options),
project: project,
diff_options: diff_options,
diff --git a/lib/gitlab/diff/file_collection/merge_request.rb b/lib/gitlab/diff/file_collection/merge_request.rb
index 7c40622d594..9fde0bba183 100644
--- a/lib/gitlab/diff/file_collection/merge_request.rb
+++ b/lib/gitlab/diff/file_collection/merge_request.rb
@@ -4,6 +4,8 @@ module Gitlab
class MergeRequest < Base
def initialize(merge_request, diff_options:)
@merge_request = merge_request
+ # Not merge just set defaults
+ diff_options = diff_options || Gitlab::Diff::FileCollection.default_options
super(merge_request.diffs(diff_options),
project: merge_request.project,
@@ -27,15 +29,10 @@ module Gitlab
if cacheable?
cache_highlight!(diff_file)
else
- highlight_diff_file!(diff_file)
+ diff_file # Don't need to eager load highlighted diff lines
end
end
- def highlight_diff_file!(diff_file)
- diff_file.highlighted_diff_lines = Gitlab::Diff::Highlight.new(diff_file, repository: diff_file.repository).highlight
- diff_file
- end
-
def highlight_diff_file_from_cache!(diff_file, cache_diff_lines)
diff_file.highlighted_diff_lines = cache_diff_lines.map do |line|
Gitlab::Diff::Line.init_from_hash(line)
@@ -56,7 +53,6 @@ module Gitlab
if highlight_cache[file_path]
highlight_diff_file_from_cache!(diff_file, highlight_cache[file_path])
else
- highlight_diff_file!(diff_file)
highlight_cache[file_path] = diff_file.highlighted_diff_lines.map(&:to_hash)
end