summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-06 15:14:29 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-04-06 15:14:29 +0000
commitfd82264391c9408d4074e2a446aa9ff45c705919 (patch)
tree6a363d7264a9aaf0c5b060812acbfbc29905d742 /lib
parentc3af43c3d263278bd39917c37a87022f8dc44e95 (diff)
parent70982bb420ad69e354db9b6999feed4e4fab9dc1 (diff)
downloadgitlab-ce-fd82264391c9408d4074e2a446aa9ff45c705919.tar.gz
Merge branch 'use-gitaly-find-ref-name' into 'master'
Use Gitaly for Environment#first_deployment_for See merge request !10294
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb15
-rw-r--r--lib/gitlab/gitaly_client/ref.rb10
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 2e4314932c8..9e338282e96 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -452,6 +452,21 @@ module Gitlab
Gitlab::Git::DiffCollection.new(diff_patches(from, to, options, *paths), options)
end
+ # Returns a RefName for a given SHA
+ def ref_name_for_sha(ref_path, sha)
+ Gitlab::GitalyClient.migrate(:find_ref_name) do |is_enabled|
+ if is_enabled
+ gitaly_ref_client.find_ref_name(sha, ref_path)
+ else
+ args = %W(#{Gitlab.config.git.bin_path} for-each-ref --count=1 #{ref_path} --contains #{sha})
+
+ # Not found -> ["", 0]
+ # Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
+ Gitlab::Popen.popen(args, @path).first.split.last
+ end
+ end
+ end
+
# Returns commits collection
#
# Ex.
diff --git a/lib/gitlab/gitaly_client/ref.rb b/lib/gitlab/gitaly_client/ref.rb
index bfc5fa573c7..4958d00c542 100644
--- a/lib/gitlab/gitaly_client/ref.rb
+++ b/lib/gitlab/gitaly_client/ref.rb
@@ -23,6 +23,16 @@ module Gitlab
consume_refs_response(stub.find_all_tag_names(request), prefix: 'refs/tags/')
end
+ def find_ref_name(commit_id, ref_prefix)
+ request = Gitaly::FindRefNameRequest.new(
+ repository: @repository,
+ commit_id: commit_id,
+ prefix: ref_prefix
+ )
+
+ stub.find_ref_name(request).name
+ end
+
private
def consume_refs_response(response, prefix:)