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

def initialize(repository, from, to, limit = 100)
  @commits, @diffs = [], []
  @commit = nil
  @same = false
  @limit = limit
  @repository = repository
  @timeout = 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)
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

#diffs(paths = nil) ⇒ Object

Returns the value of attribute diffs.



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

def diffs
  @diffs
end

#limitObject

Returns the value of attribute limit.



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

def limit
  @limit
end

#sameObject

Returns the value of attribute same.



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

def same
  @same
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#commits_over_limit?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gitlab_git/compare.rb', line 55

def commits_over_limit?
  commits.size > limit
end

#empty_diff?Boolean

Check if diff is empty because it is actually empty and not because its impossible to get it

Returns:

  • (Boolean)


51
52
53
# File 'lib/gitlab_git/compare.rb', line 51

def empty_diff?
  diffs.empty? && timeout == false && commits.size < limit
end