diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /lib/gitlab/git | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r-- | lib/gitlab/git/diff.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 61 | ||||
-rw-r--r-- | lib/gitlab/git/tag.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/git/wiki.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/git/wiki_page.rb | 34 |
5 files changed, 80 insertions, 42 deletions
diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb index 003cc87d65a..72f7413500f 100644 --- a/lib/gitlab/git/diff.rb +++ b/lib/gitlab/git/diff.rb @@ -230,7 +230,6 @@ module Gitlab private def encode_diff_to_utf8(replace_invalid_utf8_chars) - return unless Feature.enabled?(:convert_diff_to_utf8_with_replacement_symbol) return unless replace_invalid_utf8_chars && diff_should_be_converted? @diff = Gitlab::EncodingHelper.encode_utf8_with_replacement_character(@diff) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index ad655fedb6d..f1cd75258be 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -403,7 +403,7 @@ module Gitlab wrapped_gitaly_errors do gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT, - with_paths: with_paths, dynamic_timeout: dynamic_timeout) + with_paths: with_paths, dynamic_timeout: dynamic_timeout) end end @@ -701,7 +701,9 @@ module Gitlab # Delete the specified branch from the repository # Note: No Git hooks are executed for this action def delete_branch(branch_name) - write_ref(branch_name, Gitlab::Git::BLANK_SHA) + branch_name = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch_name}" unless branch_name.start_with?("refs/") + + delete_refs(branch_name) rescue CommandError => e raise DeleteBranchError, e end @@ -913,8 +915,29 @@ module Gitlab true end + # Creates a commit + # + # @param [User] user The committer of the commit. + # @param [String] branch_name: The name of the branch to be created/updated. + # @param [String] message: The commit message. + # @param [Array<Hash>] actions: An array of files to be added/updated/removed. + # @option actions: [Symbol] :action One of :create, :create_dir, :update, :move, :delete, :chmod + # @option actions: [String] :file_path The path of the file or directory being added/updated/removed. + # @option actions: [String] :previous_path The path of the file being moved. Only used for the :move action. + # @option actions: [String,IO] :content The file content for :create or :update + # @option actions: [String] :encoding One of text, base64 + # @option actions: [Boolean] :execute_filemode True sets the executable filemode on the file. + # @option actions: [Boolean] :infer_content True uses the existing file contents instead of using content on move. + # @param [String] author_email: The authors email, if unspecified the committers email is used. + # @param [String] author_name: The authors name, if unspecified the committers name is used. + # @param [String] start_branch_name: The name of the branch to be used as the parent of the commit. Only used if start_sha: is unspecified. + # @param [String] start_sha: The sha to be used as the parent of the commit. + # @param [Gitlab::Git::Repository] start_repository: The repository that contains the start branch or sha. Defaults to use this repository. + # @param [Boolean] force: Force update the branch. + # @return [Gitlab::Git::OperationService::BranchUpdate] + # # rubocop:disable Metrics/ParameterLists - def multi_action( + def commit_files( user, branch_name:, message:, actions:, author_email: nil, author_name: nil, start_branch_name: nil, start_sha: nil, start_repository: nil, @@ -989,8 +1012,8 @@ module Gitlab gitaly_ref_client.branch_names_contains_sha(sha) end - def tag_names_contains_sha(sha) - gitaly_ref_client.tag_names_contains_sha(sha) + def tag_names_contains_sha(sha, limit: 0) + gitaly_ref_client.tag_names_contains_sha(sha, limit: limit) end def search_files_by_content(query, ref, options = {}) @@ -1011,16 +1034,20 @@ module Gitlab end def search_files_by_name(query, ref) - safe_query = Regexp.escape(query.sub(%r{^/*}, "")) + safe_query = query.sub(%r{^/*}, "") ref ||= root_ref return [] if empty? || safe_query.blank? - gitaly_repository_client.search_files_by_name(ref, safe_query) + gitaly_repository_client.search_files_by_name(ref, safe_query).map do |file| + Gitlab::EncodingHelper.encode_utf8(file) + end end def search_files_by_regexp(filter, ref = 'HEAD') - gitaly_repository_client.search_files_by_regexp(ref, filter) + gitaly_repository_client.search_files_by_regexp(ref, filter).map do |file| + Gitlab::EncodingHelper.encode_utf8(file) + end end def find_commits_by_message(query, ref, path, limit, offset) @@ -1031,6 +1058,24 @@ module Gitlab end end + def list_commits_by(query, ref, author: nil, before: nil, after: nil, limit: 1000) + params = { + author: author, + ignore_case: true, + commit_message_patterns: query, + before: before, + after: after, + reverse: false, + pagination_params: { limit: limit } + } + + wrapped_gitaly_errors do + gitaly_commit_client + .list_commits([ref], params) + .map { |c| commit(c) } + end + end + def list_last_commits_for_tree(sha, path, offset: 0, limit: 25, literal_pathspec: false) wrapped_gitaly_errors do gitaly_commit_client.list_last_commits_for_tree(sha, path, offset: offset, limit: limit, literal_pathspec: literal_pathspec) diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb index 25895dc6728..5ed5158eeea 100644 --- a/lib/gitlab/git/tag.rb +++ b/lib/gitlab/git/tag.rb @@ -63,7 +63,7 @@ module Gitlab end def init_from_gitaly - @name = encode!(@raw_tag.name.dup) + @name = encode_utf8_with_escaping!(@raw_tag.name.dup) @target = @raw_tag.id @message = message_from_gitaly_tag diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 4bab94968d7..2228fcb886e 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -70,18 +70,6 @@ module Gitlab @repository.exists? end - def write_page(name, format, content, commit_details) - wrapped_gitaly_errors do - gitaly_write_page(name, format, content, commit_details) - end - end - - def update_page(page_path, title, format, content, commit_details) - wrapped_gitaly_errors do - gitaly_update_page(page_path, title, format, content, commit_details) - end - end - def list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false) wrapped_gitaly_errors do gitaly_list_pages( @@ -113,21 +101,13 @@ module Gitlab @gitaly_wiki_client ||= Gitlab::GitalyClient::WikiService.new(@repository) end - def gitaly_write_page(name, format, content, commit_details) - gitaly_wiki_client.write_page(name, format, content, commit_details) - end - - def gitaly_update_page(page_path, title, format, content, commit_details) - gitaly_wiki_client.update_page(page_path, title, format, content, commit_details) - end - def gitaly_find_page(title:, version: nil, dir: nil, load_content: true) return unless title.present? wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir, load_content: load_content) return unless wiki_page - Gitlab::Git::WikiPage.new(wiki_page, version) + Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version) rescue GRPC::InvalidArgument nil end @@ -143,7 +123,7 @@ module Gitlab end gitaly_pages.map do |wiki_page, version| - Gitlab::Git::WikiPage.new(wiki_page, version) + Gitlab::Git::WikiPage.from_gitaly_wiki_page(wiki_page, version) end end end diff --git a/lib/gitlab/git/wiki_page.rb b/lib/gitlab/git/wiki_page.rb index a1f3d64ccde..57b7e7d53dd 100644 --- a/lib/gitlab/git/wiki_page.rb +++ b/lib/gitlab/git/wiki_page.rb @@ -5,17 +5,31 @@ module Gitlab class WikiPage attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :historical, :formatted_data - # This class abstracts away Gitlab::GitalyClient::WikiPage - def initialize(gitaly_page, version) - @url_path = gitaly_page.url_path - @title = gitaly_page.title - @format = gitaly_page.format - @path = gitaly_page.path - @raw_data = gitaly_page.raw_data - @name = gitaly_page.name - @historical = gitaly_page.historical? + class << self + # Abstracts away Gitlab::GitalyClient::WikiPage + def from_gitaly_wiki_page(gitaly_page, version) + new( + url_path: gitaly_page.url_path, + title: gitaly_page.title, + format: gitaly_page.format, + path: gitaly_page.path, + raw_data: gitaly_page.raw_data, + name: gitaly_page.name, + historical: gitaly_page.historical?, + version: version + ) + end + end - @version = version + def initialize(hash) + @url_path = hash[:url_path] + @title = hash[:title] + @format = hash[:format] + @path = hash[:path] + @raw_data = hash[:raw_data] + @name = hash[:name] + @historical = hash[:historical] + @version = hash[:version] end def historical? |