Class: Gitlab::Git::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/compare.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, base, head, straight: false) ⇒ Compare

Returns a new instance of Compare.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/git/compare.rb', line 10

def initialize(repository, base, head, straight: false)
  @repository = repository
  @straight = straight

  unless base && head
    @commits = []
    return
  end

  @base = Gitlab::Git::Commit.find(repository, base.try(:strip))
  @head = Gitlab::Git::Commit.find(repository, head.try(:strip))

  @commits = [] unless @base && @head
  @commits = [] if same
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base


8
9
10
# File 'lib/gitlab/git/compare.rb', line 8

def base
  @base
end

#headObject (readonly)

Returns the value of attribute head


8
9
10
# File 'lib/gitlab/git/compare.rb', line 8

def head
  @head
end

#straightObject (readonly)

Returns the value of attribute straight


8
9
10
# File 'lib/gitlab/git/compare.rb', line 8

def straight
  @straight
end

Instance Method Details

#commitsObject


30
31
32
33
34
# File 'lib/gitlab/git/compare.rb', line 30

def commits
  return @commits if defined?(@commits)

  @commits = Gitlab::Git::Commit.between(@repository, @base.id, @head.id)
end

#diffs(options = {}) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/git/compare.rb', line 36

def diffs(options = {})
  unless @head && @base
    return Gitlab::Git::DiffCollection.new([])
  end

  paths = options.delete(:paths) || []
  options[:straight] = @straight
  Gitlab::Git::Diff.between(@repository, @head.id, @base.id, options, *paths)
end

#sameObject


26
27
28
# File 'lib/gitlab/git/compare.rb', line 26

def same
  @base && @head && @base.id == @head.id
end