diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-07-11 16:24:27 +0300 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2018-07-11 16:24:27 +0300 |
commit | 72156e83fcfee4a77b02fa8d6d201dfa6077486d (patch) | |
tree | 710583ac02034d5582196e9299f1b3a3d4b60d7e | |
parent | b647aeadb072489b7b2a8485fca9975085a54a8c (diff) |
Vendor gitlab-git at 49d7f92fd7476b4fb10e44f
-rwxr-xr-x | _support/vendor-gitlab-git | 2 | ||||
-rw-r--r-- | changelogs/unreleased/vendor-gitlab-git-20180710-jv.yml | 5 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 85 | ||||
-rwxr-xr-x | ruby/lib/gitlab/git/support/format-git-cat-file-input (renamed from ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input) | 0 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/REVISION | 2 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/encoding_helper.rb | 12 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb | 19 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb | 18 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/diff_collection.rb | 12 | ||||
-rw-r--r-- | ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb | 191 |
10 files changed, 139 insertions, 207 deletions
diff --git a/_support/vendor-gitlab-git b/_support/vendor-gitlab-git index a7b1c3745..abd8d947e 100755 --- a/_support/vendor-gitlab-git +++ b/_support/vendor-gitlab-git @@ -33,7 +33,7 @@ def main Dir.mktmpdir do |dir| gitlab_dir = File.join(dir, 'gitlab') - run!(%W[git clone --depth=1 -b #{revision} #{REMOTE}.git #{gitlab_dir}]) + run!(%W[git clone --quiet --depth=1 -b #{revision} #{REMOTE}.git #{gitlab_dir}]) revision_sha = capture!(%w[git rev-parse HEAD], gitlab_dir).chomp FileUtils.rm_rf(VENDOR_DIR) diff --git a/changelogs/unreleased/vendor-gitlab-git-20180710-jv.yml b/changelogs/unreleased/vendor-gitlab-git-20180710-jv.yml new file mode 100644 index 000000000..84af30a09 --- /dev/null +++ b/changelogs/unreleased/vendor-gitlab-git-20180710-jv.yml @@ -0,0 +1,5 @@ +--- +title: Vendor gitlab-git at 49d7f92fd7476b4fb10e44f +merge_request: 798 +author: +type: other diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 7a929d314..a8fc54b29 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -430,6 +430,25 @@ module Gitlab end end + def raw_log(options) + sha = + unless options[:all] + actual_ref = options[:ref] || root_ref + begin + sha_from_ref(actual_ref) + rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError + # Return an empty array if the ref wasn't found + return [] + end + end + + log_by_shell(sha, options) + end + + def fetch_source_branch!(source_repository, source_branch, local_ref) + rugged_fetch_source_branch(source_repository, source_branch, local_ref) + end + private def uncached_has_local_branches? @@ -448,6 +467,72 @@ module Gitlab sort_branches(branches, sort_by) end + + def log_by_shell(sha, options) + limit = options[:limit].to_i + offset = options[:offset].to_i + use_follow_flag = options[:follow] && options[:path].present? + + # We will perform the offset in Ruby because --follow doesn't play well with --skip. + # See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520 + offset_in_ruby = use_follow_flag && options[:offset].present? + limit += offset if offset_in_ruby + + cmd = %w[log] + cmd << "--max-count=#{limit}" + cmd << '--format=%H' + cmd << "--skip=#{offset}" unless offset_in_ruby + cmd << '--follow' if use_follow_flag + cmd << '--no-merges' if options[:skip_merges] + cmd << "--after=#{options[:after].iso8601}" if options[:after] + cmd << "--before=#{options[:before].iso8601}" if options[:before] + + if options[:all] + cmd += %w[--all --reverse] + else + cmd << sha + end + + # :path can be a string or an array of strings + if options[:path].present? + cmd << '--' + cmd += Array(options[:path]) + end + + raw_output, _status = run_git(cmd) + lines = offset_in_ruby ? raw_output.lines.drop(offset) : raw_output.lines + + lines.map! { |c| Rugged::Commit.new(rugged, c.strip) } + end + + def build_git_cmd(*args) + object_directories = alternate_object_directories.join(File::PATH_SEPARATOR) + + env = { 'PWD' => self.path } + env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories if object_directories.present? + + [ + env, + ::Gitlab.config.git.bin_path, + *args, + { chdir: self.path } + ] + end + + def git_diff_cmd(old_rev, new_rev) + old_rev = old_rev == ::Gitlab::Git::BLANK_SHA ? ::Gitlab::Git::EMPTY_TREE_ID : old_rev + + build_git_cmd('diff', old_rev, new_rev, '--raw') + end + + def git_cat_file_cmd + format = '%(objectname) %(objectsize) %(rest)' + build_git_cmd('cat-file', "--batch-check=#{format}") + end + + def format_git_cat_file_script + File.expand_path('../support/format-git-cat-file-input', __FILE__) + end end end end diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input b/ruby/lib/gitlab/git/support/format-git-cat-file-input index 2e93c646d..2e93c646d 100755 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/support/format-git-cat-file-input +++ b/ruby/lib/gitlab/git/support/format-git-cat-file-input diff --git a/ruby/vendor/gitlab_git/REVISION b/ruby/vendor/gitlab_git/REVISION index e1635629c..67a9ef530 100644 --- a/ruby/vendor/gitlab_git/REVISION +++ b/ruby/vendor/gitlab_git/REVISION @@ -1 +1 @@ -b14b31b819f0f09d73e001a80acd528aad913dc9 +49d7f92fd7476b4fb10e44ff92f36be99de0df49 diff --git a/ruby/vendor/gitlab_git/lib/gitlab/encoding_helper.rb b/ruby/vendor/gitlab_git/lib/gitlab/encoding_helper.rb index 0b8f6cfe3..d1fd5dfe0 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/encoding_helper.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/encoding_helper.rb @@ -65,17 +65,17 @@ module Gitlab clean(message) end rescue ArgumentError - return nil + nil end - def encode_binary(s) - return "" if s.nil? + def encode_binary(str) + return "" if str.nil? - s.dup.force_encoding(Encoding::ASCII_8BIT) + str.dup.force_encoding(Encoding::ASCII_8BIT) end - def binary_stringio(s) - StringIO.new(s || '').tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } + def binary_stringio(str) + StringIO.new(str || '').tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } end private diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb index 604bb11e7..96fa94d57 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/blob.rb @@ -50,13 +50,7 @@ module Gitlab end def raw(repository, sha) - Gitlab::GitalyClient.migrate(:git_blob_raw) do |is_enabled| - if is_enabled - repository.gitaly_blob_client.get_blob(oid: sha, limit: MAX_DATA_DISPLAY_SIZE) - else - rugged_raw(repository, sha, limit: MAX_DATA_DISPLAY_SIZE) - end - end + repository.gitaly_blob_client.get_blob(oid: sha, limit: MAX_DATA_DISPLAY_SIZE) end # Returns an array of Blob instances, specified in blob_references as @@ -207,16 +201,7 @@ module Gitlab return if @loaded_all_data - @data = Gitlab::GitalyClient.migrate(:git_blob_load_all_data) do |is_enabled| - begin - if is_enabled - repository.gitaly_blob_client.get_blob(oid: id, limit: -1).data - else - repository.lookup(id).content - end - end - end - + @data = repository.gitaly_blob_client.get_blob(oid: id, limit: -1).data @loaded_all_data = true @loaded_size = @data.bytesize end diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb index 36d56e411..4e2d817d1 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/commit.rb @@ -164,13 +164,8 @@ module Gitlab # relation to each other. The last 10 commits for a branch for example, # should go through .where def batch_by_oid(repo, oids) - repo.gitaly_migrate(:list_commits_by_oid, - status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| - if is_enabled - repo.gitaly_commit_client.list_commits_by_oid(oids) - else - oids.map { |oid| find(repo, oid) }.compact - end + repo.wrapped_gitaly_errors do + repo.gitaly_commit_client.list_commits_by_oid(oids) end end @@ -289,14 +284,7 @@ module Gitlab def deltas @deltas ||= begin - deltas = Gitlab::GitalyClient.migrate(:commit_deltas) do |is_enabled| - if is_enabled - @repository.gitaly_commit_client.commit_deltas(self) - else - rugged_diff_from_parent.each_delta - end - end - + deltas = @repository.gitaly_commit_client.commit_deltas(self) deltas.map { |delta| Gitlab::Git::Diff.new(delta) } end end diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/diff_collection.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/diff_collection.rb index 6a601561c..219c69893 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/diff_collection.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/diff_collection.rb @@ -42,12 +42,10 @@ module Gitlab return if @overflow return if @iterator.nil? - Gitlab::GitalyClient.migrate(:commit_raw_diffs) do |is_enabled| - if is_enabled && @iterator.is_a?(Gitlab::GitalyClient::DiffStitcher) - each_gitaly_patch(&block) - else - each_rugged_patch(&block) - end + if @iterator.is_a?(Gitlab::GitalyClient::DiffStitcher) + each_gitaly_patch(&block) + else + each_serialized_patch(&block) end @populated = true @@ -118,7 +116,7 @@ module Gitlab end end - def each_rugged_patch + def each_serialized_patch i = @array.length @iterator.each do |raw| diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb index bbfe6ab1d..a1a050647 100644 --- a/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb +++ b/ruby/vendor/gitlab_git/lib/gitlab/git/repository.rb @@ -439,31 +439,11 @@ module Gitlab raise ArgumentError.new("invalid Repository#log limit: #{limit.inspect}") end - gitaly_migrate(:find_commits) do |is_enabled| - if is_enabled - gitaly_commit_client.find_commits(options) - else - raw_log(options).map { |c| Commit.decorate(self, c) } - end + wrapped_gitaly_errors do + gitaly_commit_client.find_commits(options) end end - # Used in gitaly-ruby - def raw_log(options) - sha = - unless options[:all] - actual_ref = options[:ref] || root_ref - begin - sha_from_ref(actual_ref) - rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError - # Return an empty array if the ref wasn't found - return [] - end - end - - log_by_shell(sha, options) - end - def count_commits(options) options = process_count_commits_options(options.dup) @@ -555,13 +535,7 @@ module Gitlab # diff options. The +options+ hash can also include :break_rewrites to # split larger rewrites into delete/add pairs. def diff(from, to, options = {}, *paths) - iterator = gitaly_migrate(:diff_between) do |is_enabled| - if is_enabled - gitaly_commit_client.diff(from, to, options.merge(paths: paths)) - else - diff_patches(from, to, options, *paths) - end - end + iterator = gitaly_commit_client.diff(from, to, options.merge(paths: paths)) Gitlab::Git::DiffCollection.new(iterator, options) end @@ -651,7 +625,13 @@ module Gitlab end def update_branch(branch_name, user:, newrev:, oldrev:) - OperationService.new(user, self).update_branch(branch_name, newrev, oldrev) + gitaly_migrate(:operation_user_update_branch) do |is_enabled| + if is_enabled + gitaly_operation_client.user_update_branch(branch_name, user, newrev, oldrev) + else + OperationService.new(user, self).update_branch(branch_name, newrev, oldrev) + end + end end def rm_branch(branch_name, user:) @@ -924,12 +904,8 @@ module Gitlab end def fetch_source_branch!(source_repository, source_branch, local_ref) - Gitlab::GitalyClient.migrate(:fetch_source_branch) do |is_enabled| - if is_enabled - gitaly_repository_client.fetch_source_branch(source_repository, source_branch, local_ref) - else - rugged_fetch_source_branch(source_repository, source_branch, local_ref) - end + wrapped_gitaly_errors do + gitaly_repository_client.fetch_source_branch(source_repository, source_branch, local_ref) end end @@ -1084,18 +1060,13 @@ module Gitlab end def bundle_to_disk(save_path) - gitaly_migrate(:bundle_to_disk) do |is_enabled| - if is_enabled - gitaly_repository_client.create_bundle(save_path) - else - run_git!(%W(bundle create #{save_path} --all)) - end + wrapped_gitaly_errors do + gitaly_repository_client.create_bundle(save_path) end true end - # rubocop:disable Metrics/ParameterLists def multi_action( user, branch_name:, message:, actions:, author_email: nil, author_name: nil, @@ -1107,7 +1078,6 @@ module Gitlab start_branch_name, start_repository) end end - # rubocop:enable Metrics/ParameterLists def write_config(full_path:) return unless full_path.present? @@ -1115,8 +1085,18 @@ module Gitlab # This guard avoids Gitaly log/error spam raise NoRepository, 'repository does not exist' unless exists? + set_config('gitlab.fullpath' => full_path) + end + + def set_config(entries) wrapped_gitaly_errors do - gitaly_repository_client.write_config(full_path: full_path) + gitaly_repository_client.set_config(entries) + end + end + + def delete_config(*keys) + wrapped_gitaly_errors do + gitaly_repository_client.delete_config(keys) end end @@ -1219,12 +1199,10 @@ module Gitlab end def find_commits_by_message(query, ref, path, limit, offset) - gitaly_migrate(:commits_by_message) do |is_enabled| - if is_enabled - find_commits_by_message_by_gitaly(query, ref, path, limit, offset) - else - find_commits_by_message_by_shelling_out(query, ref, path, limit, offset) - end + wrapped_gitaly_errors do + gitaly_commit_client + .commits_by_message(query, revision: ref, path: path, limit: limit, offset: offset) + .map { |c| commit(c) } end end @@ -1234,12 +1212,8 @@ module Gitlab end def last_commit_for_path(sha, path) - gitaly_migrate(:last_commit_for_path) do |is_enabled| - if is_enabled - last_commit_for_path_by_gitaly(sha, path) - else - last_commit_for_path_by_rugged(sha, path) - end + wrapped_gitaly_errors do + gitaly_commit_client.last_commit_for_path(sha, path) end end @@ -1450,46 +1424,6 @@ module Gitlab end end - # Gitaly note: JV: although #log_by_shell shells out to Git I think the - # complexity is such that we should migrate it as Ruby before trying to - # do it in Go. - def log_by_shell(sha, options) - limit = options[:limit].to_i - offset = options[:offset].to_i - use_follow_flag = options[:follow] && options[:path].present? - - # We will perform the offset in Ruby because --follow doesn't play well with --skip. - # See: https://gitlab.com/gitlab-org/gitlab-ce/issues/3574#note_3040520 - offset_in_ruby = use_follow_flag && options[:offset].present? - limit += offset if offset_in_ruby - - cmd = %w[log] - cmd << "--max-count=#{limit}" - cmd << '--format=%H' - cmd << "--skip=#{offset}" unless offset_in_ruby - cmd << '--follow' if use_follow_flag - cmd << '--no-merges' if options[:skip_merges] - cmd << "--after=#{options[:after].iso8601}" if options[:after] - cmd << "--before=#{options[:before].iso8601}" if options[:before] - - if options[:all] - cmd += %w[--all --reverse] - else - cmd << sha - end - - # :path can be a string or an array of strings - if options[:path].present? - cmd << '--' - cmd += Array(options[:path]) - end - - raw_output, _status = run_git(cmd) - lines = offset_in_ruby ? raw_output.lines.drop(offset) : raw_output.lines - - lines.map! { |c| Rugged::Commit.new(rugged, c.strip) } - end - # We are trying to deprecate this method because it does a lot of work # but it seems to be used only to look up submodule URL's. # https://gitlab.com/gitlab-org/gitaly/issues/329 @@ -1619,11 +1553,6 @@ module Gitlab end end - def last_commit_for_path_by_rugged(sha, path) - sha = last_commit_id_for_path_by_shelling_out(sha, path) - commit(sha) - end - # Returns true if the given ref name exists # # Ref names must start with `refs/`. @@ -1816,35 +1745,6 @@ module Gitlab raise CommandError, @gitlab_projects.output end - def find_commits_by_message_by_shelling_out(query, ref, path, limit, offset) - ref ||= root_ref - - args = %W( - log #{ref} --pretty=%H --skip #{offset} - --max-count #{limit} --grep=#{query} --regexp-ignore-case - ) - args = args.concat(%W(-- #{path})) if path.present? - - git_log_results = run_git(args).first.lines - - git_log_results.map { |c| commit(c.chomp) }.compact - end - - def find_commits_by_message_by_gitaly(query, ref, path, limit, offset) - gitaly_commit_client - .commits_by_message(query, revision: ref, path: path, limit: limit, offset: offset) - .map { |c| commit(c) } - end - - def last_commit_for_path_by_gitaly(sha, path) - gitaly_commit_client.last_commit_for_path(sha, path) - end - - def last_commit_id_for_path_by_shelling_out(sha, path) - args = %W(rev-list --max-count=1 #{sha} -- #{path}) - run_git_with_timeout(args, Gitlab::Git::Popen::FAST_GIT_PROCESS_TIMEOUT).first.strip - end - def rugged_merge_base(from, to) rugged.merge_base(from, to) rescue Rugged::ReferenceError @@ -1858,35 +1758,6 @@ module Gitlab def sha_from_ref(ref) rev_parse_target(ref).oid end - - def build_git_cmd(*args) - object_directories = alternate_object_directories.join(File::PATH_SEPARATOR) - - env = { 'PWD' => self.path } - env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories if object_directories.present? - - [ - env, - ::Gitlab.config.git.bin_path, - *args, - { chdir: self.path } - ] - end - - def git_diff_cmd(old_rev, new_rev) - old_rev = old_rev == ::Gitlab::Git::BLANK_SHA ? ::Gitlab::Git::EMPTY_TREE_ID : old_rev - - build_git_cmd('diff', old_rev, new_rev, '--raw') - end - - def git_cat_file_cmd - format = '%(objectname) %(objectsize) %(rest)' - build_git_cmd('cat-file', "--batch-check=#{format}") - end - - def format_git_cat_file_script - File.expand_path('../support/format-git-cat-file-input', __FILE__) - end end end end |