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

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

  return unless from && to

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

  return unless base && head

  if base.id == head.id
    @same = true
    return
  end

  @commit = head
  @commits = Gitlab::Git::Commit.between(repository, base.id, head.id)
  @diffs = if @commits.size > limit
             []
           else
             Gitlab::Git::Diff.between(repository, head.id, base.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