Commit e0195f33 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/migrate-recursive-tree-entries-fetching' into 'master'

Migrate recursive tree entries fetching to Gitaly

See merge request gitlab-org/gitlab-ce!17191
parents ab24a7b2 c370f53c
...@@ -411,7 +411,7 @@ group :ed25519 do ...@@ -411,7 +411,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.84.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.85.0', require: 'gitaly'
# Locked until https://github.com/google/protobuf/issues/4210 is closed # Locked until https://github.com/google/protobuf/issues/4210 is closed
gem 'google-protobuf', '= 3.5.1' gem 'google-protobuf', '= 3.5.1'
......
...@@ -285,7 +285,7 @@ GEM ...@@ -285,7 +285,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.84.0) gitaly-proto (0.85.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (5.3.3) github-linguist (5.3.3)
...@@ -1057,7 +1057,7 @@ DEPENDENCIES ...@@ -1057,7 +1057,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.84.0) gitaly-proto (~> 0.85.0)
github-linguist (~> 5.3.3) github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2) gitlab-markup (~> 1.6.2)
......
...@@ -9,10 +9,9 @@ class Tree ...@@ -9,10 +9,9 @@ class Tree
@repository = repository @repository = repository
@sha = sha @sha = sha
@path = path @path = path
@recursive = recursive
git_repo = @repository.raw_repository git_repo = @repository.raw_repository
@entries = get_entries(git_repo, @sha, @path, recursive: @recursive) @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path, recursive)
end end
def readme def readme
...@@ -58,21 +57,4 @@ class Tree ...@@ -58,21 +57,4 @@ class Tree
def sorted_entries def sorted_entries
trees + blobs + submodules trees + blobs + submodules
end end
private
def get_entries(git_repo, sha, path, recursive: false)
current_path_entries = Gitlab::Git::Tree.where(git_repo, sha, path)
ordered_entries = []
current_path_entries.each do |entry|
ordered_entries << entry
if recursive && entry.dir?
ordered_entries.concat(get_entries(git_repo, sha, entry.path, recursive: true))
end
end
ordered_entries
end
end end
...@@ -14,14 +14,14 @@ module Gitlab ...@@ -14,14 +14,14 @@ module Gitlab
# Uses rugged for raw objects # Uses rugged for raw objects
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/320 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/320
def where(repository, sha, path = nil) def where(repository, sha, path = nil, recursive = false)
path = nil if path == '' || path == '/' path = nil if path == '' || path == '/'
Gitlab::GitalyClient.migrate(:tree_entries) do |is_enabled| Gitlab::GitalyClient.migrate(:tree_entries) do |is_enabled|
if is_enabled if is_enabled
repository.gitaly_commit_client.tree_entries(repository, sha, path) repository.gitaly_commit_client.tree_entries(repository, sha, path, recursive)
else else
tree_entries_from_rugged(repository, sha, path) tree_entries_from_rugged(repository, sha, path, recursive)
end end
end end
end end
...@@ -57,7 +57,22 @@ module Gitlab ...@@ -57,7 +57,22 @@ module Gitlab
end end
end end
def tree_entries_from_rugged(repository, sha, path) def tree_entries_from_rugged(repository, sha, path, recursive)
current_path_entries = get_tree_entries_from_rugged(repository, sha, path)
ordered_entries = []
current_path_entries.each do |entry|
ordered_entries << entry
if recursive && entry.dir?
ordered_entries.concat(tree_entries_from_rugged(repository, sha, entry.path, true))
end
end
ordered_entries
end
def get_tree_entries_from_rugged(repository, sha, path)
commit = repository.lookup(sha) commit = repository.lookup(sha)
root_tree = commit.tree root_tree = commit.tree
......
...@@ -105,11 +105,12 @@ module Gitlab ...@@ -105,11 +105,12 @@ module Gitlab
entry unless entry.oid.blank? entry unless entry.oid.blank?
end end
def tree_entries(repository, revision, path) def tree_entries(repository, revision, path, recursive)
request = Gitaly::GetTreeEntriesRequest.new( request = Gitaly::GetTreeEntriesRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
revision: encode_binary(revision), revision: encode_binary(revision),
path: path.present? ? encode_binary(path) : '.' path: path.present? ? encode_binary(path) : '.',
recursive: recursive
) )
response = GitalyClient.call(@repository.storage, :commit_service, :get_tree_entries, request, timeout: GitalyClient.medium_timeout) response = GitalyClient.call(@repository.storage, :commit_service, :get_tree_entries, request, timeout: GitalyClient.medium_timeout)
......
...@@ -113,7 +113,7 @@ describe Gitlab::GitalyClient::CommitService do ...@@ -113,7 +113,7 @@ describe Gitlab::GitalyClient::CommitService do
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([]) .and_return([])
client.tree_entries(repository, revision, path) client.tree_entries(repository, revision, path, false)
end end
context 'with UTF-8 params strings' do context 'with UTF-8 params strings' do
...@@ -126,7 +126,7 @@ describe Gitlab::GitalyClient::CommitService do ...@@ -126,7 +126,7 @@ describe Gitlab::GitalyClient::CommitService do
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([]) .and_return([])
client.tree_entries(repository, revision, path) client.tree_entries(repository, revision, path, false)
end end
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