2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Gitlab::Git::CommitStats counts the additions, deletions, and total changes
|
|
|
|
# in a commit.
|
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class CommitStats
|
2018-12-13 13:39:08 +05:30
|
|
|
include Gitlab::Git::WrapsGitalyErrors
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
attr_reader :id, :additions, :deletions, :total
|
|
|
|
|
|
|
|
# Instantiate a CommitStats object
|
2017-09-10 17:25:29 +05:30
|
|
|
#
|
|
|
|
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
|
2018-03-17 18:26:18 +05:30
|
|
|
def initialize(repo, commit)
|
2017-08-17 22:00:37 +05:30
|
|
|
@id = commit.id
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
additions, deletions = fetch_stats(repo, commit)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
@additions = additions.to_i
|
|
|
|
@deletions = deletions.to_i
|
2018-03-17 18:26:18 +05:30
|
|
|
@total = @additions + @deletions
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
def fetch_stats(repo, commit)
|
|
|
|
Rails.cache.fetch("commit_stats:#{repo.gl_project_path}:#{@id}") do
|
|
|
|
stats = wrapped_gitaly_errors do
|
|
|
|
repo.gitaly_commit_client.commit_stats(@id)
|
|
|
|
end
|
|
|
|
|
|
|
|
[stats.additions, stats.deletions]
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|