Class: Gitlab::Git::GitStats

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_git/git_stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, ref, timeout = 30) ⇒ GitStats

Returns a new instance of GitStats.



8
9
10
# File 'lib/gitlab_git/git_stats.rb', line 8

def initialize(repo, ref, timeout = 30)
  @repo, @ref, @timeout = repo, ref, timeout
end

Instance Attribute Details

#refObject

Returns the value of attribute ref.



6
7
8
# File 'lib/gitlab_git/git_stats.rb', line 6

def ref
  @ref
end

#repoObject

Returns the value of attribute repo.



6
7
8
# File 'lib/gitlab_git/git_stats.rb', line 6

def repo
  @repo
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/gitlab_git/git_stats.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#logObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab_git/git_stats.rb', line 12

def log
  log = nil
  Grit::Git.with_timeout(timeout) do
    # Limit log to 6k commits to avoid timeout for huge projects
    args = [ref, '-6000', '--format=%aN%x0a%aE%x0a%cd', '--date=short', '--shortstat', '--no-merges', '--diff-filter=ACDM']
    log = repo.git.native(:log, {}, args)
  end

  log
rescue Grit::Git::GitTimeout
  nil
end

#parsed_logObject



25
26
27
# File 'lib/gitlab_git/git_stats.rb', line 25

def parsed_log
  LogParser.parse_log(log)
end