summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-08-14 15:44:36 +0000
committerDouwe Maan <douwe@gitlab.com>2017-08-14 15:44:36 +0000
commita64760d6d0a9bc0ce0747de349d37f3c46a1c221 (patch)
treeef418c4bf1c6edd55a688f5ca8abc6e665fbf5a1
parent2857ed5f68dcd02f20e006180de39263e14a6e36 (diff)
parent7b10885046137633fa615ed5d6ba29d4d0d09cd7 (diff)
downloadgitlab-ce-a64760d6d0a9bc0ce0747de349d37f3c46a1c221.tar.gz
Merge branch 'gitaly-404-commit-list-files' into 'master'
Migrate `Git::Repository.ls_files` to Gitaly Closes gitaly#404 See merge request !13302
-rw-r--r--lib/gitlab/git/repository.rb58
-rw-r--r--lib/gitlab/gitaly_client/commit_service.rb12
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb2
3 files changed, 49 insertions, 23 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 7000b173075..afe4fb58ad0 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -620,29 +620,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 []
- 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
+ gitaly_migrate(:ls_files) do |is_enabled|
+ if is_enabled
+ gitaly_ls_files(ref)
+ else
+ git_ls_files(ref)
+ end
end
-
- raw_output.compact
end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/328
@@ -974,6 +958,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
diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb
index 692d7e02eef..93268d9f33c 100644
--- a/lib/gitlab/gitaly_client/commit_service.rb
+++ b/lib/gitlab/gitaly_client/commit_service.rb
@@ -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,
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 04c86a2c1a7..8d24d6f55b8 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -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