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>2023-11-02 21:12:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-11-02 21:12:04 +0300
commiteed7260f13c0a3139876e3659603f3d803e8fcd7 (patch)
treef877bb301ff936d73516241ad608271bc5a624fd /lib/gitlab
parentef211f6aff22891e232a700b61d2d3bf567ed6bf (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/config_checker/puma_rugged_checker.rb28
-rw-r--r--lib/gitlab/git/blob.rb2
-rw-r--r--lib/gitlab/git/commit.rb3
-rw-r--r--lib/gitlab/git/ref.rb1
-rw-r--r--lib/gitlab/git/repository.rb1
-rw-r--r--lib/gitlab/git/rugged_impl/blob.rb107
-rw-r--r--lib/gitlab/git/rugged_impl/commit.rb115
-rw-r--r--lib/gitlab/git/rugged_impl/ref.rb20
-rw-r--r--lib/gitlab/git/rugged_impl/repository.rb79
-rw-r--r--lib/gitlab/git/rugged_impl/tree.rb147
-rw-r--r--lib/gitlab/git/rugged_impl/use_rugged.rb50
-rw-r--r--lib/gitlab/git/tree.rb5
-rw-r--r--lib/gitlab/gitaly_client/storage_settings.rb8
13 files changed, 0 insertions, 566 deletions
diff --git a/lib/gitlab/config_checker/puma_rugged_checker.rb b/lib/gitlab/config_checker/puma_rugged_checker.rb
deleted file mode 100644
index 82c59f3328b..00000000000
--- a/lib/gitlab/config_checker/puma_rugged_checker.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module ConfigChecker
- module PumaRuggedChecker
- extend self
- extend Gitlab::Git::RuggedImpl::UseRugged
-
- def check
- notices = []
-
- if running_puma_with_multiple_threads? && rugged_enabled_through_feature_flag?
- link_start = '<a href="https://docs.gitlab.com/ee/administration/operations/puma.html#performance-caveat-when-using-puma-with-rugged">'
- link_end = '</a>'
- notices << {
- type: 'warning',
- message: _('Puma is running with a thread count above 1 and the Rugged '\
- 'service is enabled. This may decrease performance in some environments. '\
- 'See our %{link_start}documentation%{link_end} '\
- 'for details of this issue.') % { link_start: link_start, link_end: link_end }
- }
- end
-
- notices
- end
- end
- end
-end
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb
index ae90291c0a3..3744c81f51d 100644
--- a/lib/gitlab/git/blob.rb
+++ b/lib/gitlab/git/blob.rb
@@ -230,5 +230,3 @@ module Gitlab
end
end
end
-
-Gitlab::Git::Blob.singleton_class.prepend Gitlab::Git::RuggedImpl::Blob::ClassMethods
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb
index 571dde6fcfc..1086ea45a7a 100644
--- a/lib/gitlab/git/commit.rb
+++ b/lib/gitlab/git/commit.rb
@@ -5,7 +5,6 @@ module Gitlab
module Git
class Commit
include Gitlab::EncodingHelper
- prepend Gitlab::Git::RuggedImpl::Commit
extend Gitlab::Git::WrapsGitalyErrors
include Gitlab::Utils::StrongMemoize
@@ -502,5 +501,3 @@ module Gitlab
end
end
end
-
-Gitlab::Git::Commit.singleton_class.prepend Gitlab::Git::RuggedImpl::Commit::ClassMethods
diff --git a/lib/gitlab/git/ref.rb b/lib/gitlab/git/ref.rb
index 4a09f866db4..205dd5be35a 100644
--- a/lib/gitlab/git/ref.rb
+++ b/lib/gitlab/git/ref.rb
@@ -4,7 +4,6 @@ module Gitlab
module Git
class Ref
include Gitlab::EncodingHelper
- include Gitlab::Git::RuggedImpl::Ref
# Branch or tag name
# without "refs/tags|heads" prefix
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index a98cf95edf4..db6e6b4d00b 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -11,7 +11,6 @@ module Gitlab
include Gitlab::Git::WrapsGitalyErrors
include Gitlab::EncodingHelper
include Gitlab::Utils::StrongMemoize
- prepend Gitlab::Git::RuggedImpl::Repository
SEARCH_CONTEXT_LINES = 3
REV_LIST_COMMIT_LIMIT = 2_000
diff --git a/lib/gitlab/git/rugged_impl/blob.rb b/lib/gitlab/git/rugged_impl/blob.rb
deleted file mode 100644
index dc869ff5279..00000000000
--- a/lib/gitlab/git/rugged_impl/blob.rb
+++ /dev/null
@@ -1,107 +0,0 @@
-# frozen_string_literal: true
-
-# NOTE: This code is legacy. Do not add/modify code here unless you have
-# discussed with the Gitaly team. See
-# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
-# for more details.
-
-module Gitlab
- module Git
- module RuggedImpl
- module Blob
- module ClassMethods
- extend ::Gitlab::Utils::Override
- include Gitlab::Git::RuggedImpl::UseRugged
-
- override :tree_entry
- def tree_entry(repository, sha, path, limit)
- if use_rugged?(repository, :rugged_tree_entry)
- execute_rugged_call(:rugged_tree_entry, repository, sha, path, limit)
- else
- super
- end
- end
-
- private
-
- def rugged_tree_entry(repository, sha, path, limit)
- return unless path
-
- # Strip any leading / characters from the path
- path = path.sub(%r{\A/*}, '')
-
- rugged_commit = repository.lookup(sha)
- root_tree = rugged_commit.tree
-
- blob_entry = find_entry_by_path(repository, root_tree.oid, *path.split('/'))
-
- return unless blob_entry
-
- if blob_entry[:type] == :commit
- submodule_blob(blob_entry, path, sha)
- else
- blob = repository.lookup(blob_entry[:oid])
-
- if blob
- new(
- id: blob.oid,
- name: blob_entry[:name],
- size: blob.size,
- # Rugged::Blob#content is expensive; don't call it if we don't have to.
- data: limit == 0 ? '' : blob.content(limit),
- mode: blob_entry[:filemode].to_s(8),
- path: path,
- commit_id: sha,
- binary: blob.binary?
- )
- end
- end
- rescue Rugged::ReferenceError
- nil
- end
-
- # Recursive search of blob id by path
- #
- # Ex.
- # blog/ # oid: 1a
- # app/ # oid: 2a
- # models/ # oid: 3a
- # file.rb # oid: 4a
- #
- #
- # Blob.find_entry_by_path(repo, '1a', 'blog', 'app', 'file.rb') # => '4a'
- #
- def find_entry_by_path(repository, root_id, *path_parts)
- root_tree = repository.lookup(root_id)
-
- entry = root_tree.find do |entry|
- entry[:name] == path_parts[0]
- end
-
- return unless entry
-
- if path_parts.size > 1
- return unless entry[:type] == :tree
-
- path_parts.shift
- find_entry_by_path(repository, entry[:oid], *path_parts)
- else
- [:blob, :commit].include?(entry[:type]) ? entry : nil
- end
- end
-
- def submodule_blob(blob_entry, path, sha)
- new(
- id: blob_entry[:oid],
- name: blob_entry[:name],
- size: 0,
- data: '',
- path: path,
- commit_id: sha
- )
- end
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/git/rugged_impl/commit.rb b/lib/gitlab/git/rugged_impl/commit.rb
deleted file mode 100644
index cf547414b0d..00000000000
--- a/lib/gitlab/git/rugged_impl/commit.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-# frozen_string_literal: true
-
-# NOTE: This code is legacy. Do not add/modify code here unless you have
-# discussed with the Gitaly team. See
-# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
-# for more details.
-
-# rubocop:disable Gitlab/ModuleWithInstanceVariables
-module Gitlab
- module Git
- module RuggedImpl
- module Commit
- module ClassMethods
- extend ::Gitlab::Utils::Override
- include Gitlab::Git::RuggedImpl::UseRugged
-
- def rugged_find(repo, commit_id)
- obj = repo.rev_parse_target(commit_id)
-
- obj.is_a?(::Rugged::Commit) ? obj : nil
- rescue ::Rugged::Error
- nil
- end
-
- # This needs to return an array of Gitlab::Git:Commit objects
- # instead of Rugged::Commit objects to ensure upstream models
- # operate on a consistent interface. Unlike
- # Gitlab::Git::Commit.find, Gitlab::Git::Commit.batch_by_oid
- # doesn't attempt to decorate the result.
- def rugged_batch_by_oid(repo, oids)
- oids.map { |oid| rugged_find(repo, oid) }
- .compact
- .map { |commit| decorate(repo, commit) }
- # Match Gitaly's list_commits_by_oid behavior
- rescue ::Gitlab::Git::Repository::NoRepository
- []
- end
-
- override :find_commit
- def find_commit(repo, commit_id)
- if use_rugged?(repo, :rugged_find_commit)
- execute_rugged_call(:rugged_find, repo, commit_id)
- else
- super
- end
- end
-
- override :batch_by_oid
- def batch_by_oid(repo, oids)
- if use_rugged?(repo, :rugged_list_commits_by_oid)
- execute_rugged_call(:rugged_batch_by_oid, repo, oids)
- else
- super
- end
- end
- end
-
- extend ::Gitlab::Utils::Override
- include Gitlab::Git::RuggedImpl::UseRugged
-
- override :init_commit
- def init_commit(raw_commit)
- case raw_commit
- when ::Rugged::Commit
- init_from_rugged(raw_commit)
- else
- super
- end
- end
-
- override :commit_tree_entry
- def commit_tree_entry(path)
- if use_rugged?(@repository, :rugged_commit_tree_entry)
- execute_rugged_call(:rugged_tree_entry, path)
- else
- super
- end
- end
-
- # Is this the same as Blob.find_entry_by_path ?
- def rugged_tree_entry(path)
- rugged_commit.tree.path(path)
- rescue Rugged::TreeError
- nil
- end
-
- def rugged_commit
- @rugged_commit ||= if raw_commit.is_a?(Rugged::Commit)
- raw_commit
- else
- @repository.rev_parse_target(id)
- end
- end
-
- def init_from_rugged(commit)
- author = commit.author
- committer = commit.committer
-
- @raw_commit = commit
- @id = commit.oid
- @message = commit.message
- @authored_date = author[:time]
- @committed_date = committer[:time]
- @author_name = author[:name]
- @author_email = author[:email]
- @committer_name = committer[:name]
- @committer_email = committer[:email]
- @parent_ids = commit.parents.map(&:oid)
- @trailers = Hash[commit.trailers]
- end
- end
- end
- end
-end
-# rubocop:enable Gitlab/ModuleWithInstanceVariables
diff --git a/lib/gitlab/git/rugged_impl/ref.rb b/lib/gitlab/git/rugged_impl/ref.rb
deleted file mode 100644
index b553e82dc47..00000000000
--- a/lib/gitlab/git/rugged_impl/ref.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-# NOTE: This code is legacy. Do not add/modify code here unless you have
-# discussed with the Gitaly team. See
-# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
-# for more details.
-
-module Gitlab
- module Git
- module RuggedImpl
- module Ref
- def self.dereference_object(object)
- object = object.target while object.is_a?(::Rugged::Tag::Annotation)
-
- object
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/git/rugged_impl/repository.rb b/lib/gitlab/git/rugged_impl/repository.rb
deleted file mode 100644
index cd4eefa158e..00000000000
--- a/lib/gitlab/git/rugged_impl/repository.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-# frozen_string_literal: true
-
-# NOTE: This code is legacy. Do not add/modify code here unless you have
-# discussed with the Gitaly team. See
-# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
-# for more details.
-
-# rubocop:disable Gitlab/ModuleWithInstanceVariables
-module Gitlab
- module Git
- module RuggedImpl
- module Repository
- extend ::Gitlab::Utils::Override
- include Gitlab::Git::RuggedImpl::UseRugged
-
- FEATURE_FLAGS = %i[rugged_find_commit rugged_tree_entries rugged_tree_entry rugged_commit_is_ancestor rugged_commit_tree_entry rugged_list_commits_by_oid].freeze
-
- def alternate_object_directories
- relative_object_directories.map { |d| File.join(path, d) }
- end
-
- ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES = %w[
- GIT_OBJECT_DIRECTORY_RELATIVE
- GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
- ].freeze
-
- def relative_object_directories
- Gitlab::Git::HookEnv.all(gl_repository).values_at(*ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES).flatten.compact
- end
-
- def rugged
- @rugged ||= ::Rugged::Repository.new(path, alternates: alternate_object_directories)
- rescue ::Rugged::RepositoryError, ::Rugged::OSError
- raise ::Gitlab::Git::Repository::NoRepository, 'no repository for such path'
- end
-
- def cleanup
- @rugged&.close
- end
-
- # Return the object that +revspec+ points to. If +revspec+ is an
- # annotated tag, then return the tag's target instead.
- def rev_parse_target(revspec)
- obj = rugged.rev_parse(revspec)
- Ref.dereference_object(obj)
- end
-
- override :ancestor?
- def ancestor?(from, to)
- if use_rugged?(self, :rugged_commit_is_ancestor)
- execute_rugged_call(:rugged_is_ancestor?, from, to)
- else
- super
- end
- end
-
- def rugged_is_ancestor?(ancestor_id, descendant_id)
- return false if ancestor_id.nil? || descendant_id.nil?
-
- rugged_merge_base(ancestor_id, descendant_id) == ancestor_id
- rescue Rugged::OdbError
- false
- end
-
- def rugged_merge_base(from, to)
- rugged.merge_base(from, to)
- rescue Rugged::ReferenceError
- nil
- end
-
- # Lookup for rugged object by oid or ref name
- def lookup(oid_or_ref_name)
- rev_parse_target(oid_or_ref_name)
- end
- end
- end
- end
-end
-# rubocop:enable Gitlab/ModuleWithInstanceVariables
diff --git a/lib/gitlab/git/rugged_impl/tree.rb b/lib/gitlab/git/rugged_impl/tree.rb
deleted file mode 100644
index bc3ff01e1e2..00000000000
--- a/lib/gitlab/git/rugged_impl/tree.rb
+++ /dev/null
@@ -1,147 +0,0 @@
-# frozen_string_literal: true
-
-# NOTE: This code is legacy. Do not add/modify code here unless you have
-# discussed with the Gitaly team. See
-# https://docs.gitlab.com/ee/development/gitaly.html#legacy-rugged-code
-# for more details.
-
-module Gitlab
- module Git
- module RuggedImpl
- module Tree
- module ClassMethods
- extend ::Gitlab::Utils::Override
- include Gitlab::Git::RuggedImpl::UseRugged
-
- TREE_SORT_ORDER = { tree: 0, blob: 1, commit: 2 }.freeze
-
- override :tree_entries
- def tree_entries(repository, sha, path, recursive, skip_flat_paths, rescue_not_found, pagination_params = nil)
- if use_rugged?(repository, :rugged_tree_entries)
- entries = execute_rugged_call(
- :tree_entries_with_flat_path_from_rugged, repository, sha, path, recursive, skip_flat_paths)
-
- if pagination_params
- paginated_response(entries, pagination_params[:limit], pagination_params[:page_token].to_s)
- else
- [entries, nil]
- end
- else
- super
- end
- end
-
- # Rugged version of TreePagination in Go: https://gitlab.com/gitlab-org/gitaly/-/merge_requests/3611
- def paginated_response(entries, limit, token)
- total_entries = entries.count
-
- return [[], nil] if limit == 0 || limit.blank?
-
- entries = Gitlab::Utils.stable_sort_by(entries) { |x| TREE_SORT_ORDER[x.type] }
-
- if token.blank?
- index = 0
- else
- index = entries.index { |entry| entry.id == token }
-
- raise Gitlab::Git::CommandError, "could not find starting OID: #{token}" if index.nil?
-
- index += 1
- end
-
- return [entries[index..], nil] if limit < 0
-
- last_index = index + limit
- result = entries[index...last_index]
-
- if last_index < total_entries
- cursor = Gitaly::PaginationCursor.new(next_cursor: result.last.id)
- end
-
- [result, cursor]
- end
-
- def tree_entries_with_flat_path_from_rugged(repository, sha, path, recursive, skip_flat_paths)
- tree_entries_from_rugged(repository, sha, path, recursive).tap do |entries|
- # This was an optimization to reduce N+1 queries for Gitaly
- # (https://gitlab.com/gitlab-org/gitaly/issues/530).
- rugged_populate_flat_path(repository, sha, path, entries) unless skip_flat_paths
- end
- end
-
- def tree_entries_from_rugged(repository, sha, path, recursive)
- current_path_entries = get_tree_entries_from_rugged(repository, sha, path)
- ordered_entries = []
-
- current_path_entries.each do |entry|
- ordered_entries << entry
-
- if recursive && entry.dir?
- ordered_entries.concat(tree_entries_from_rugged(repository, sha, entry.path, true))
- end
- end
-
- ordered_entries
- end
-
- def rugged_populate_flat_path(repository, sha, path, entries)
- entries.each do |entry|
- entry.flat_path = entry.path
-
- next unless entry.dir?
-
- entry.flat_path =
- if path
- File.join(path, rugged_flatten_tree(repository, sha, entry, path))
- else
- rugged_flatten_tree(repository, sha, entry, path)
- end
- end
- end
-
- # Returns the relative path of the first subdir that doesn't have only one directory descendant
- def rugged_flatten_tree(repository, sha, tree, root_path)
- subtree = tree_entries_from_rugged(repository, sha, tree.path, false)
-
- if subtree.count == 1 && subtree.first.dir?
- File.join(tree.name, rugged_flatten_tree(repository, sha, subtree.first, root_path))
- else
- tree.name
- end
- end
-
- def get_tree_entries_from_rugged(repository, sha, path)
- commit = repository.lookup(sha)
- root_tree = commit.tree
-
- tree = if path
- id = find_id_by_path(repository, root_tree.oid, path)
- if id
- repository.lookup(id)
- else
- []
- end
- else
- root_tree
- end
-
- tree.map do |entry|
- current_path = path ? File.join(path, entry[:name]) : entry[:name]
-
- new(
- id: entry[:oid],
- name: entry[:name],
- type: entry[:type],
- mode: entry[:filemode].to_s(8),
- path: current_path,
- commit_id: sha
- )
- end
- rescue Rugged::ReferenceError
- []
- end
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/git/rugged_impl/use_rugged.rb b/lib/gitlab/git/rugged_impl/use_rugged.rb
deleted file mode 100644
index 57cced97d02..00000000000
--- a/lib/gitlab/git/rugged_impl/use_rugged.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Git
- module RuggedImpl
- module UseRugged
- def use_rugged?(_, _)
- false
- end
-
- def execute_rugged_call(method_name, *args)
- Gitlab::GitalyClient::StorageSettings.allow_disk_access do
- start = Gitlab::Metrics::System.monotonic_time
-
- result = send(method_name, *args) # rubocop:disable GitlabSecurity/PublicSend
-
- duration = Gitlab::Metrics::System.monotonic_time - start
-
- if Gitlab::RuggedInstrumentation.active?
- Gitlab::RuggedInstrumentation.increment_query_count
- Gitlab::RuggedInstrumentation.add_query_time(duration)
-
- Gitlab::RuggedInstrumentation.add_call_details(
- feature: method_name,
- args: args,
- duration: duration,
- backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller))
- end
-
- result
- end
- end
-
- def running_puma_with_multiple_threads?
- return false unless Gitlab::Runtime.puma?
-
- ::Puma.respond_to?(:cli_config) && ::Puma.cli_config.options[:max_threads] > 1
- end
-
- def rugged_feature_keys
- Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS
- end
-
- def rugged_enabled_through_feature_flag?
- false
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb
index 6e97e412b91..4747ab55c63 100644
--- a/lib/gitlab/git/tree.rb
+++ b/lib/gitlab/git/tree.rb
@@ -12,9 +12,6 @@ module Gitlab
class << self
# Get list of tree objects
# for repository based on commit sha and path
- # Uses rugged for raw objects
- #
- # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/320
def where(
repository, sha, path = nil, recursive = false, skip_flat_paths = true, rescue_not_found = true,
pagination_params = nil)
@@ -110,5 +107,3 @@ module Gitlab
end
end
end
-
-Gitlab::Git::Tree.singleton_class.prepend Gitlab::Git::RuggedImpl::Tree::ClassMethods
diff --git a/lib/gitlab/gitaly_client/storage_settings.rb b/lib/gitlab/gitaly_client/storage_settings.rb
index 4cc0269673f..adf0c811274 100644
--- a/lib/gitlab/gitaly_client/storage_settings.rb
+++ b/lib/gitlab/gitaly_client/storage_settings.rb
@@ -31,19 +31,11 @@ module Gitlab
end
def self.disk_access_denied?
- return false if rugged_enabled?
-
!temporarily_allowed?(ALLOW_KEY)
rescue StandardError
false # Err on the side of caution, don't break gitlab for people
end
- def self.rugged_enabled?
- Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS.any? do |flag|
- Feature.enabled?(flag)
- end
- end
-
def initialize(storage)
raise InvalidConfigurationError, "expected a Hash, got a #{storage.class.name}" unless storage.is_a?(Hash)
raise InvalidConfigurationError, INVALID_STORAGE_MESSAGE unless storage.has_key?('path')