summaryrefslogtreecommitdiff
path: root/app/models/compare.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/compare.rb')
-rw-r--r--app/models/compare.rb47
1 files changed, 45 insertions, 2 deletions
diff --git a/app/models/compare.rb b/app/models/compare.rb
index 6672d1bf059..05c8fbbcc36 100644
--- a/app/models/compare.rb
+++ b/app/models/compare.rb
@@ -1,5 +1,5 @@
class Compare
- delegate :commits, :same, :head, :base, to: :@compare
+ delegate :same, :head, :base, to: :@compare
def self.decorate(compare, project)
if compare.is_a?(Compare)
@@ -14,10 +14,53 @@ class Compare
@project = project
end
- def diff_file_collection(diff_options:, diff_refs: nil)
+ def commits
+ @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
+ end
+
+ def commit
+ return @commit if defined?(@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
+ end
+
+ 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)
+ 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,
diff_options: diff_options,
diff_refs: diff_refs)
end
+
+ def diff_refs
+ @diff_refs ||= Gitlab::Diff::DiffRefs.new(
+ base_sha: base_commit.try(:sha),
+ start_sha: start_commit.try(:sha),
+ head_sha: commit.try(:sha)
+ )
+ end
end