BigW Consortium Gitlab

Commit 25c34608 by Kim "BKC" Carlbäcker

Migrate Git::CommitStats to Gitaly

parent de14e9c2
...@@ -352,7 +352,7 @@ module Gitlab ...@@ -352,7 +352,7 @@ module Gitlab
end end
def stats def stats
Gitlab::Git::CommitStats.new(self) Gitlab::Git::CommitStats.new(@repository, self)
end end
def to_patch(options = {}) def to_patch(options = {})
......
...@@ -10,12 +10,29 @@ module Gitlab ...@@ -10,12 +10,29 @@ module Gitlab
# Instantiate a CommitStats object # Instantiate a CommitStats object
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
def initialize(commit) def initialize(repo, commit)
@id = commit.id @id = commit.id
@additions = 0 @additions = 0
@deletions = 0 @deletions = 0
@total = 0 @total = 0
repo.gitaly_migrate(:commit_stats) do |is_enabled|
if is_enabled
gitaly_stats(repo, commit)
else
rugged_stats(commit)
end
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
def rugged_stats(commit)
diff = commit.rugged_diff_from_parent diff = commit.rugged_diff_from_parent
diff.each_patch do |p| diff.each_patch do |p|
......
...@@ -204,6 +204,14 @@ module Gitlab ...@@ -204,6 +204,14 @@ module Gitlab
response.sum(&:data) response.sum(&:data)
end end
def commit_stats(revision)
request = Gitaly::CommitStatsRequest.new(
repository: @gitaly_repo,
revision: GitalyClient.encode(revision)
)
GitalyClient.call(@repository.storage, :commit_service, :commit_stats, request)
end
private private
def commit_diff_request_params(commit, options = {}) def commit_diff_request_params(commit, options = {})
......
...@@ -401,7 +401,7 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -401,7 +401,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
end end
describe '#stats' do shared_examples '#stats' do
subject { commit.stats } subject { commit.stats }
describe '#additions' do describe '#additions' do
...@@ -415,6 +415,14 @@ describe Gitlab::Git::Commit, seed_helper: true do ...@@ -415,6 +415,14 @@ describe Gitlab::Git::Commit, seed_helper: true do
end end
end end
describe '#stats with gitaly on' do
it_should_behave_like '#stats'
end
describe '#stats with gitaly disabled', skip_gitaly_mock: true do
it_should_behave_like '#stats'
end
describe '#to_diff' do describe '#to_diff' do
subject { commit.to_diff } subject { commit.to_diff }
......
...@@ -165,4 +165,29 @@ describe Gitlab::GitalyClient::CommitService do ...@@ -165,4 +165,29 @@ describe Gitlab::GitalyClient::CommitService do
expect(subject).to eq("my diff") expect(subject).to eq("my diff")
end end
end end
describe '#commit_stats' do
let(:request) do
Gitaly::CommitStatsRequest.new(
repository: repository_message, revision: revision
)
end
let(:response) do
Gitaly::CommitStatsResponse.new(
oid: revision,
additions: 11,
deletions: 15
)
end
subject { described_class.new(repository).commit_stats(revision) }
it 'sends an RPC request' do
expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:commit_stats)
.with(request, kind_of(Hash)).and_return(response)
expect(subject.additions).to eq(11)
expect(subject.deletions).to eq(15)
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment