Migrate Git::Repository.ls_files to Gitaly
This commit is contained in:
parent
932a6e69b8
commit
7b10885046
|
@ -603,29 +603,13 @@ module Gitlab
|
|||
#
|
||||
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/327
|
||||
def 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 []
|
||||
gitaly_migrate(:ls_files) do |is_enabled|
|
||||
if is_enabled
|
||||
gitaly_ls_files(ref)
|
||||
else
|
||||
git_ls_files(ref)
|
||||
end
|
||||
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
|
||||
|
||||
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/328
|
||||
|
@ -973,6 +957,36 @@ module Gitlab
|
|||
|
||||
raw_output.to_i
|
||||
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
|
||||
|
|
|
@ -10,6 +10,18 @@ module Gitlab
|
|||
@repository = repository
|
||||
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)
|
||||
request = Gitaly::CommitIsAncestorRequest.new(
|
||||
repository: @gitaly_repo,
|
||||
|
|
|
@ -1002,7 +1002,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
|
|||
expect(master_file_paths).to include("files/html/500.html")
|
||||
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")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue