2017-09-10 17:25:29 +05:30
|
|
|
# Gitaly note: JV: 1 RPC, migration in progress.
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
@additions = 0
|
|
|
|
@deletions = 0
|
|
|
|
@total = 0
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
repo.gitaly_migrate(:commit_stats) do |is_enabled|
|
|
|
|
if is_enabled
|
|
|
|
gitaly_stats(repo, commit)
|
|
|
|
else
|
|
|
|
rugged_stats(commit)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def gitaly_stats(repo, commit)
|
|
|
|
stats = repo.gitaly_commit_client.commit_stats(@id)
|
|
|
|
@additions = stats.additions
|
|
|
|
@deletions = stats.deletions
|
|
|
|
@total = @additions + @deletions
|
|
|
|
end
|
|
|
|
|
|
|
|
def rugged_stats(commit)
|
|
|
|
diff = commit.rugged_diff_from_parent
|
|
|
|
_files_changed, @additions, @deletions = diff.stat
|
|
|
|
@total = @additions + @deletions
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|