Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
commit0c872e02b2c822e3397515ec324051ff540f0cd5 (patch)
treece2fb6ce7030e4dad0f4118d21ab6453e5938cdd /lib/gitlab/git
parentf7e05a6853b12f02911494c4b3fe53d9540d74fc (diff)
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/base_error.rb46
-rw-r--r--lib/gitlab/git/cross_repo.rb (renamed from lib/gitlab/git/cross_repo_comparer.rb)13
-rw-r--r--lib/gitlab/git/repository.rb41
3 files changed, 67 insertions, 33 deletions
diff --git a/lib/gitlab/git/base_error.rb b/lib/gitlab/git/base_error.rb
index a7eaa82b347..0b0fdef54cc 100644
--- a/lib/gitlab/git/base_error.rb
+++ b/lib/gitlab/git/base_error.rb
@@ -1,20 +1,50 @@
# frozen_string_literal: true
+require 'grpc'
module Gitlab
module Git
class BaseError < StandardError
DEBUG_ERROR_STRING_REGEX = /(.*?) debug_error_string:.*$/m.freeze
+ GRPC_CODES = {
+ '0' => 'ok',
+ '1' => 'cancelled',
+ '2' => 'unknown',
+ '3' => 'invalid_argument',
+ '4' => 'deadline_exceeded',
+ '5' => 'not_found',
+ '6' => 'already_exists',
+ '7' => 'permission_denied',
+ '8' => 'resource_exhausted',
+ '9' => 'failed_precondition',
+ '10' => 'aborted',
+ '11' => 'out_of_range',
+ '12' => 'unimplemented',
+ '13' => 'internal',
+ '14' => 'unavailable',
+ '15' => 'data_loss',
+ '16' => 'unauthenticated'
+ }.freeze
+
+ attr_reader :status, :code, :service
def initialize(msg = nil)
- if msg
- raw_message = msg.to_s
- match = DEBUG_ERROR_STRING_REGEX.match(raw_message)
- raw_message = match[1] if match
+ super && return if msg.nil?
+
+ set_grpc_error_code(msg) if msg.is_a?(::GRPC::BadStatus)
+
+ super(build_raw_message(msg))
+ end
+
+ def build_raw_message(message)
+ raw_message = message.to_s
+ match = DEBUG_ERROR_STRING_REGEX.match(raw_message)
+ match ? match[1] : raw_message
+ end
- super(raw_message)
- else
- super
- end
+ def set_grpc_error_code(grpc_error)
+ @status = grpc_error.code
+ @code = GRPC_CODES[@status.to_s]
+ @service = 'git'
end
end
end
diff --git a/lib/gitlab/git/cross_repo_comparer.rb b/lib/gitlab/git/cross_repo.rb
index d42b2a3bd98..d44657e7db1 100644
--- a/lib/gitlab/git/cross_repo_comparer.rb
+++ b/lib/gitlab/git/cross_repo.rb
@@ -2,7 +2,7 @@
module Gitlab
module Git
- class CrossRepoComparer
+ class CrossRepo
attr_reader :source_repo, :target_repo
def initialize(source_repo, target_repo)
@@ -10,15 +10,8 @@ module Gitlab
@target_repo = target_repo
end
- def compare(source_ref, target_ref, straight:)
- ensuring_ref_in_source(target_ref) do |target_commit_id|
- Gitlab::Git::Compare.new(
- source_repo,
- target_commit_id,
- source_ref,
- straight: straight
- )
- end
+ def execute(target_ref, &blk)
+ ensuring_ref_in_source(target_ref, &blk)
end
private
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 3b5151ef4f2..2f9cfe3e764 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -116,9 +116,9 @@ module Gitlab
# Returns an Array of branch names
# sorted by name ASC
def branch_names
- wrapped_gitaly_errors do
- gitaly_ref_client.branch_names
- end
+ refs = list_refs([Gitlab::Git::BRANCH_REF_PREFIX])
+
+ refs.map { |ref| Gitlab::Git.branch_name(ref.name) }
end
# Returns an Array of Branches
@@ -134,6 +134,10 @@ module Gitlab
wrapped_gitaly_errors do
gitaly_ref_client.find_branch(name)
end
+ rescue Gitlab::Git::AmbiguousRef
+ # Gitaly returns "reference is ambiguous" error in case when users request
+ # branch "my-branch", when another branch "my-branch/branch" exists.
+ # We handle this error here and return nil for this case.
end
def find_tag(name)
@@ -158,9 +162,7 @@ module Gitlab
# Returns the number of valid branches
def branch_count
- wrapped_gitaly_errors do
- gitaly_ref_client.count_branch_names
- end
+ branch_names.count
end
def rename(new_relative_path)
@@ -202,16 +204,14 @@ module Gitlab
# Returns the number of valid tags
def tag_count
- wrapped_gitaly_errors do
- gitaly_ref_client.count_tag_names
- end
+ tag_names.count
end
# Returns an Array of tag names
def tag_names
- wrapped_gitaly_errors do
- gitaly_ref_client.tag_names
- end
+ refs = list_refs([Gitlab::Git::TAG_REF_PREFIX])
+
+ refs.map { |ref| Gitlab::Git.tag_name(ref.name) }
end
# Returns an Array of Tags
@@ -385,6 +385,12 @@ module Gitlab
end
end
+ def check_objects_exist(refs)
+ wrapped_gitaly_errors do
+ gitaly_commit_client.object_existence_map(Array.wrap(refs))
+ end
+ end
+
def new_blobs(newrevs, dynamic_timeout: nil)
newrevs = Array.wrap(newrevs).reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA }
return [] if newrevs.empty?
@@ -823,9 +829,14 @@ module Gitlab
end
def compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:)
- CrossRepoComparer
- .new(source_repository, self)
- .compare(source_branch_name, target_branch_name, straight: straight)
+ CrossRepo.new(source_repository, self).execute(target_branch_name) do |target_commit_id|
+ Gitlab::Git::Compare.new(
+ source_repository,
+ target_commit_id,
+ source_branch_name,
+ straight: straight
+ )
+ end
end
def write_ref(ref_path, ref, old_ref: nil)