ebf98f27c4
Enables frozen string for the following: * lib/gitlab/fogbugz_import/**/*.rb * lib/gitlab/gfm/**/*.rb * lib/gitlab/git/**/*.rb * lib/gitlab/gitaly_client/**/*.rb * lib/gitlab/gitlab_import/**/*.rb * lib/gitlab/google_code_import/**/*.rb * lib/gitlab/gpg/**/*.rb * lib/gitlab/grape_logging/**/*.rb * lib/gitlab/graphql/**/*.rb * lib/gitlab/graphs/**/*.rb * lib/gitlab/hashed_storage/**/*.rb * lib/gitlab/health_checks/**/*.rb Partially address gitlab-org/gitlab-ce#47424.
34 lines
855 B
Ruby
34 lines
855 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Gitlab::Git::CommitStats counts the additions, deletions, and total changes
|
|
# in a commit.
|
|
module Gitlab
|
|
module Git
|
|
class CommitStats
|
|
include Gitlab::Git::WrapsGitalyErrors
|
|
|
|
attr_reader :id, :additions, :deletions, :total
|
|
|
|
# Instantiate a CommitStats object
|
|
#
|
|
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
|
|
def initialize(repo, commit)
|
|
@id = commit.id
|
|
@additions = 0
|
|
@deletions = 0
|
|
@total = 0
|
|
|
|
wrapped_gitaly_errors do
|
|
gitaly_stats(repo, commit)
|
|
end
|
|
end
|
|
|
|
def gitaly_stats(repo, commit)
|
|
stats = repo.gitaly_commit_client.commit_stats(@id)
|
|
@additions = stats.additions
|
|
@deletions = stats.deletions
|
|
@total = @additions + @deletions
|
|
end
|
|
end
|
|
end
|
|
end
|