diff options
Diffstat (limited to 'lib/gitlab/git')
27 files changed, 170 insertions, 170 deletions
diff --git a/lib/gitlab/git/attributes_at_ref_parser.rb b/lib/gitlab/git/attributes_at_ref_parser.rb index cbddf836ce8..5b2b8290966 100644 --- a/lib/gitlab/git/attributes_at_ref_parser.rb +++ b/lib/gitlab/git/attributes_at_ref_parser.rb @@ -7,7 +7,7 @@ module Gitlab delegate :attributes, to: :@parser def initialize(repository, ref) - blob = repository.blob_at(ref, '.gitattributes') + blob = repository.blob_at(ref, ".gitattributes") @parser = AttributesParser.new(blob&.data) end diff --git a/lib/gitlab/git/attributes_parser.rb b/lib/gitlab/git/attributes_parser.rb index 8b9d74ae8e7..a719357a958 100644 --- a/lib/gitlab/git/attributes_parser.rb +++ b/lib/gitlab/git/attributes_parser.rb @@ -15,7 +15,7 @@ module Gitlab # # Returns a Hash. def attributes(file_path) - absolute_path = File.join('/', file_path) + absolute_path = File.join("/", file_path) patterns.each do |pattern, attrs| return attrs if File.fnmatch?(pattern, absolute_path) @@ -42,9 +42,9 @@ module Gitlab # Returns a Hash containing the attributes and their values. def parse_attributes(string) values = {} - dash = '-' - equal = '=' - binary = 'binary' + dash = "-" + equal = "=" + binary = "binary" string.split(/\s+/).each do |chunk| # Data such as "foo = bar" should be treated as "foo" and "bar" being @@ -72,7 +72,7 @@ module Gitlab # When the "binary" option is set the "diff" option should be set to # the inverse. If "diff" is later set it should overwrite the # automatically set value. - values['diff'] = false if key == binary && value + values["diff"] = false if key == binary && value end values @@ -92,7 +92,7 @@ module Gitlab # Parses the Git attributes file contents. def parse_data pairs = [] - comment = '#' + comment = "#" each_line do |line| next if line.start_with?(comment) || line.empty? @@ -101,7 +101,7 @@ module Gitlab parsed = attrs ? parse_attributes(attrs) : {} - absolute_pattern = File.join('/', pattern) + absolute_pattern = File.join("/", pattern) pairs << [absolute_pattern, parsed] end diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 259a2b7911a..f2070fe15ca 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -25,8 +25,8 @@ module Gitlab def find(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) return unless path - path = path.sub(%r{\A/*}, '') - path = '/' if path.empty? + path = path.sub(%r{\A/*}, "") + path = "/" if path.empty? name = File.basename(path) # Gitaly will think that setting the limit to 0 means unlimited, while @@ -43,7 +43,7 @@ module Gitlab case entry.type when :COMMIT - new(id: entry.oid, name: name, size: 0, data: '', path: path, commit_id: sha) + new(id: entry.oid, name: name, size: 0, data: "", path: path, commit_id: sha) when :BLOB new(id: entry.oid, name: name, size: entry.size, data: entry.data.dup, mode: entry.mode.to_s(8), path: path, commit_id: sha, binary: binary?(entry.data)) @@ -91,8 +91,8 @@ module Gitlab end def initialize(options) - %w(id name path size data mode commit_id binary).each do |key| - self.__send__("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend + %w[id name path size data mode commit_id binary].each do |key| + __send__("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend end # Retain the actual size before it is encoded @@ -111,7 +111,7 @@ module Gitlab # Load all blob data (not just the first MAX_DATA_DISPLAY_SIZE bytes) into # memory as a Ruby string. def load_all_data!(repository) - return if @data == '' # don't mess with submodule blobs + return if @data == "" # don't mess with submodule blobs # Even if we return early, recalculate wether this blob is binary in # case a blob was initialized as text but the full data isn't @@ -169,7 +169,7 @@ module Gitlab :lfs end - alias_method :external_size, :lfs_size + alias external_size lfs_size private diff --git a/lib/gitlab/git/branch.rb b/lib/gitlab/git/branch.rb index 9447cfa0fb6..465ecc24430 100644 --- a/lib/gitlab/git/branch.rb +++ b/lib/gitlab/git/branch.rb @@ -18,7 +18,7 @@ module Gitlab end def active? - self.dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago + dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago end def stale? diff --git a/lib/gitlab/git/bundle_file.rb b/lib/gitlab/git/bundle_file.rb index 8384a436fcc..c6c18600f57 100644 --- a/lib/gitlab/git/bundle_file.rb +++ b/lib/gitlab/git/bundle_file.rb @@ -21,9 +21,9 @@ module Gitlab end def check! - data = File.open(filename, 'r') { |f| f.read(MAGIC.size) } + data = File.open(filename, "r") { |f| f.read(MAGIC.size) } - raise InvalidBundleError, 'Invalid bundle file' unless data == MAGIC + raise InvalidBundleError, "Invalid bundle file" unless data == MAGIC end end end diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 5863815ca85..4c5f4a27ced 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -14,7 +14,7 @@ module Gitlab SERIALIZE_KEYS = [ :id, :message, :parent_ids, :authored_date, :author_name, :author_email, - :committed_date, :committer_name, :committer_email + :committed_date, :committer_name, :committer_email, ].freeze attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator @@ -39,7 +39,7 @@ module Gitlab # def where(options) repo = options.delete(:repo) - raise 'Gitlab::Git::Repository is required' unless repo.respond_to?(:log) + raise "Gitlab::Git::Repository is required" unless repo.respond_to?(:log) repo.log(options) end @@ -60,11 +60,11 @@ module Gitlab return nil unless commit_id.is_a?(String) # This saves us an RPC round trip. - return nil if commit_id.include?(':') + return nil if commit_id.include?(":") - commit = wrapped_gitaly_errors do + commit = wrapped_gitaly_errors { repo.gitaly_commit_client.find_commit(commit_id) - end + } decorate(repo, commit) if commit rescue Gitlab::Git::CommandError, Gitlab::Git::Repository::NoRepository, ArgumentError diff --git a/lib/gitlab/git/conflict/file.rb b/lib/gitlab/git/conflict/file.rb index 7ffe4a7ae81..33d4c7fd176 100644 --- a/lib/gitlab/git/conflict/file.rb +++ b/lib/gitlab/git/conflict/file.rb @@ -23,18 +23,18 @@ module Gitlab return @lines if defined?(@lines) begin - @type = 'text' + @type = "text" @lines = Gitlab::Git::Conflict::Parser.parse(content, - our_path: our_path, - their_path: their_path) + our_path: our_path, + their_path: their_path) rescue Gitlab::Git::Conflict::Parser::ParserError - @type = 'text-editor' + @type = "text-editor" @lines = nil end end def content - @content ||= @raw_content.dup.force_encoding('UTF-8') + @content ||= @raw_content.dup.force_encoding("UTF-8") raise UnsupportedEncoding unless @content.valid_encoding? @@ -66,7 +66,7 @@ module Gitlab def resolve_lines(resolution) section_id = nil - lines.map do |line| + lines.map { |line| unless line[:type] section_id = nil next line @@ -75,16 +75,16 @@ module Gitlab section_id ||= line_code(line) case resolution[section_id] - when 'head' - next unless line[:type] == 'new' - when 'origin' - next unless line[:type] == 'old' + when "head" + next unless line[:type] == "new" + when "origin" + next unless line[:type] == "old" else raise Gitlab::Git::Conflict::Resolver::ResolutionError, "Missing resolution for section ID: #{section_id}" end line - end.compact + }.compact end def resolve_content(resolution) diff --git a/lib/gitlab/git/conflict/parser.rb b/lib/gitlab/git/conflict/parser.rb index 20de8ebde4e..6e7c05b34f2 100644 --- a/lib/gitlab/git/conflict/parser.rb +++ b/lib/gitlab/git/conflict/parser.rb @@ -23,7 +23,7 @@ module Gitlab type = nil lines = [] conflict_start = "<<<<<<< #{our_path}" - conflict_middle = '=======' + conflict_middle = "=======" conflict_end = ">>>>>>> #{their_path}" text.each_line.map do |line| @@ -32,23 +32,23 @@ module Gitlab if full_line == conflict_start validate_delimiter!(type.nil?) - type = 'new' + type = "new" elsif full_line == conflict_middle - validate_delimiter!(type == 'new') + validate_delimiter!(type == "new") - type = 'old' + type = "old" elsif full_line == conflict_end - validate_delimiter!(type == 'old') + validate_delimiter!(type == "old") type = nil elsif line[0] == '\\' - type = 'nonewline' + type = "nonewline" lines << { full_line: full_line, type: type, line_obj_index: line_obj_index, line_old: line_old, - line_new: line_new + line_new: line_new, } else lines << { @@ -56,11 +56,11 @@ module Gitlab type: type, line_obj_index: line_obj_index, line_old: line_old, - line_new: line_new + line_new: line_new, } - line_old += 1 if type != 'new' - line_new += 1 if type != 'old' + line_old += 1 if type != "new" + line_new += 1 if type != "old" line_obj_index += 1 end diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 26e82643a4c..ec5bb1d054d 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -16,9 +16,9 @@ module Gitlab end def conflicts - @conflicts ||= wrapped_gitaly_errors do + @conflicts ||= wrapped_gitaly_errors { gitaly_conflicts_client(@target_repository).list_conflict_files.to_a - end + } rescue GRPC::FailedPrecondition => e raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing.new(e.message) rescue GRPC::BadStatus => e diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb index 74a4633424f..df9818ed20d 100644 --- a/lib/gitlab/git/diff.rb +++ b/lib/gitlab/git/diff.rb @@ -12,14 +12,14 @@ module Gitlab # Stats properties attr_accessor :new_file, :renamed_file, :deleted_file - alias_method :new_file?, :new_file - alias_method :deleted_file?, :deleted_file - alias_method :renamed_file?, :renamed_file + alias new_file? new_file + alias deleted_file? deleted_file + alias renamed_file? renamed_file attr_accessor :expanded attr_writer :too_large - alias_method :expanded?, :expanded + alias expanded? expanded # The default maximum content size to display a diff patch. # @@ -31,24 +31,24 @@ module Gitlab # persisting limits over that. MAX_PATCH_BYTES_UPPER_BOUND = 500.kilobytes - SERIALIZE_KEYS = %i(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file too_large).freeze + SERIALIZE_KEYS = %i[diff new_path old_path a_mode b_mode new_file renamed_file deleted_file too_large].freeze class << self def between(repo, head, base, options = {}, *paths) straight = options.delete(:straight) || false common_commit = if straight - base - else - # Only show what is new in the source branch - # compared to the target branch, not the other way - # around. The linex below with merge_base is - # equivalent to diff with three dots (git diff - # branch1...branch2) From the git documentation: - # "git diff A...B" is equivalent to "git diff - # $(git-merge-base A B) B" - repo.merge_base(head, base) - end + base + else + # Only show what is new in the source branch + # compared to the target branch, not the other way + # around. The linex below with merge_base is + # equivalent to diff with three dots (git diff + # branch1...branch2) From the git documentation: + # "git diff A...B" is equivalent to "git diff + # $(git-merge-base A B) B" + repo.merge_base(head, base) + end options ||= {} actual_options = filter_diff_options(options) @@ -79,7 +79,7 @@ module Gitlab # exceeded def filter_diff_options(options, default_options = {}) allowed_options = [:ignore_whitespace_change, :max_files, :max_lines, - :limits, :expanded] + :limits, :expanded,] if default_options actual_defaults = default_options.dup @@ -167,7 +167,7 @@ module Gitlab end def submodule? - a_mode == '160000' || b_mode == '160000' + a_mode == "160000" || b_mode == "160000" end def line_count @@ -183,10 +183,10 @@ module Gitlab end # This is used by `to_hash` and `init_from_hash`. - alias_method :too_large, :too_large? + alias too_large too_large? def too_large! - @diff = '' + @diff = "" @line_count = 0 @too_large = true end @@ -198,7 +198,7 @@ module Gitlab end def collapse! - @diff = '' + @diff = "" @line_count = 0 @collapsed = true end @@ -211,7 +211,7 @@ module Gitlab end def has_binary_notice? - @diff.start_with?('Binary') + @diff.start_with?("Binary") end private diff --git a/lib/gitlab/git/diff_collection.rb b/lib/gitlab/git/diff_collection.rb index 5c70cb6c66c..88907203a93 100644 --- a/lib/gitlab/git/diff_collection.rb +++ b/lib/gitlab/git/diff_collection.rb @@ -7,7 +7,7 @@ module Gitlab class DiffCollection include Enumerable - DEFAULT_LIMITS = { max_files: 100, max_lines: 5000 }.freeze + DEFAULT_LIMITS = {max_files: 100, max_lines: 5000}.freeze attr_reader :limits @@ -36,7 +36,7 @@ module Gitlab @byte_count = 0 @overflow = false @empty = true - @array = Array.new + @array = [] end def each(&block) @@ -88,7 +88,7 @@ module Gitlab collection end - alias_method :to_ary, :to_a + alias to_ary to_a private diff --git a/lib/gitlab/git/gitmodules_parser.rb b/lib/gitlab/git/gitmodules_parser.rb index 575e12390cd..7d877c28b74 100644 --- a/lib/gitlab/git/gitmodules_parser.rb +++ b/lib/gitlab/git/gitmodules_parser.rb @@ -27,7 +27,7 @@ module Gitlab # In some .gitmodules files (e.g. nodegit's), a header # with the same name appears multiple times; we want to # accumulate the configs across these - @current_submodule = @result[section] || { 'name' => section } + @current_submodule = @result[section] || {"name" => section} @result[section] = @current_submodule end @@ -72,7 +72,7 @@ module Gitlab # If a submodule doesn't have a path, it is considered bogus # and is ignored submodules_by_name.each_with_object({}) do |(name, data), results| - path = data.delete 'path' + path = data.delete "path" next unless path results[path] = data diff --git a/lib/gitlab/git/lfs_pointer_file.rb b/lib/gitlab/git/lfs_pointer_file.rb index b7019a221ac..efd84e30ad9 100644 --- a/lib/gitlab/git/lfs_pointer_file.rb +++ b/lib/gitlab/git/lfs_pointer_file.rb @@ -3,8 +3,8 @@ module Gitlab module Git class LfsPointerFile - VERSION = "https://git-lfs.github.com/spec/v1".freeze - VERSION_LINE = "version #{VERSION}".freeze + VERSION = "https://git-lfs.github.com/spec/v1" + VERSION_LINE = "version #{VERSION}" def initialize(data) @data = data diff --git a/lib/gitlab/git/merge_base.rb b/lib/gitlab/git/merge_base.rb index b27f7038c26..d85553e2f89 100644 --- a/lib/gitlab/git/merge_base.rb +++ b/lib/gitlab/git/merge_base.rb @@ -31,7 +31,7 @@ module Gitlab # the repository, and thus cannot be used to find a merge base. def unknown_refs @unknown_refs ||= Hash[@refs.zip(commits_for_refs)] - .select { |ref, commit| commit.nil? }.keys + .select { |ref, commit| commit.nil? }.keys end private diff --git a/lib/gitlab/git/operation_service.rb b/lib/gitlab/git/operation_service.rb index 8797d3dce24..6107daeca5f 100644 --- a/lib/gitlab/git/operation_service.rb +++ b/lib/gitlab/git/operation_service.rb @@ -3,7 +3,7 @@ module Gitlab module Git class OperationService - BranchUpdate = Struct.new(:newrev, :repo_created, :branch_created) do + BranchUpdate = Struct.new(:newrev, :repo_created, :branch_created) { alias_method :repo_created?, :repo_created alias_method :branch_created?, :branch_created @@ -16,7 +16,7 @@ module Gitlab branch_update.branch_created ) end - end + } end end end diff --git a/lib/gitlab/git/patches/collection.rb b/lib/gitlab/git/patches/collection.rb index ad6b5d32abc..5830ef2eeb4 100644 --- a/lib/gitlab/git/patches/collection.rb +++ b/lib/gitlab/git/patches/collection.rb @@ -7,9 +7,9 @@ module Gitlab MAX_PATCH_SIZE = 2.megabytes def initialize(one_or_more_patches) - @patches = Array(one_or_more_patches).map do |patch_content| + @patches = Array(one_or_more_patches).map { |patch_content| Gitlab::Git::Patches::Patch.new(patch_content) - end + } end def content diff --git a/lib/gitlab/git/path_helper.rb b/lib/gitlab/git/path_helper.rb index e3a2031eeca..68c8b52b546 100644 --- a/lib/gitlab/git/path_helper.rb +++ b/lib/gitlab/git/path_helper.rb @@ -8,11 +8,11 @@ module Gitlab class << self def normalize_path(filename) # Strip all leading slashes so that //foo -> foo - filename = filename.sub(%r{\A/*}, '') + filename = filename.sub(%r{\A/*}, "") # Expand relative paths (e.g. foo/../bar) filename = Pathname.new(filename) - filename.relative_path_from(Pathname.new('')) + filename.relative_path_from(Pathname.new("")) end end end diff --git a/lib/gitlab/git/pre_receive_error.rb b/lib/gitlab/git/pre_receive_error.rb index 03caace6fce..8fd378bf571 100644 --- a/lib/gitlab/git/pre_receive_error.rb +++ b/lib/gitlab/git/pre_receive_error.rb @@ -7,7 +7,7 @@ module Gitlab # in the web UI. To prevent XSS we sanitize the message on # initialization. class PreReceiveError < StandardError - def initialize(msg = '') + def initialize(msg = "") super(nlbr(msg)) end diff --git a/lib/gitlab/git/push.rb b/lib/gitlab/git/push.rb index b6577ba17f1..def088616dc 100644 --- a/lib/gitlab/git/push.rb +++ b/lib/gitlab/git/push.rb @@ -44,7 +44,7 @@ module Gitlab def modified_paths unless branch_updated? - raise ArgumentError, 'Unable to calculate modified paths!' + raise ArgumentError, "Unable to calculate modified paths!" end strong_memoize(:modified_paths) do diff --git a/lib/gitlab/git/raw_diff_change.rb b/lib/gitlab/git/raw_diff_change.rb index e1002af40f6..43aac9d3508 100644 --- a/lib/gitlab/git/raw_diff_change.rb +++ b/lib/gitlab/git/raw_diff_change.rb @@ -29,7 +29,7 @@ module Gitlab # When a file has been renamed: # 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee def parse(raw_change) - @blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4) + @blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(" ", 4) @blob_size = @blob_size.to_i @operation = extract_operation @old_path, @new_path = extract_paths(raw_paths) @@ -52,17 +52,17 @@ module Gitlab return :unknown unless @raw_operation case @raw_operation[0] - when 'A' + when "A" :added - when 'C' + when "C" :copied - when 'D' + when "D" :deleted - when 'M' + when "M" :modified - when 'R' + when "R" :renamed - when 'T' + when "T" :type_changed else :unknown diff --git a/lib/gitlab/git/ref.rb b/lib/gitlab/git/ref.rb index eec91194949..ea0d162ec59 100644 --- a/lib/gitlab/git/ref.rb +++ b/lib/gitlab/git/ref.rb @@ -23,21 +23,19 @@ module Gitlab # Ex. # Ref.extract_branch_name('refs/heads/master') #=> 'master' def self.extract_branch_name(str) - str.gsub(%r{\Arefs/heads/}, '') + str.gsub(%r{\Arefs/heads/}, "") end def initialize(repository, name, target, dereferenced_target) @name = Gitlab::Git.ref_name(name) @dereferenced_target = dereferenced_target @target = if target.respond_to?(:oid) - target.oid - elsif target.respond_to?(:name) - target.name - elsif target.is_a? String - target - else - nil - end + target.oid + elsif target.respond_to?(:name) + target.name + elsif target.is_a? String + target + end end end end diff --git a/lib/gitlab/git/remote_repository.rb b/lib/gitlab/git/remote_repository.rb index 234541d8145..2f03330d5ef 100644 --- a/lib/gitlab/git/remote_repository.rb +++ b/lib/gitlab/git/remote_repository.rb @@ -54,18 +54,18 @@ module Gitlab end def fetch_env - gitaly_ssh = File.absolute_path(File.join(Gitlab.config.gitaly.client_path, 'gitaly-ssh')) + gitaly_ssh = File.absolute_path(File.join(Gitlab.config.gitaly.client_path, "gitaly-ssh")) gitaly_address = gitaly_client.address(storage) gitaly_token = gitaly_client.token(storage) request = Gitaly::SSHUploadPackRequest.new(repository: gitaly_repository) env = { - 'GITALY_ADDRESS' => gitaly_address, - 'GITALY_PAYLOAD' => request.to_json, - 'GITALY_WD' => Dir.pwd, - 'GIT_SSH_COMMAND' => "#{gitaly_ssh} upload-pack" + "GITALY_ADDRESS" => gitaly_address, + "GITALY_PAYLOAD" => request.to_json, + "GITALY_WD" => Dir.pwd, + "GIT_SSH_COMMAND" => "#{gitaly_ssh} upload-pack", } - env['GITALY_TOKEN'] = gitaly_token if gitaly_token.present? + env["GITALY_TOKEN"] = gitaly_token if gitaly_token.present? env end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index aea132a3dd9..9f6580c1c81 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'tempfile' -require 'forwardable' +require "tempfile" +require "forwardable" require "rubygems/package" module Gitlab @@ -17,11 +17,11 @@ module Gitlab # In https://gitlab.com/gitlab-org/gitaly/merge_requests/698 # We copied these two prefixes into gitaly-go, so don't change these # or things will break! (REBASE_WORKTREE_PREFIX and SQUASH_WORKTREE_PREFIX) - REBASE_WORKTREE_PREFIX = 'rebase'.freeze - SQUASH_WORKTREE_PREFIX = 'squash'.freeze - GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'.freeze + REBASE_WORKTREE_PREFIX = "rebase" + SQUASH_WORKTREE_PREFIX = "squash" + GITALY_INTERNAL_URL = "ssh://gitaly/internal.git" GITLAB_PROJECTS_TIMEOUT = Gitlab.config.gitlab_shell.git_timeout - EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000'.freeze + EMPTY_REPOSITORY_CHECKSUM = "0000000000000000000000000000000000000000" NoRepository = Class.new(StandardError) InvalidRepository = Class.new(StandardError) @@ -35,7 +35,7 @@ module Gitlab class << self def create_hooks(repo_path, global_hooks_path) - local_hooks_path = File.join(repo_path, 'hooks') + local_hooks_path = File.join(repo_path, "hooks") real_local_hooks_path = :not_found begin @@ -50,7 +50,8 @@ module Gitlab # Move the existing hooks somewhere safe FileUtils.mv( local_hooks_path, - "#{local_hooks_path}.old.#{Time.now.to_i}") + "#{local_hooks_path}.old.#{Time.now.to_i}" + ) end # Create the hooks symlink @@ -74,7 +75,7 @@ module Gitlab # has to be performed on the object pools to update the remote names. # Else the pool can't be updated anymore and is left in an inconsistent # state. - alias_method :object_pool_remote_name, :gl_repository + alias object_pool_remote_name gl_repository # This initializer method is only used on the client side (gitlab-ce). # Gitaly-ruby uses a different initializer. @@ -91,7 +92,7 @@ module Gitlab other.is_a?(self.class) && [storage, relative_path] == [other.storage, other.relative_path] end - alias_method :eql?, :== + alias eql? == def hash [self.class, storage, relative_path].hash @@ -168,7 +169,7 @@ module Gitlab # /refs/git-as-svn/* # /refs/pulls/* # This refs by default not visible in project page and not cloned to client side. - alias_method :has_visible_content?, :has_local_branches? + alias has_visible_content? has_local_branches? # Returns the number of valid tags def tag_count @@ -238,10 +239,10 @@ module Gitlab prefix = archive_prefix(ref, commit.id, project_path, append_sha: append_sha) { - 'ArchivePrefix' => prefix, - 'ArchivePath' => archive_file_path(storage_path, commit.id, prefix, format), - 'CommitId' => commit.id, - 'GitalyRepository' => gitaly_repository.to_h + "ArchivePrefix" => prefix, + "ArchivePath" => archive_file_path(storage_path, commit.id, prefix, format), + "CommitId" => commit.id, + "GitalyRepository" => gitaly_repository.to_h, } end @@ -250,12 +251,12 @@ module Gitlab def archive_prefix(ref, sha, project_path, append_sha:) append_sha = (ref != sha) if append_sha.nil? - formatted_ref = ref.tr('/', '-') + formatted_ref = ref.tr("/", "-") prefix_segments = [project_path, formatted_ref] prefix_segments << sha if append_sha - prefix_segments.join('-') + prefix_segments.join("-") end private :archive_prefix @@ -291,7 +292,7 @@ module Gitlab end file_name = "#{name}.#{extension}" - File.join(storage_path, self.gl_repository, sha, file_name) + File.join(storage_path, gl_repository, sha, file_name) end private :archive_file_path @@ -321,7 +322,7 @@ module Gitlab skip_merges: false, after: nil, before: nil, - all: false + all: false, } options = default_options.merge(options) @@ -417,9 +418,9 @@ module Gitlab return [] unless root_sha - branches = wrapped_gitaly_errors do + branches = wrapped_gitaly_errors { gitaly_merged_branch_names(branch_names, root_sha) - end + } Set.new(branches) end @@ -439,9 +440,9 @@ module Gitlab return empty_diff_stats end - stats = wrapped_gitaly_errors do + stats = wrapped_gitaly_errors { gitaly_commit_client.diff_stats(left_id, right_id) - end + } Gitlab::Git::DiffStatsCollection.new(stats) rescue CommandError, TypeError @@ -581,7 +582,7 @@ module Gitlab branch_name: branch_name, message: message, start_branch_name: start_branch_name, - start_repository: start_repository + start_repository: start_repository, } wrapped_gitaly_errors do @@ -596,7 +597,7 @@ module Gitlab branch_name: branch_name, message: message, start_branch_name: start_branch_name, - start_repository: start_repository + start_repository: start_repository, } wrapped_gitaly_errors do @@ -610,7 +611,7 @@ module Gitlab submodule: submodule, commit_sha: commit_sha, branch: branch, - message: message + message: message, } wrapped_gitaly_errors do @@ -753,7 +754,7 @@ module Gitlab end # Refactoring aid; allows us to copy code from app/models/repository.rb - def commit(ref = 'HEAD') + def commit(ref = "HEAD") Gitlab::Git::Commit.find(self, ref) end @@ -818,10 +819,10 @@ module Gitlab def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:) wrapped_gitaly_errors do gitaly_operation_client.user_rebase(user, rebase_id, - branch: branch, - branch_sha: branch_sha, - remote_repository: remote_repository, - remote_branch: remote_branch) + branch: branch, + branch_sha: branch_sha, + remote_repository: remote_repository, + remote_branch: remote_branch) end end @@ -834,7 +835,7 @@ module Gitlab def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:) wrapped_gitaly_errors do gitaly_operation_client.user_squash(user, squash_id, branch, - start_sha, end_sha, author, message) + start_sha, end_sha, author, message) end end @@ -855,12 +856,13 @@ module Gitlab def multi_action( user, branch_name:, message:, actions:, author_email: nil, author_name: nil, - start_branch_name: nil, start_repository: self) + start_branch_name: nil, start_repository: self + ) wrapped_gitaly_errors do gitaly_operation_client.user_commit_files(user, branch_name, - message, actions, author_email, author_name, - start_branch_name, start_repository) + message, actions, author_email, author_name, + start_branch_name, start_repository) end end @@ -868,9 +870,9 @@ module Gitlab return unless full_path.present? # This guard avoids Gitaly log/error spam - raise NoRepository, 'repository does not exist' unless exists? + raise NoRepository, "repository does not exist" unless exists? - set_config('gitlab.fullpath' => full_path) + set_config("gitlab.fullpath" => full_path) end def set_config(entries) @@ -925,7 +927,7 @@ module Gitlab Rails.logger.error("Unable to clean repository on storage #{storage} with relative path #{relative_path}: #{e.message}") Gitlab::Metrics.counter( :failed_repository_cleanup_total, - 'Number of failed repository cleanup events' + "Number of failed repository cleanup events" ).increment end @@ -1038,12 +1040,12 @@ module Gitlab return unless commit_object && commit_object.type == :COMMIT - gitmodules = gitaly_commit_client.tree_entry(ref, '.gitmodules', Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) + gitmodules = gitaly_commit_client.tree_entry(ref, ".gitmodules", Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) return unless gitmodules found_module = GitmodulesParser.new(gitmodules.data).parse[path] - found_module && found_module['url'] + found_module && found_module["url"] end # Returns true if the given ref name exists diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb index 23d989ff258..881061760d9 100644 --- a/lib/gitlab/git/tag.rb +++ b/lib/gitlab/git/tag.rb @@ -68,7 +68,7 @@ module Gitlab return @raw_tag.message.dup if full_message_fetched_from_gitaly? if @raw_tag.message_size > MAX_TAG_MESSAGE_DISPLAY_SIZE - '--tag message is too big' + "--tag message is too big" else self.class.get_message(@repository, target) end diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb index 51542bcaaa2..60e066e268e 100644 --- a/lib/gitlab/git/tree.rb +++ b/lib/gitlab/git/tree.rb @@ -16,7 +16,7 @@ module Gitlab # # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/320 def where(repository, sha, path = nil, recursive = false) - path = nil if path == '' || path == '/' + path = nil if path == "" || path == "/" wrapped_gitaly_errors do repository.gitaly_commit_client.tree_entries(repository, sha, path, recursive) @@ -38,17 +38,17 @@ module Gitlab # def find_id_by_path(repository, root_id, path) root_tree = repository.lookup(root_id) - path_arr = path.split('/') + path_arr = path.split("/") - entry = root_tree.find do |entry| + entry = root_tree.find { |entry| entry[:name] == path_arr[0] && entry[:type] == :tree - end + } return nil unless entry if path_arr.size > 1 path_arr.shift - find_id_by_path(repository, entry[:oid], path_arr.join('/')) + find_id_by_path(repository, entry[:oid], path_arr.join("/")) else entry[:oid] end @@ -56,8 +56,8 @@ module Gitlab end def initialize(options) - %w(id root_id name path flat_path type mode commit_id).each do |key| - self.send("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend + %w[id root_id name path flat_path type mode commit_id].each do |key| + send("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend end end diff --git a/lib/gitlab/git/util.rb b/lib/gitlab/git/util.rb index 03c2c1367b0..cf8571bf917 100644 --- a/lib/gitlab/git/util.rb +++ b/lib/gitlab/git/util.rb @@ -5,7 +5,7 @@ module Gitlab module Git module Util - LINE_SEP = "\n".freeze + LINE_SEP = "\n" def self.count_lines(string) case string[-1] diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index c43331bed60..9aa8c8ae8fd 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -10,21 +10,21 @@ module Gitlab DEFAULT_PAGINATION = Kaminari.config.default_per_page - CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do + CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) { def to_h - { user_id: user_id, username: username, name: name, email: email, message: message } + {user_id: user_id, username: username, name: name, email: email, message: message} end - end + } # GollumSlug inlines just enough knowledge from Gollum::Page to generate a # slug, which is used when previewing pages that haven't been persisted class GollumSlug class << self - def cname(name, char_white_sub = '-', char_other_sub = '-') + def cname(name, char_white_sub = "-", char_other_sub = "-") if name.respond_to?(:gsub) name.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub) else - '' + "" end end @@ -33,22 +33,22 @@ module Gitlab end def canonicalize_filename(filename) - ::File.basename(filename, ::File.extname(filename)).tr('-', ' ') + ::File.basename(filename, ::File.extname(filename)).tr("-", " ") end def generate(title, format) ext = format_to_ext(format.to_sym) - name = cname(title) + '.' + ext + name = cname(title) + "." + ext canonical_name = canonicalize_filename(name) path = - if name.include?('/') - name.sub(%r{/[^/]+$}, '/') + if name.include?("/") + name.sub(%r{/[^/]+$}, "/") else - '' + "" end - path + cname(canonical_name, '-', '-') + path + cname(canonical_name, "-", "-") end end end @@ -56,7 +56,7 @@ module Gitlab attr_reader :repository def self.default_ref - 'master' + "master" end # Initialize with a Gitlab::Git::Repository instance @@ -109,9 +109,9 @@ module Gitlab # :per_page - The number of items per page. # :limit - Total number of items to return. def page_versions(page_path, options = {}) - versions = wrapped_gitaly_errors do + versions = wrapped_gitaly_errors { gitaly_wiki_client.page_versions(page_path, options) - end + } # Gitaly uses gollum-lib to get the versions. Gollum defaults to 20 # per page, but also fetches 20 if `limit` or `per_page` < 20. @@ -121,7 +121,7 @@ module Gitlab end def count_page_versions(page_path) - @repository.count_commits(ref: 'HEAD', path: page_path) + @repository.count_commits(ref: "HEAD", path: page_path) end def preview_slug(title, format) |