summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-08-04 15:46:36 +0000
committerRobert Speicher <robert@gitlab.com>2017-08-04 15:46:36 +0000
commite299d595c790c355eff9d3719dce824e8380f983 (patch)
tree2c9de74e60a92e05eb0986146007c216575157f9 /app
parent7e45159f0d8b2e0b6963f40f1a2a54ec1171a2c0 (diff)
parentf81c07eacc6c37092b13559dcaf479805138eb45 (diff)
downloadgitlab-ce-e299d595c790c355eff9d3719dce824e8380f983.tar.gz
Merge branch 'feature/migrate-last-commit-for-path-to-gitaly' into 'master'
Migrate Repository#last_commit_for_path to Gitaly Closes gitaly#433 See merge request !13200
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb34
1 files changed, 29 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 4e9fe759fdc..2dd48290e58 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -613,17 +613,26 @@ class Repository
end
def last_commit_for_path(sha, path)
- sha = last_commit_id_for_path(sha, path)
- commit(sha)
+ raw_repository.gitaly_migrate(:last_commit_for_path) do |is_enabled|
+ if is_enabled
+ last_commit_for_path_by_gitaly(sha, path)
+ else
+ last_commit_for_path_by_rugged(sha, path)
+ end
+ end
end
- # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/383
def last_commit_id_for_path(sha, path)
key = path.blank? ? "last_commit_id_for_path:#{sha}" : "last_commit_id_for_path:#{sha}:#{Digest::SHA1.hexdigest(path)}"
cache.fetch(key) do
- args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path})
- Gitlab::Popen.popen(args, path_to_repo).first.strip
+ raw_repository.gitaly_migrate(:last_commit_for_path) do |is_enabled|
+ if is_enabled
+ last_commit_for_path_by_gitaly(sha, path).id
+ else
+ last_commit_id_for_path_by_shelling_out(sha, path)
+ end
+ end
end
end
@@ -1138,6 +1147,21 @@ class Repository
Rugged::Commit.create(rugged, params)
end
+ def last_commit_for_path_by_gitaly(sha, path)
+ c = raw_repository.gitaly_commit_client.last_commit_for_path(sha, path)
+ commit(c)
+ end
+
+ def last_commit_for_path_by_rugged(sha, path)
+ sha = last_commit_id_for_path_by_shelling_out(sha, path)
+ commit(sha)
+ end
+
+ def last_commit_id_for_path_by_shelling_out(sha, path)
+ args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path})
+ Gitlab::Popen.popen(args, path_to_repo).first.strip
+ end
+
def repository_storage_path
@project.repository_storage_path
end