summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb10
-rw-r--r--app/models/compare.rb36
-rw-r--r--app/models/legacy_diff_note.rb4
-rw-r--r--app/models/merge_request.rb8
-rw-r--r--app/models/repository.rb2
5 files changed, 32 insertions, 28 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index a339d47f5f3..d58c2fb8106 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -104,7 +104,7 @@ class Commit
end
def diff_line_count
- @diff_line_count ||= Commit::diff_line_count(self.diffs)
+ @diff_line_count ||= Commit::diff_line_count(raw_diffs)
@diff_line_count
end
@@ -317,7 +317,11 @@ class Commit
nil
end
- def diff_file_collection(diff_options = nil)
+ def raw_diffs(*args)
+ raw.diffs(*args)
+ end
+
+ def diffs(diff_options = nil)
Gitlab::Diff::FileCollection::Commit.new(self, diff_options: diff_options)
end
@@ -330,7 +334,7 @@ class Commit
def repo_changes
changes = { added: [], modified: [], removed: [] }
- diffs.each do |diff|
+ raw_diffs.each do |diff|
if diff.deleted_file
changes[:removed] << diff.old_path
elsif diff.renamed_file || diff.new_file
diff --git a/app/models/compare.rb b/app/models/compare.rb
index 05c8fbbcc36..98c042f3809 100644
--- a/app/models/compare.rb
+++ b/app/models/compare.rb
@@ -1,6 +1,8 @@
class Compare
delegate :same, :head, :base, to: :@compare
+ attr_reader :project
+
def self.decorate(compare, project)
if compare.is_a?(Compare)
compare
@@ -15,49 +17,47 @@ class Compare
end
def commits
- @commits ||= Commit.decorate(@compare.commits, @project)
+ @commits ||= Commit.decorate(@compare.commits, project)
end
def start_commit
return @start_commit if defined?(@start_commit)
commit = @compare.base
- @start_commit = commit ? ::Commit.new(commit, @project) : nil
+ @start_commit = commit ? ::Commit.new(commit, project) : nil
end
- def commit
- return @commit if defined?(@commit)
+ def head_commit
+ return @head_commit if defined?(@head_commit)
commit = @compare.head
- @commit = commit ? ::Commit.new(commit, @project) : nil
- end
- alias_method :head_commit, :commit
-
- # Used only on emails_on_push_worker.rb
- def base_commit=(commit)
- @base_commit = commit
+ @head_commit = commit ? ::Commit.new(commit, project) : nil
end
+ alias_method :commit, :head_commit
def base_commit
return @base_commit if defined?(@base_commit)
- @base_commit = if start_commit && commit
- @project.merge_base_commit(start_commit.id, commit.id)
+ @base_commit = if start_commit && head_commit
+ project.merge_base_commit(start_commit.id, head_commit.id)
else
nil
end
end
- # keyword args until we get ride of diff_refs as argument
- def diff_file_collection(diff_options:, diff_refs: self.diff_refs)
- Gitlab::Diff::FileCollection::Compare.new(@compare,
- project: @project,
+ def raw_diffs(*args)
+ @compare.diffs(*args)
+ end
+
+ def diffs(diff_options:)
+ Gitlab::Diff::FileCollection::Compare.new(self,
+ project: project,
diff_options: diff_options,
diff_refs: diff_refs)
end
def diff_refs
- @diff_refs ||= Gitlab::Diff::DiffRefs.new(
+ Gitlab::Diff::DiffRefs.new(
base_sha: base_commit.try(:sha),
start_sha: start_commit.try(:sha),
head_sha: commit.try(:sha)
diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb
index 865712268a0..6ed66001513 100644
--- a/app/models/legacy_diff_note.rb
+++ b/app/models/legacy_diff_note.rb
@@ -85,7 +85,7 @@ class LegacyDiffNote < Note
return nil unless noteable
return @diff if defined?(@diff)
- @diff = noteable.diffs(Commit.max_diff_options).find do |d|
+ @diff = noteable.raw_diffs(Commit.max_diff_options).find do |d|
d.new_path && Digest::SHA1.hexdigest(d.new_path) == diff_file_hash
end
end
@@ -116,7 +116,7 @@ class LegacyDiffNote < Note
# Find the diff on noteable that matches our own
def find_noteable_diff
- diffs = noteable.diffs(Commit.max_diff_options)
+ diffs = noteable.raw_diffs(Commit.max_diff_options)
diffs.find { |d| d.new_path == self.diff.new_path }
end
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 62e5573dfdc..009262d6b48 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -164,13 +164,13 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff ? merge_request_diff.first_commit : compare_commits.first
end
- def diffs(*args)
- merge_request_diff ? merge_request_diff.diffs(*args) : compare.diffs(*args)
+ def raw_diffs(*args)
+ merge_request_diff ? merge_request_diff.diffs(*args) : compare.raw_diffs(*args)
end
- def diff_file_collection(diff_options = nil)
+ def diffs(diff_options = nil)
if self.compare
- self.compare.diff_file_collection(diff_options: diff_options, diff_refs: diff_refs)
+ self.compare.diffs(diff_options: diff_options)
else
Gitlab::Diff::FileCollection::MergeRequest.new(self, diff_options: diff_options)
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index bac37483c47..3d95344a68f 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -372,7 +372,7 @@ class Repository
# We don't want to flush the cache if the commit didn't actually make any
# changes to any of the possible avatar files.
if revision && commit = self.commit(revision)
- return unless commit.diffs.
+ return unless commit.raw_diffs.
any? { |diff| AVATAR_FILES.include?(diff.new_path) }
end