summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-07-07 15:21:05 +0000
committerRobert Speicher <robert@gitlab.com>2017-07-07 15:21:05 +0000
commit1dab640357fa1ba8992757499e4167fcd4ce6276 (patch)
treeded95743dee788d563abeb0c9638679ef0dfd879 /lib
parenta77158ff31d84bf978038e5c3c7aec3faa509035 (diff)
parentc393d88df3b815bf6cbfad37ef20b8e70313563d (diff)
downloadgitlab-ce-1dab640357fa1ba8992757499e4167fcd4ce6276.tar.gz
Merge branch 'feature/migrate-commit-count-to-gitaly' into 'master'
Migrate Gitlab::Git::Repository#commit_count to Gitaly Closes gitaly#355 See merge request !12688
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb16
-rw-r--r--lib/gitlab/gitaly_client/commit.rb9
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index dd5a4d5ad55..e51966313d4 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -568,11 +568,17 @@ module Gitlab
# Return total commits count accessible from passed ref
def commit_count(ref)
- walker = Rugged::Walker.new(rugged)
- walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
- oid = rugged.rev_parse_oid(ref)
- walker.push(oid)
- walker.count
+ gitaly_migrate(:commit_count) do |is_enabled|
+ if is_enabled
+ gitaly_commit_client.commit_count(ref)
+ else
+ walker = Rugged::Walker.new(rugged)
+ walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
+ oid = rugged.rev_parse_oid(ref)
+ walker.push(oid)
+ walker.count
+ end
+ end
end
# Sets HEAD to the commit specified by +ref+; +ref+ can be a branch or
diff --git a/lib/gitlab/gitaly_client/commit.rb b/lib/gitlab/gitaly_client/commit.rb
index b8877619797..aafc0520664 100644
--- a/lib/gitlab/gitaly_client/commit.rb
+++ b/lib/gitlab/gitaly_client/commit.rb
@@ -56,6 +56,15 @@ module Gitlab
entry
end
+ def commit_count(ref)
+ request = Gitaly::CountCommitsRequest.new(
+ repository: @gitaly_repo,
+ revision: ref
+ )
+
+ GitalyClient.call(@repository.storage, :commit_service, :count_commits, request).count
+ end
+
private
def commit_diff_request_params(commit, options = {})