Welcome to mirror list, hosted at ThFree Co, Russian Federation.

compare.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4856510f5263360306304d6b1be45fdab2db6297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Compare
  delegate :same, :head, :base, to: :@compare

  attr_reader :project

  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

  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 head_commit
    return @head_commit if defined?(@head_commit)

    commit = @compare.head
    @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 && head_commit
                     project.merge_base_commit(start_commit.id, head_commit.id)
                   else
                     nil
                   end
  end

  def raw_diffs(*args)
    @compare.diffs(*args)
  end

  def diffs(diff_options = nil)
    Gitlab::Diff::FileCollection::Compare.new(self,
      project: project,
      diff_options: diff_options,
      diff_refs: diff_refs)
  end

  def 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