From b76ae638462ab0f673e5915986070518dd3f9ad3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 Aug 2021 09:08:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-2-stable-ee --- lib/gitlab/git/blob.rb | 4 +-- lib/gitlab/git/commit.rb | 12 ++++++++- lib/gitlab/git/commit_stats.rb | 24 +++++++++-------- lib/gitlab/git/conflict/file.rb | 12 ++++++++- lib/gitlab/git/conflict/resolver.rb | 5 ++-- lib/gitlab/git/remote_mirror.rb | 6 ++--- lib/gitlab/git/repository.rb | 53 ++++++++++++------------------------- lib/gitlab/git/rugged_impl/tree.rb | 7 +++-- lib/gitlab/git/tag.rb | 16 ++++++++++- lib/gitlab/git/tree.rb | 8 +++--- 10 files changed, 83 insertions(+), 64 deletions(-) (limited to 'lib/gitlab/git') diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 1c8e55ecf50..f72217dedde 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -77,8 +77,8 @@ module Gitlab end end - def raw(repository, sha) - repository.gitaly_blob_client.get_blob(oid: sha, limit: MAX_DATA_DISPLAY_SIZE) + def raw(repository, sha, limit: MAX_DATA_DISPLAY_SIZE) + repository.gitaly_blob_client.get_blob(oid: sha, limit: limit) end # Returns an array of Blob instances, specified in blob_references as diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index a863b952390..7fd4acb4179 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -111,8 +111,18 @@ module Gitlab # Commit.between(repo, '29eda46b', 'master') # def between(repo, base, head) + # In either of these cases, we are guaranteed to return no commits, so + # shortcut the RPC call + return [] if Gitlab::Git.blank_ref?(base) || Gitlab::Git.blank_ref?(head) + wrapped_gitaly_errors do - repo.gitaly_commit_client.between(base, head) + if Feature.enabled?(:between_uses_list_commits, default_enabled: :yaml) + revisions = [head, "^#{base}"] # base..head + + repo.gitaly_commit_client.list_commits(revisions, reverse: true) + else + repo.gitaly_commit_client.between(base, head) + end end end diff --git a/lib/gitlab/git/commit_stats.rb b/lib/gitlab/git/commit_stats.rb index 8815088d23c..6a7a7032665 100644 --- a/lib/gitlab/git/commit_stats.rb +++ b/lib/gitlab/git/commit_stats.rb @@ -14,21 +14,23 @@ module Gitlab # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323 def initialize(repo, commit) @id = commit.id - @additions = 0 - @deletions = 0 - @total = 0 - wrapped_gitaly_errors do - gitaly_stats(repo, commit) - end - end + additions, deletions = fetch_stats(repo, commit) - def gitaly_stats(repo, commit) - stats = repo.gitaly_commit_client.commit_stats(@id) - @additions = stats.additions - @deletions = stats.deletions + @additions = additions.to_i + @deletions = deletions.to_i @total = @additions + @deletions end + + def fetch_stats(repo, commit) + Rails.cache.fetch("commit_stats:#{repo.gl_project_path}:#{@id}") do + stats = wrapped_gitaly_errors do + repo.gitaly_commit_client.commit_stats(@id) + end + + [stats.additions, stats.deletions] + end + end end end end diff --git a/lib/gitlab/git/conflict/file.rb b/lib/gitlab/git/conflict/file.rb index 7ffe4a7ae81..049ca5a54b3 100644 --- a/lib/gitlab/git/conflict/file.rb +++ b/lib/gitlab/git/conflict/file.rb @@ -6,13 +6,14 @@ module Gitlab class File UnsupportedEncoding = Class.new(StandardError) - attr_reader :their_path, :our_path, :our_mode, :repository, :commit_oid + attr_reader :ancestor_path, :their_path, :our_path, :our_mode, :repository, :commit_oid attr_accessor :raw_content def initialize(repository, commit_oid, conflict, raw_content) @repository = repository @commit_oid = commit_oid + @ancestor_path = conflict[:ancestor][:path] @their_path = conflict[:theirs][:path] @our_path = conflict[:ours][:path] @our_mode = conflict[:ours][:mode] @@ -94,6 +95,15 @@ module Gitlab resolution end + + def path + # There are conflict scenarios (e.g. file is removed on source) wherein + # our_path will be blank/nil. Since we are indexing them by path in + # `#conflicts` helper and we want to match the diff file to a conflict + # in `DiffFileEntity#highlighted_diff_lines`, we need to fallback to + # their_path (this is the path on target). + our_path.presence || their_path + end end end end diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index aa5d50d1fb1..2069d26400e 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -9,15 +9,16 @@ module Gitlab ConflictSideMissing = Class.new(StandardError) ResolutionError = Class.new(StandardError) - def initialize(target_repository, our_commit_oid, their_commit_oid) + def initialize(target_repository, our_commit_oid, their_commit_oid, allow_tree_conflicts: false) @target_repository = target_repository @our_commit_oid = our_commit_oid @their_commit_oid = their_commit_oid + @allow_tree_conflicts = allow_tree_conflicts end def conflicts @conflicts ||= wrapped_gitaly_errors do - gitaly_conflicts_client(@target_repository).list_conflict_files.to_a + gitaly_conflicts_client(@target_repository).list_conflict_files(allow_tree_conflicts: @allow_tree_conflicts).to_a rescue GRPC::FailedPrecondition => e raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing, e.message end diff --git a/lib/gitlab/git/remote_mirror.rb b/lib/gitlab/git/remote_mirror.rb index eb368af199d..2f618294e8e 100644 --- a/lib/gitlab/git/remote_mirror.rb +++ b/lib/gitlab/git/remote_mirror.rb @@ -5,11 +5,10 @@ module Gitlab class RemoteMirror include Gitlab::Git::WrapsGitalyErrors - attr_reader :repository, :ref_name, :remote_url, :only_branches_matching, :ssh_key, :known_hosts, :keep_divergent_refs + attr_reader :repository, :remote_url, :only_branches_matching, :ssh_key, :known_hosts, :keep_divergent_refs - def initialize(repository, ref_name, remote_url, only_branches_matching: [], ssh_key: nil, known_hosts: nil, keep_divergent_refs: false) + def initialize(repository, remote_url, only_branches_matching: [], ssh_key: nil, known_hosts: nil, keep_divergent_refs: false) @repository = repository - @ref_name = ref_name @remote_url = remote_url @only_branches_matching = only_branches_matching @ssh_key = ssh_key @@ -20,7 +19,6 @@ module Gitlab def update wrapped_gitaly_errors do repository.gitaly_remote_client.update_remote_mirror( - ref_name, remote_url, only_branches_matching, ssh_key: ssh_key, diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 70d072e8082..1ab80fe2454 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -354,13 +354,9 @@ module Gitlab end end - def new_commits(newrevs) + def new_commits(newrevs, allow_quarantine: false) wrapped_gitaly_errors do - if Feature.enabled?(:list_commits) - gitaly_commit_client.list_commits(Array.wrap(newrevs) + %w[--not --all]) - else - Array.wrap(newrevs).flat_map { |newrev| gitaly_ref_client.list_new_commits(newrev) } - end + gitaly_commit_client.list_new_commits(Array.wrap(newrevs), allow_quarantine: allow_quarantine) end end @@ -703,24 +699,11 @@ module Gitlab write_ref(ref, start_point) end - # If `mirror_refmap` is present the remote is set as mirror with that mapping - def add_remote(remote_name, url, mirror_refmap: nil) - wrapped_gitaly_errors do - gitaly_remote_client.add_remote(remote_name, url, mirror_refmap) - end - end - - def remove_remote(remote_name) - wrapped_gitaly_errors do - gitaly_remote_client.remove_remote(remote_name) - end - end - - def find_remote_root_ref(remote_name, remote_url, authorization = nil) - return unless remote_name.present? && remote_url.present? + def find_remote_root_ref(remote_url, authorization = nil) + return unless remote_url.present? wrapped_gitaly_errors do - gitaly_remote_client.find_remote_root_ref(remote_name, remote_url, authorization) + gitaly_remote_client.find_remote_root_ref(remote_url, authorization) end end @@ -820,18 +803,18 @@ module Gitlab # no_tags - should we use --no-tags flag? # prune - should we use --prune flag? # check_tags_changed - should we ask gitaly to calculate whether any tags changed? - def fetch_remote(remote, url: nil, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, prune: true, check_tags_changed: false) + def fetch_remote(url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, prune: true, check_tags_changed: false, http_authorization_header: "") wrapped_gitaly_errors do gitaly_repository_client.fetch_remote( - remote, - url: url, + url, refmap: refmap, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, prune: prune, check_tags_changed: check_tags_changed, - timeout: GITLAB_PROJECTS_TIMEOUT + timeout: GITLAB_PROJECTS_TIMEOUT, + http_authorization_header: http_authorization_header ) end end @@ -844,8 +827,8 @@ module Gitlab end end - def blob_at(sha, path) - Gitlab::Git::Blob.find(self, sha, path) unless Gitlab::Git.blank_ref?(sha) + def blob_at(sha, path, limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) + Gitlab::Git::Blob.find(self, sha, path, limit: limit) unless Gitlab::Git.blank_ref?(sha) end # Items should be of format [[commit_id, path], [commit_id1, path1]] @@ -922,13 +905,17 @@ module Gitlab end # rubocop:enable Metrics/ParameterLists - def write_config(full_path:) + def set_full_path(full_path:) return unless full_path.present? # This guard avoids Gitaly log/error spam raise NoRepository, 'repository does not exist' unless exists? - set_config('gitlab.fullpath' => full_path) + if Feature.enabled?(:set_full_path) + gitaly_repository_client.set_full_path(full_path) + else + set_config('gitlab.fullpath' => full_path) + end end def set_config(entries) @@ -937,12 +924,6 @@ module Gitlab end end - def delete_config(*keys) - wrapped_gitaly_errors do - gitaly_repository_client.delete_config(keys) - end - end - def disconnect_alternates wrapped_gitaly_errors do gitaly_repository_client.disconnect_alternates diff --git a/lib/gitlab/git/rugged_impl/tree.rb b/lib/gitlab/git/rugged_impl/tree.rb index 389c9d32ccb..5993c8888d3 100644 --- a/lib/gitlab/git/rugged_impl/tree.rb +++ b/lib/gitlab/git/rugged_impl/tree.rb @@ -14,9 +14,12 @@ module Gitlab include Gitlab::Git::RuggedImpl::UseRugged override :tree_entries - def tree_entries(repository, sha, path, recursive) + def tree_entries(repository, sha, path, recursive, pagination_params = nil) if use_rugged?(repository, :rugged_tree_entries) - execute_rugged_call(:tree_entries_with_flat_path_from_rugged, repository, sha, path, recursive) + [ + execute_rugged_call(:tree_entries_with_flat_path_from_rugged, repository, sha, path, recursive), + nil + ] else super end diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb index 568e894a02f..25895dc6728 100644 --- a/lib/gitlab/git/tag.rb +++ b/lib/gitlab/git/tag.rb @@ -5,6 +5,8 @@ module Gitlab class Tag < Ref extend Gitlab::EncodingHelper + delegate :id, to: :@raw_tag + attr_reader :object_sha, :repository MAX_TAG_MESSAGE_DISPLAY_SIZE = 10.megabytes @@ -24,6 +26,18 @@ module Gitlab def get_messages(repository, tag_ids) repository.gitaly_ref_client.get_tag_messages(tag_ids) end + + def extract_signature_lazily(repository, tag_id) + BatchLoader.for(tag_id).batch(key: repository) do |tag_ids, loader, args| + batch_signature_extraction(args[:key], tag_ids).each do |tag_id, signature_data| + loader.call(tag_id, signature_data) + end + end + end + + def batch_signature_extraction(repository, tag_ids) + repository.gitaly_ref_client.get_tag_signatures(tag_ids) + end end def initialize(repository, raw_tag) @@ -81,7 +95,7 @@ module Gitlab when :PGP nil # not implemented, see https://gitlab.com/gitlab-org/gitlab/issues/19260 when :X509 - X509::Tag.new(@raw_tag).signature + X509::Tag.new(@repository, self).signature else nil end diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb index ed02f2e92ec..eb008507397 100644 --- a/lib/gitlab/git/tree.rb +++ b/lib/gitlab/git/tree.rb @@ -15,15 +15,15 @@ module Gitlab # Uses rugged for raw objects # # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/320 - def where(repository, sha, path = nil, recursive = false) + def where(repository, sha, path = nil, recursive = false, pagination_params = nil) path = nil if path == '' || path == '/' - tree_entries(repository, sha, path, recursive) + tree_entries(repository, sha, path, recursive, pagination_params) end - def tree_entries(repository, sha, path, recursive) + def tree_entries(repository, sha, path, recursive, pagination_params = nil) wrapped_gitaly_errors do - repository.gitaly_commit_client.tree_entries(repository, sha, path, recursive) + repository.gitaly_commit_client.tree_entries(repository, sha, path, recursive, pagination_params) end end -- cgit v1.2.1