Enable frozen string for lib/gitlab/*.rb

This commit is contained in:
gfyoung 2018-10-22 07:00:50 +00:00 committed by Rémy Coutable
parent 173b1436b1
commit c858f70d07
151 changed files with 327 additions and 22 deletions

View file

@ -0,0 +1,5 @@
---
title: Enable frozen string for lib/gitlab/*.rb
merge_request:
author: gfyoung
type: performance

View file

@ -164,7 +164,7 @@ module Backup
def tar_version
tar_version, _ = Gitlab::Popen.popen(%w(tar --version))
tar_version.force_encoding('locale').split("\n").first
tar_version.dup.force_encoding('locale').split("\n").first
end
def skipped?(item)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Gitlab::Access module
#
# Define allowed roles that can be used

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# This class implements a simple rate limiter that can be used to throttle
# certain actions. Unlike Rack Attack and Rack::Throttle, which operate at

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Allowable
def can?(*args)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class AppLogger < Gitlab::Logger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'asciidoctor'
require 'asciidoctor/converter/html5'
require "asciidoctor-plantuml"

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Auth
MissingPersonalAccessTokenError = Class.new(StandardError)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
def self.queue

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This is a base controller for doorkeeper.
# It adds the `can?` helper used in the views.
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Blame
attr_accessor :blob, :commit

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This has been extracted from https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb
module Gitlab
module BlobHelper

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class BuildAccess < UserAccess
attr_accessor :user, :project

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ChangesList
include Enumerable

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'json'
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# For backwards compatibility, generic CI (which is a build without a user) is
# allowed to :build_download_code without any other checks.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ClosingIssueExtractor
ISSUE_CLOSING_REGEX = begin

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Module containing GitLab's syntax color scheme definitions and helper
# methods for accessing them.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab::ConfigHelper
def gitlab_config_features
Gitlab.config.gitlab.default_projects_features

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ContributionsCalendar
attr_reader :contributor

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Contributor
attr_accessor :email, :name, :commits, :additions, :deletions

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class CrossProjectAccess
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module CurrentSettings
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Daemon
def self.initialize_instance(*args)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Database
# The max value of INTEGER type is the same between MySQL and PostgreSQL:
@ -99,11 +101,11 @@ module Gitlab
order = "#{field} #{direction}"
if postgresql?
order << ' NULLS LAST'
order = "#{order} NULLS LAST"
else
# `field IS NULL` will be `0` for non-NULL columns and `1` for NULL
# columns. In the (default) ascending order, `0` comes first.
order.prepend("#{field} IS NULL, ") if direction == 'ASC'
order = "#{field} IS NULL, #{order}" if direction == 'ASC'
end
order
@ -113,11 +115,11 @@ module Gitlab
order = "#{field} #{direction}"
if postgresql?
order << ' NULLS FIRST'
order = "#{order} NULLS FIRST"
else
# `field IS NULL` will be `0` for non-NULL columns and `1` for NULL
# columns. In the (default) ascending order, `0` comes first.
order.prepend("#{field} IS NULL, ") if direction == 'DESC'
order = "#{field} IS NULL, #{order}" if direction == 'DESC'
end
order
@ -184,7 +186,7 @@ module Gitlab
EOF
if return_ids
sql << 'RETURNING id'
sql = "#{sql}RETURNING id"
end
result = connection.execute(sql)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module DependencyLinker
LINKERS = [

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Checks if a set of migrations requires downtime or not.
class DowntimeCheck

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# rubocop: disable Rails/Output
module Gitlab
# Checks if a set of migrations requires downtime or not.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Emoji
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module EncodingHelper
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Environment
def self.hostname

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class EnvironmentLogger < Gitlab::Logger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'securerandom'
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# This module provides helper methods which are intregrated with GitLab::ExclusiveLease
module ExclusiveLeaseHelpers

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This class extends an OpenStruct object by adding predicate methods to mimic
# ActiveRecord access. We rely on the initial values being true or false to
# determine whether to define a predicate method because for a newly-added

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Favicon
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'set'
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This class finds files in a repository by name and content
# the result is joined and sorted by file name
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Builds the markdown link of a file
# It needs the methods filename and secure_url (final destination url) to be defined.
module Gitlab
@ -8,7 +10,7 @@ module Gitlab
return unless name = markdown_name
markdown = "[#{name.gsub(']', '\\]')}](#{secure_url})"
markdown.prepend("!") if image_or_video? || dangerous?
markdown = "!#{markdown}" if image_or_video? || dangerous?
markdown
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'gitlab/encoding_helper'
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Check a user's access to perform a git action. All public methods in this
# class return an instance of `GitlabAccessStatus`
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class GitAccessWiki < GitAccess
ERROR_MESSAGES = {

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class GitLogger < Gitlab::Logger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Gitaly note: JV: does not need to be migrated, works without a repo.
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'base64'
require 'gitaly'
@ -23,7 +25,7 @@ module Gitlab
stacks = most_invoked_stack.join('\n') if most_invoked_stack
msg = "GitalyClient##{call_site} called #{invocation_count} times from single request. Potential n+1?"
msg << "\nThe following call site called into Gitaly #{max_call_stack} times:\n#{stacks}\n" if stacks
msg = "#{msg}\nThe following call site called into Gitaly #{max_call_stack} times:\n#{stacks}\n" if stacks
super(msg)
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module GithubImport
def self.refmap

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module GlId
def self.gl_id(user)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module GlRepository
def self.gl_repository(project, is_wiki)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# rubocop:disable Metrics/AbcSize
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Gpg
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Graphql
StandardGraphqlError = Class.new(StandardError)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Retrieving of parent or child groups based on a base ActiveRecord relation.
#

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Highlight
TIMEOUT_BACKGROUND = 30.seconds

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This class is used as a proxy for all outbounding http connection
# coming from callbacks, services and hooks. The direct use of the HTTParty
# is discouraged because it can lead to several security problems, like SSRF

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
##
# This class is compatible with IO class (https://ruby-doc.org/core-2.3.1/IO.html)
# source: https://gitlab.com/snippets/1685610
@ -73,8 +75,8 @@ module Gitlab
end
end
def read(length = nil, outbuf = "")
out = ""
def read(length = nil, outbuf = nil)
out = []
length ||= size - tell
@ -90,17 +92,18 @@ module Gitlab
length -= chunk_data.bytesize
end
out = out.join
# If outbuf is passed, we put the output into the buffer. This supports IO.copy_stream functionality
if outbuf
outbuf.slice!(0, outbuf.bytesize)
outbuf << out
outbuf.replace(out)
end
out
end
def readline
out = ""
out = []
until eof?
data = get_chunk
@ -116,7 +119,7 @@ module Gitlab
end
end
out
out.join
end
def write(data)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module I18n
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Detect user based on identifier like
# key-13 or user-36 or last commit
module Gitlab

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module ImportExport
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ImportFormatter
def comment(author, date, body)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Gitlab::ImportSources module
#
# Define import sources that can be used

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module IncomingEmail
UNSUBSCRIBE_SUFFIX = '+unsubscribe'.freeze

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
#
# Calculates the fingerprint of a given key without using

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module IssuableMetadata
def issuable_meta_data(issuable_collection, collection_type)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module IssuableSorter
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Class for counting and caching the number of issuables per state.
class IssuablesCountForState

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class IssuesLabels
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# JobWaiter can be used to wait for a number of Sidekiq jobs to complete.
#

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class JsonLogger < ::Gitlab::Logger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Helper methods to do with Kubernetes network services & resources
module Kubernetes

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class LanguageDetection
MAX_LANGUAGES = 5

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# A class that can be wrapped around an expensive method call so it's only
# executed when actually needed.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class LfsToken
attr_accessor :actor

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class Logger < ::Logger
def self.file_name

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'yaml'
require 'json'
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module MarkupHelper
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Metrics
include Gitlab::Metrics::InfluxDb

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class MultiCollectionPaginator
attr_reader :first_collection, :second_collection, :per_page

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class OmniauthInitializer
def initialize(devise_config)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module OptimisticLocking
module_function

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Parser/renderer for markups without other special support code.
module OtherMarkup

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# The +otp_key_base+ param is used to encrypt the User#otp_secret attribute.
#

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Pages
VERSION = File.read(Rails.root.join("GITLAB_PAGES_VERSION")).strip.freeze

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class PagesClient
class << self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class PagesTransfer < ProjectTransfer
def root_dir

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module PathRegex
extend self

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module PerformanceBar
ALLOWED_USER_IDS_KEY = 'performance_bar_allowed_user_ids:v2'.freeze

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Plugin
def self.files

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class PluginLogger < Gitlab::Logger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class PollingInterval
HEADER_NAME = 'Poll-Interval'.freeze

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'fileutils'
require 'open3'
@ -11,7 +13,7 @@ module Gitlab
def popen(cmd, path = nil, vars = {}, &block)
result = popen_with_detail(cmd, path, vars, &block)
[result.stdout << result.stderr, result.status&.exitstatus]
["#{result.stdout}#{result.stderr}", result.status&.exitstatus]
end
# Returns Result

View file

@ -1,4 +1,6 @@
# coding: utf-8
# frozen_string_literal: true
module Gitlab
module Profiler
FILTERED_STRING = '[FILTERED]'.freeze

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ProjectSearchResults < SearchResults
attr_reader :project, :repository_ref
@ -57,7 +59,8 @@ module Gitlab
ref = nil
filename = nil
basename = nil
data = ""
data = []
startline = 0
result.each_line.each_with_index do |line, index|
@ -78,7 +81,7 @@ module Gitlab
basename: basename,
ref: ref,
startline: startline,
data: data,
data: data.join,
project_id: project ? project.id : nil
)
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ProjectServiceLogger < Gitlab::JsonLogger
def self.file_name_noext

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
class ProjectTemplate
attr_reader :title, :name, :description, :preview

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# This class is used to move local, unhashed files owned by projects to their new location
class ProjectTransfer

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
# Helper methods to interact with Prometheus network services & resources
class PrometheusClient

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module ProtocolAccess
def self.allowed?(protocol)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This class is part of the Gitlab::HTTP wrapper. Depending on the value
# of the global setting allow_local_requests_from_hooks_and_services this adapter
# will allow/block connection to internal IPs and/or urls.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module QueryLimiting
# Returns true if we should enable tracking of query counts.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Gitlab
module Recaptcha
def self.load_configurations!

Some files were not shown because too many files have changed in this diff Show more