summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/projects.rb21
-rw-r--r--lib/gitlab/git/operation_service.rb2
-rw-r--r--lib/gitlab/git/repository.rb63
-rw-r--r--lib/gitlab/git/repository_mirroring.rb30
-rw-r--r--lib/gitlab/gitaly_client/operation_service.rb11
-rw-r--r--lib/gitlab/profiler.rb6
-rw-r--r--lib/gitlab/profiler/total_time_flat_printer.rb39
-rw-r--r--lib/gitlab/url_sanitizer.rb15
8 files changed, 86 insertions, 101 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 0888e3befac..889e3d4f819 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -9,6 +9,21 @@ module API
before { authenticate_non_get! }
helpers do
+ params :optional_filter_params_ee do
+ # EE::API::Projects would override this helper
+ end
+
+ # EE::API::Projects would override this method
+ def apply_filters(projects)
+ projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
+ projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
+ projects = projects.with_statistics if params[:statistics]
+
+ projects
+ end
+ end
+
+ helpers do
params :statistics_params do
optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
end
@@ -39,6 +54,8 @@ module API
optional :membership, type: Boolean, default: false, desc: 'Limit by projects that the current user is a member of'
optional :with_issues_enabled, type: Boolean, default: false, desc: 'Limit by enabled issues feature'
optional :with_merge_requests_enabled, type: Boolean, default: false, desc: 'Limit by enabled merge requests feature'
+
+ use :optional_filter_params_ee
end
params :create_params do
@@ -52,9 +69,7 @@ module API
def present_projects(projects, options = {})
projects = reorder_projects(projects)
- projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
- projects = projects.with_merge_requests_enabled if params[:with_merge_requests_enabled]
- projects = projects.with_statistics if params[:statistics]
+ projects = apply_filters(projects)
projects = paginate(projects)
projects, options = with_custom_attributes(projects, options)
diff --git a/lib/gitlab/git/operation_service.rb b/lib/gitlab/git/operation_service.rb
index 280def182d5..57d748343be 100644
--- a/lib/gitlab/git/operation_service.rb
+++ b/lib/gitlab/git/operation_service.rb
@@ -8,6 +8,8 @@ module Gitlab
alias_method :branch_created?, :branch_created
def self.from_gitaly(branch_update)
+ return if branch_update.nil?
+
new(
branch_update.commit_id,
branch_update.repo_created,
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index f6d3894a71e..5b955753a92 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -672,35 +672,17 @@ module Gitlab
# If `mirror_refmap` is present the remote is set as mirror with that mapping
def add_remote(remote_name, url, mirror_refmap: nil)
- gitaly_migrate(:remote_add_remote) do |is_enabled|
- if is_enabled
- gitaly_remote_client.add_remote(remote_name, url, mirror_refmap)
- else
- rugged_add_remote(remote_name, url, mirror_refmap)
- end
+ wrapped_gitaly_errors do
+ gitaly_remote_client.add_remote(remote_name, url, mirror_refmap)
end
end
def remove_remote(remote_name)
- gitaly_migrate(:remote_remove_remote) do |is_enabled|
- if is_enabled
- gitaly_remote_client.remove_remote(remote_name)
- else
- rugged_remove_remote(remote_name)
- end
+ wrapped_gitaly_errors do
+ gitaly_remote_client.remove_remote(remote_name)
end
end
- # Update the specified remote using the values in the +options+ hash
- #
- # Example
- # repo.update_remote("origin", url: "path/to/repo")
- def remote_update(remote_name, url:)
- # TODO: Implement other remote options
- rugged.remotes.set_url(remote_name, url)
- nil
- end
-
AUTOCRLF_VALUES = {
"true" => true,
"false" => false,
@@ -874,12 +856,8 @@ module Gitlab
end
def fetch_repository_as_mirror(repository)
- gitaly_migrate(:remote_fetch_internal_remote) do |is_enabled|
- if is_enabled
- gitaly_remote_client.fetch_internal_remote(repository)
- else
- rugged_fetch_repository_as_mirror(repository)
- end
+ wrapped_gitaly_errors do
+ gitaly_remote_client.fetch_internal_remote(repository)
end
end
@@ -1287,35 +1265,6 @@ module Gitlab
gitaly_ref_client.delete_refs(refs: ref_names) if ref_names.any?
end
- def rugged_remove_remote(remote_name)
- # When a remote is deleted all its remote refs are deleted too, but in
- # the case of mirrors we map its refs (that would usualy go under
- # [remote_name]/) to the top level namespace. We clean the mapping so
- # those don't get deleted.
- if rugged.config["remote.#{remote_name}.mirror"]
- rugged.config.delete("remote.#{remote_name}.fetch")
- end
-
- rugged.remotes.delete(remote_name)
- true
- rescue Rugged::ConfigError
- false
- end
-
- def rugged_fetch_repository_as_mirror(repository)
- remote_name = "tmp-#{SecureRandom.hex}"
- repository = RemoteRepository.new(repository) unless repository.is_a?(RemoteRepository)
-
- add_remote(remote_name, GITALY_INTERNAL_URL, mirror_refmap: :all_refs)
- fetch_remote(remote_name, env: repository.fetch_env)
- ensure
- remove_remote(remote_name)
- end
-
- def fetch_remote(remote_name = 'origin', env: nil)
- run_git(['fetch', remote_name], env: env).last.zero?
- end
-
def gitlab_projects_error
raise CommandError, @gitlab_projects.output
end
diff --git a/lib/gitlab/git/repository_mirroring.rb b/lib/gitlab/git/repository_mirroring.rb
index ef86d4a55ca..8835bfb2481 100644
--- a/lib/gitlab/git/repository_mirroring.rb
+++ b/lib/gitlab/git/repository_mirroring.rb
@@ -1,22 +1,6 @@
module Gitlab
module Git
module RepositoryMirroring
- REFMAPS = {
- # With `:all_refs`, the repository is equivalent to the result of `git clone --mirror`
- all_refs: '+refs/*:refs/*',
- heads: '+refs/heads/*:refs/heads/*',
- tags: '+refs/tags/*:refs/tags/*'
- }.freeze
-
- RemoteError = Class.new(StandardError)
-
- def set_remote_as_mirror(remote_name, refmap: :all_refs)
- set_remote_refmap(remote_name, refmap)
-
- rugged.config["remote.#{remote_name}.mirror"] = true
- rugged.config["remote.#{remote_name}.prune"] = true
- end
-
def remote_branches(remote_name)
gitaly_migrate(:ref_find_all_remote_branches) do |is_enabled|
if is_enabled
@@ -45,20 +29,6 @@ module Gitlab
branches
end
-
- def set_remote_refmap(remote_name, refmap)
- Array(refmap).each_with_index do |refspec, i|
- refspec = REFMAPS[refspec] || refspec
-
- # We need multiple `fetch` entries, but Rugged only allows replacing a config, not adding to it.
- # To make sure we start from scratch, we set the first using rugged, and use `git` for any others
- if i == 0
- rugged.config["remote.#{remote_name}.fetch"] = refspec
- else
- run_git(%W[config --add remote.#{remote_name}.fetch #{refspec}])
- end
- end
- end
end
end
end
diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb
index 555733d1834..54c78fdb680 100644
--- a/lib/gitlab/gitaly_client/operation_service.rb
+++ b/lib/gitlab/gitaly_client/operation_service.rb
@@ -144,13 +144,14 @@ module Gitlab
branch: encode_binary(target_branch)
)
- branch_update = GitalyClient.call(
+ response = GitalyClient.call(
@repository.storage,
:operation_service,
:user_ff_branch,
request
- ).branch_update
- Gitlab::Git::OperationService::BranchUpdate.from_gitaly(branch_update)
+ )
+
+ Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update)
rescue GRPC::FailedPrecondition => e
raise Gitlab::Git::CommitError, e
end
@@ -306,9 +307,9 @@ module Gitlab
raise Gitlab::Git::CommitError, response.commit_error
elsif response.create_tree_error.presence
raise Gitlab::Git::Repository::CreateTreeError, response.create_tree_error
- else
- Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update)
end
+
+ Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update)
end
def user_commit_files_request_header(
diff --git a/lib/gitlab/profiler.rb b/lib/gitlab/profiler.rb
index ecff6ab5d5e..c5bb4648572 100644
--- a/lib/gitlab/profiler.rb
+++ b/lib/gitlab/profiler.rb
@@ -146,5 +146,11 @@ module Gitlab
logger.info("#{model} total (#{query_count}): #{time.round(2)}ms")
end
end
+
+ def self.print_by_total_time(result, options = {})
+ default_options = { sort_method: :total_time }
+
+ Gitlab::Profiler::TotalTimeFlatPrinter.new(result).print(STDOUT, default_options.merge(options))
+ end
end
end
diff --git a/lib/gitlab/profiler/total_time_flat_printer.rb b/lib/gitlab/profiler/total_time_flat_printer.rb
new file mode 100644
index 00000000000..2fd0ec10ba8
--- /dev/null
+++ b/lib/gitlab/profiler/total_time_flat_printer.rb
@@ -0,0 +1,39 @@
+module Gitlab
+ module Profiler
+ class TotalTimeFlatPrinter < RubyProf::FlatPrinter
+ def max_percent
+ @options[:max_percent] || 100
+ end
+
+ # Copied from:
+ # <https://github.com/ruby-prof/ruby-prof/blob/master/lib/ruby-prof/printers/flat_printer.rb>
+ #
+ # The changes are just to filter by total time, not self time, and add a
+ # max_percent option as well.
+ def print_methods(thread)
+ total_time = thread.total_time
+ methods = thread.methods.sort_by(&sort_method).reverse
+
+ sum = 0
+ methods.each do |method|
+ total_percent = (method.total_time / total_time) * 100
+ next if total_percent < min_percent
+ next if total_percent > max_percent
+
+ sum += method.self_time
+
+ @output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%s\n" % [
+ method.self_time / total_time * 100, # %self
+ method.total_time, # total
+ method.self_time, # self
+ method.wait_time, # wait
+ method.children_time, # children
+ method.called, # calls
+ method.recursive? ? "*" : " ", # cycle
+ method_name(method) # name
+ ]
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb
index de8b6ec69ce..308a95d2f09 100644
--- a/lib/gitlab/url_sanitizer.rb
+++ b/lib/gitlab/url_sanitizer.rb
@@ -71,12 +71,10 @@ module Gitlab
def generate_full_url
return @url unless valid_credentials?
- @full_url = @url.dup
-
- @full_url.password = credentials[:password] if credentials[:password].present?
- @full_url.user = credentials[:user] if credentials[:user].present?
-
- @full_url
+ @url.dup.tap do |generated|
+ generated.password = encode_percent(credentials[:password]) if credentials[:password].present?
+ generated.user = encode_percent(credentials[:user]) if credentials[:user].present?
+ end
end
def safe_url
@@ -89,5 +87,10 @@ module Gitlab
def valid_credentials?
credentials && credentials.is_a?(Hash) && credentials.any?
end
+
+ def encode_percent(string)
+ # CGI.escape converts spaces to +, but this doesn't work for git clone
+ CGI.escape(string).gsub('+', '%20')
+ end
end
end