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>2021-09-20 16:18:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/git
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/commit.rb19
-rw-r--r--lib/gitlab/git/repository.rb60
-rw-r--r--lib/gitlab/git/rugged_impl/tree.rb43
-rw-r--r--lib/gitlab/git/user.rb2
4 files changed, 74 insertions, 50 deletions
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb
index 7fd4acb4179..6605e896ef1 100644
--- a/lib/gitlab/git/commit.rb
+++ b/lib/gitlab/git/commit.rb
@@ -108,20 +108,25 @@ module Gitlab
# See also #repository.commits_between
#
# Ex.
- # Commit.between(repo, '29eda46b', 'master')
+ # Commit.between(repo, '29eda46b', 'master') # all commits, ordered oldest to newest
+ # Commit.between(repo, '29eda46b', 'master', limit: 100) # 100 newest commits, ordered oldest to newest
#
- def between(repo, base, head)
+ def between(repo, base, head, limit: nil)
# 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
- if Feature.enabled?(:between_uses_list_commits, default_enabled: :yaml)
- revisions = [head, "^#{base}"] # base..head
-
- repo.gitaly_commit_client.list_commits(revisions, reverse: true)
+ revisions = [head, "^#{base}"] # base..head
+ client = repo.gitaly_commit_client
+
+ # We must return the commits in chronological order but using both
+ # limit and reverse in the Gitaly RPC would return the oldest N,
+ # rather than newest N, commits, so reorder in Ruby with limit
+ if limit
+ client.list_commits(revisions, pagination_params: { limit: limit }).reverse!
else
- repo.gitaly_commit_client.between(base, head)
+ client.list_commits(revisions, reverse: true)
end
end
end
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 1ab80fe2454..bc15bd367d8 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -127,6 +127,13 @@ module Gitlab
end
end
+ def find_tag(name)
+ wrapped_gitaly_errors do
+ gitaly_ref_client.find_tag(name)
+ end
+ rescue CommandError
+ end
+
def local_branches(sort_by: nil, pagination_params: nil)
wrapped_gitaly_errors do
gitaly_ref_client.local_branches(sort_by: sort_by, pagination_params: pagination_params)
@@ -191,9 +198,9 @@ module Gitlab
# Returns an Array of Tags
#
- def tags
+ def tags(sort_by: nil)
wrapped_gitaly_errors do
- gitaly_ref_client.tags
+ gitaly_ref_client.tags(sort_by: sort_by)
end
end
@@ -360,27 +367,31 @@ module Gitlab
end
end
- def new_blobs(newrev, dynamic_timeout: nil)
- return [] if newrev.blank? || newrev == ::Gitlab::Git::BLANK_SHA
+ def new_blobs(newrevs, dynamic_timeout: nil)
+ newrevs = Array.wrap(newrevs).reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA }
+ return [] if newrevs.empty?
- strong_memoize("new_blobs_#{newrev}") do
- wrapped_gitaly_errors do
- gitaly_ref_client.list_new_blobs(newrev, REV_LIST_COMMIT_LIMIT, dynamic_timeout: dynamic_timeout)
- end
+ newrevs = newrevs.uniq.sort
+
+ @new_blobs ||= Hash.new do |h, revs|
+ h[revs] = blobs(['--not', '--all', '--not'] + newrevs, with_paths: true, dynamic_timeout: dynamic_timeout)
end
+
+ @new_blobs[newrevs]
end
# List blobs reachable via a set of revisions. Supports the
# pseudo-revisions `--not` and `--all`. Uses the minimum of
# GitalyClient.medium_timeout and dynamic timeout if the dynamic
# timeout is set, otherwise it'll always use the medium timeout.
- def blobs(revisions, dynamic_timeout: nil)
+ def blobs(revisions, with_paths: false, dynamic_timeout: nil)
revisions = revisions.reject { |rev| rev.blank? || rev == ::Gitlab::Git::BLANK_SHA }
return [] if revisions.blank?
wrapped_gitaly_errors do
- gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT, dynamic_timeout: dynamic_timeout)
+ gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT,
+ with_paths: with_paths, dynamic_timeout: dynamic_timeout)
end
end
@@ -491,13 +502,6 @@ module Gitlab
[]
end
- # Returns a RefName for a given SHA
- def ref_name_for_sha(ref_path, sha)
- raise ArgumentError, "sha can't be empty" unless sha.present?
-
- gitaly_ref_client.find_ref_name(sha, ref_path)
- end
-
# Get refs hash which key is the commit id
# and value is a Gitlab::Git::Tag or Gitlab::Git::Branch
# Note that both inherit from Gitlab::Git::Ref
@@ -607,10 +611,6 @@ module Gitlab
end
end
- def find_tag(name)
- tags.find { |tag| tag.name == name }
- end
-
def merge_to_ref(user, **kwargs)
wrapped_gitaly_errors do
gitaly_operation_client.user_merge_to_ref(user, **kwargs)
@@ -876,12 +876,6 @@ module Gitlab
end
end
- def squash_in_progress?(squash_id)
- wrapped_gitaly_errors do
- gitaly_repository_client.squash_in_progress?(squash_id)
- end
- end
-
def bundle_to_disk(save_path)
wrapped_gitaly_errors do
gitaly_repository_client.create_bundle(save_path)
@@ -911,17 +905,7 @@ module Gitlab
# This guard avoids Gitaly log/error spam
raise NoRepository, 'repository does not exist' unless exists?
- 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)
- wrapped_gitaly_errors do
- gitaly_repository_client.set_config(entries)
- end
+ gitaly_repository_client.set_full_path(full_path)
end
def disconnect_alternates
diff --git a/lib/gitlab/git/rugged_impl/tree.rb b/lib/gitlab/git/rugged_impl/tree.rb
index 5993c8888d3..40c003821b9 100644
--- a/lib/gitlab/git/rugged_impl/tree.rb
+++ b/lib/gitlab/git/rugged_impl/tree.rb
@@ -13,18 +13,53 @@ module Gitlab
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, pagination_params = nil)
if use_rugged?(repository, :rugged_tree_entries)
- [
- execute_rugged_call(:tree_entries_with_flat_path_from_rugged, repository, sha, path, recursive),
- nil
- ]
+ entries = execute_rugged_call(:tree_entries_with_flat_path_from_rugged, repository, sha, path, recursive)
+
+ 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)
tree_entries_from_rugged(repository, sha, path, recursive).tap do |entries|
# This was an optimization to reduce N+1 queries for Gitaly
diff --git a/lib/gitlab/git/user.rb b/lib/gitlab/git/user.rb
index 05ae3391040..0798cc51055 100644
--- a/lib/gitlab/git/user.rb
+++ b/lib/gitlab/git/user.rb
@@ -6,7 +6,7 @@ module Gitlab
attr_reader :username, :name, :email, :gl_id, :timezone
def self.from_gitlab(gitlab_user)
- new(gitlab_user.username, gitlab_user.name, gitlab_user.commit_email, Gitlab::GlId.gl_id(gitlab_user), gitlab_user.timezone)
+ new(gitlab_user.username, gitlab_user.name, gitlab_user.commit_email_or_default, Gitlab::GlId.gl_id(gitlab_user), gitlab_user.timezone)
end
def self.from_gitaly(gitaly_user)