diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-09-27 13:29:56 +0200 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2016-09-28 10:37:53 -0500 |
commit | 16518f6a377385c1d635049ba9601cd7ed2a68bc (patch) | |
tree | b8756a277c5f74e09bd72edccc60596f0668f428 /app | |
parent | 57837fd1ca96532e8e2ac0f3260dc3c028aebbb0 (diff) | |
download | gitlab-ce-16518f6a377385c1d635049ba9601cd7ed2a68bc.tar.gz |
Merge branch '22578-cycle-analytics-incorrect-commit-count'
Diffstat (limited to 'app')
-rw-r--r-- | app/models/cycle_analytics/summary.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/app/models/cycle_analytics/summary.rb b/app/models/cycle_analytics/summary.rb index 53b2cacb131..b46db449bf3 100644 --- a/app/models/cycle_analytics/summary.rb +++ b/app/models/cycle_analytics/summary.rb @@ -10,15 +10,33 @@ class CycleAnalytics end def commits - repository = @project.repository.raw_repository - - if @project.default_branch - repository.log(ref: @project.default_branch, after: @from).count - end + ref = @project.default_branch.presence + count_commits_for(ref) end def deploys @project.deployments.where("created_at > ?", @from).count end + + private + + # Don't use the `Gitlab::Git::Repository#log` method, because it enforces + # a limit. Since we need a commit count, we _can't_ enforce a limit, so + # the easiest way forward is to replicate the relevant portions of the + # `log` function here. + def count_commits_for(ref) + return unless ref + + repository = @project.repository.raw_repository + sha = @project.repository.commit(ref).sha + + cmd = %W(git --git-dir=#{repository.path} log) + cmd << '--format=%H' + cmd << "--after=#{@from.iso8601}" + cmd << sha + + raw_output = IO.popen(cmd) { |io| io.read } + raw_output.lines.count + end end end |