2016-07-26 03:21:42 -04:00
|
|
|
class Compare
|
2016-07-27 07:09:52 -04:00
|
|
|
delegate :same, :head, :base, to: :@compare
|
2016-07-26 03:21:42 -04:00
|
|
|
|
2016-07-27 13:00:34 -04:00
|
|
|
attr_reader :project
|
|
|
|
|
2016-07-26 03:21:42 -04:00
|
|
|
def self.decorate(compare, project)
|
|
|
|
if compare.is_a?(Compare)
|
|
|
|
compare
|
|
|
|
else
|
|
|
|
self.new(compare, project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(compare, project)
|
|
|
|
@compare = compare
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
2016-07-27 07:09:52 -04:00
|
|
|
def commits
|
2016-07-27 13:00:34 -04:00
|
|
|
@commits ||= Commit.decorate(@compare.commits, project)
|
2016-07-27 07:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_commit
|
|
|
|
return @start_commit if defined?(@start_commit)
|
|
|
|
|
|
|
|
commit = @compare.base
|
2016-07-27 13:00:34 -04:00
|
|
|
@start_commit = commit ? ::Commit.new(commit, project) : nil
|
2016-07-27 07:09:52 -04:00
|
|
|
end
|
|
|
|
|
2016-07-27 13:00:34 -04:00
|
|
|
def head_commit
|
|
|
|
return @head_commit if defined?(@head_commit)
|
2016-07-27 07:09:52 -04:00
|
|
|
|
|
|
|
commit = @compare.head
|
2016-07-27 13:00:34 -04:00
|
|
|
@head_commit = commit ? ::Commit.new(commit, project) : nil
|
2016-07-27 07:09:52 -04:00
|
|
|
end
|
2016-07-27 13:00:34 -04:00
|
|
|
alias_method :commit, :head_commit
|
2016-07-27 07:09:52 -04:00
|
|
|
|
|
|
|
def base_commit
|
|
|
|
return @base_commit if defined?(@base_commit)
|
|
|
|
|
2016-07-27 13:00:34 -04:00
|
|
|
@base_commit = if start_commit && head_commit
|
|
|
|
project.merge_base_commit(start_commit.id, head_commit.id)
|
2016-07-27 07:09:52 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-27 13:00:34 -04:00
|
|
|
def raw_diffs(*args)
|
|
|
|
@compare.diffs(*args)
|
|
|
|
end
|
|
|
|
|
2016-08-03 12:32:01 -04:00
|
|
|
def diffs(diff_options = nil)
|
2016-07-27 13:00:34 -04:00
|
|
|
Gitlab::Diff::FileCollection::Compare.new(self,
|
|
|
|
project: project,
|
2016-07-26 03:21:42 -04:00
|
|
|
diff_options: diff_options,
|
|
|
|
diff_refs: diff_refs)
|
|
|
|
end
|
2016-07-27 07:09:52 -04:00
|
|
|
|
|
|
|
def diff_refs
|
2016-07-27 13:00:34 -04:00
|
|
|
Gitlab::Diff::DiffRefs.new(
|
2016-07-27 07:09:52 -04:00
|
|
|
base_sha: base_commit.try(:sha),
|
|
|
|
start_sha: start_commit.try(:sha),
|
|
|
|
head_sha: commit.try(:sha)
|
|
|
|
)
|
|
|
|
end
|
2016-07-26 03:21:42 -04:00
|
|
|
end
|