Commit a64760d6 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'gitaly-404-commit-list-files' into 'master'

Migrate `Git::Repository.ls_files` to Gitaly

Closes gitaly#404

See merge request !13302
parents 2857ed5f 7b108850
...@@ -620,29 +620,13 @@ module Gitlab ...@@ -620,29 +620,13 @@ module Gitlab
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/327 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/327
def ls_files(ref) def ls_files(ref)
actual_ref = ref || root_ref gitaly_migrate(:ls_files) do |is_enabled|
if is_enabled
begin gitaly_ls_files(ref)
sha_from_ref(actual_ref) else
rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError git_ls_files(ref)
# Return an empty array if the ref wasn't found end
return []
end
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} ls-tree)
cmd += %w(-r)
cmd += %w(--full-tree)
cmd += %w(--full-name)
cmd += %W(-- #{actual_ref})
raw_output = IO.popen(cmd, &:read).split("\n").map do |f|
stuff, path = f.split("\t")
_mode, type, _sha = stuff.split(" ")
path if type == "blob"
# Contain only blob type
end end
raw_output.compact
end end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/328 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/328
...@@ -974,6 +958,36 @@ module Gitlab ...@@ -974,6 +958,36 @@ module Gitlab
raw_output.to_i raw_output.to_i
end end
def gitaly_ls_files(ref)
gitaly_commit_client.ls_files(ref)
end
def git_ls_files(ref)
actual_ref = ref || root_ref
begin
sha_from_ref(actual_ref)
rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError
# Return an empty array if the ref wasn't found
return []
end
cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} ls-tree)
cmd += %w(-r)
cmd += %w(--full-tree)
cmd += %w(--full-name)
cmd += %W(-- #{actual_ref})
raw_output = IO.popen(cmd, &:read).split("\n").map do |f|
stuff, path = f.split("\t")
_mode, type, _sha = stuff.split(" ")
path if type == "blob"
# Contain only blob type
end
raw_output.compact
end
end end
end end
end end
...@@ -10,6 +10,18 @@ module Gitlab ...@@ -10,6 +10,18 @@ module Gitlab
@repository = repository @repository = repository
end end
def ls_files(revision)
request = Gitaly::ListFilesRequest.new(
repository: @gitaly_repo,
revision: GitalyClient.encode(revision)
)
response = GitalyClient.call(@repository.storage, :commit_service, :list_files, request)
response.flat_map do |msg|
msg.paths.map { |d| d.dup.force_encoding(Encoding::UTF_8) }
end
end
def is_ancestor(ancestor_id, child_id) def is_ancestor(ancestor_id, child_id)
request = Gitaly::CommitIsAncestorRequest.new( request = Gitaly::CommitIsAncestorRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
......
...@@ -1002,7 +1002,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1002,7 +1002,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
expect(master_file_paths).to include("files/html/500.html") expect(master_file_paths).to include("files/html/500.html")
end end
it "dose not read submodule directory and empty directory of master branch" do it "does not read submodule directory and empty directory of master branch" do
expect(master_file_paths).not_to include("six") expect(master_file_paths).not_to include("six")
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