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, from, to) ⇒ Compare

Returns a new instance of Compare.



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
# File 'lib/gitlab_git/compare.rb', line 6

def initialize(repository, from, to)
  @commits, @diffs = [], []
  @commit = nil
  @same = false

  return unless from && to

  first = repository.commit(to.try(:strip))
  last = repository.commit(from.try(:strip))

  return unless first && last

  if first.id == last.id
    @same = true
    return
  end

  @commit = first
  @commits = repository.commits_between(last.id, first.id)

  @diffs = if @commits.size > 100
             []
           else
             repository.repo.diff(last.id, first.id) rescue []
           end
end

Instance Attribute Details

#commitObject

Returns the value of attribute commit.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def commit
  @commit
end

#commitsObject

Returns the value of attribute commits.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def commits
  @commits
end

#diffsObject

Returns the value of attribute diffs.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def diffs
  @diffs
end

#sameObject

Returns the value of attribute same.



4
5
6
# File 'lib/gitlab_git/compare.rb', line 4

def same
  @same
end