Skip to content
Snippets Groups Projects
Unverified Commit fd46d6ce authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg
Browse files

Remove intermediate methods on Branch and Tag classes

parent 73bd48de
No related branches found
No related tags found
No related merge requests found
module Gitlab
module Git
class Branch < Ref
class << self
def find(repo, branch_name)
if branch_name.is_a?(Gitlab::Git::Branch)
branch_name
else
repo.find_branch(branch_name)
end
end
def names_contains_sha(repo, sha, limit: 0)
GitalyClient::RefService.new(repo).branch_names_contains_sha(sha)
def self.find(repo, branch_name)
if branch_name.is_a?(Gitlab::Git::Branch)
branch_name
else
repo.find_branch(branch_name)
end
end
 
Loading
Loading
Loading
Loading
@@ -1358,7 +1358,7 @@ module Gitlab
def branch_names_contains_sha(sha)
gitaly_migrate(:branch_names_contains_sha) do |is_enabled|
if is_enabled
Gitlab::Git::Branch.names_contains_sha(self, sha)
gitaly_ref_client.branch_names_contains_sha(sha)
else
refs_contains_sha(:branch, sha)
end
Loading
Loading
@@ -1368,7 +1368,7 @@ module Gitlab
def tag_names_contains_sha(sha)
gitaly_migrate(:tag_names_contains_sha) do |is_enabled|
if is_enabled
Gitlab::Git::Tag.names_contains_sha(self, sha)
gitaly_ref_client.tag_names_contains_sha(sha)
else
refs_contains_sha(:tag, sha)
end
Loading
Loading
module Gitlab
module Git
class Tag < Ref
class << self
def names_contains_sha(repo, sha)
GitalyClient::RefService.new(repo).branch_names_contains_sha(sha)
end
end
attr_reader :object_sha
 
def initialize(repository, name, target, target_commit, message = nil)
Loading
Loading
Loading
Loading
@@ -146,7 +146,7 @@ module Gitlab
end
 
# Limit: 0 implies no limit, thus all tag names will be returned
def tag_names_containing(sha, limit: 0)
def tag_names_contains_sha(sha, limit: 0)
request = Gitaly::ListTagNamesContainingCommitRequest.new(
repository: @gitaly_repo,
commit_id: sha,
Loading
Loading
@@ -155,10 +155,7 @@ module Gitlab
 
stream = GitalyClient.call(@repository.storage, :ref_service, :list_tag_names_containing_commit, request)
 
stream.each_with_object([]) do |response, array|
encoded_names = response.tag_names.map { |t| Gitlab::Git.ref_name(t) }
array.concat(encoded_names)
end
consume_ref_contains_sha_response(stream, :tag_names)
end
 
# Limit: 0 implies no limit, thus all tag names will be returned
Loading
Loading
@@ -171,10 +168,7 @@ module Gitlab
 
stream = GitalyClient.call(@repository.storage, :ref_service, :list_branch_names_containing_commit, request)
 
stream.each_with_object([]) do |response, array|
encoded_names = response.branch_names.map { |b| Gitlab::Git.ref_name(b) }
array.concat(encoded_names)
end
consume_ref_contains_sha_response(stream, :branch_names)
end
 
private
Loading
Loading
@@ -247,6 +241,13 @@ module Gitlab
Gitlab::Git::Commit.decorate(@repository, hash)
end
 
def consume_ref_contains_sha_response(stream, collection_name)
stream.each_with_object([]) do |response, array|
encoded_names = response.send(collection_name).map { |b| Gitlab::Git.ref_name(b) } # rubocop:disable GitlabSecurity/PublicSend
array.concat(encoded_names)
end
end
def invalid_ref!(message)
raise Gitlab::Git::Repository::InvalidRef.new(message)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment