Commit c770d2f9 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Make more things mandatory

parent b62825fd
...@@ -164,13 +164,8 @@ module Gitlab ...@@ -164,13 +164,8 @@ module Gitlab
# relation to each other. The last 10 commits for a branch for example, # relation to each other. The last 10 commits for a branch for example,
# should go through .where # should go through .where
def batch_by_oid(repo, oids) def batch_by_oid(repo, oids)
repo.gitaly_migrate(:list_commits_by_oid, repo.wrapped_gitaly_errors do
status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| repo.gitaly_commit_client.list_commits_by_oid(oids)
if is_enabled
repo.gitaly_commit_client.list_commits_by_oid(oids)
else
oids.map { |oid| find(repo, oid) }.compact
end
end end
end end
...@@ -289,14 +284,7 @@ module Gitlab ...@@ -289,14 +284,7 @@ module Gitlab
def deltas def deltas
@deltas ||= begin @deltas ||= begin
deltas = Gitlab::GitalyClient.migrate(:commit_deltas) do |is_enabled| deltas = @repository.gitaly_commit_client.commit_deltas(self)
if is_enabled
@repository.gitaly_commit_client.commit_deltas(self)
else
rugged_diff_from_parent.each_delta
end
end
deltas.map { |delta| Gitlab::Git::Diff.new(delta) } deltas.map { |delta| Gitlab::Git::Diff.new(delta) }
end end
end end
......
...@@ -1858,35 +1858,6 @@ module Gitlab ...@@ -1858,35 +1858,6 @@ module Gitlab
def sha_from_ref(ref) def sha_from_ref(ref)
rev_parse_target(ref).oid rev_parse_target(ref).oid
end 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 end
end end
#!/usr/bin/env ruby
# This script formats the output of the `git diff <old_rev> <new_rev> --raw`
# command so it can be processed by `git cat-file`
# We need to convert this:
# ":100644 100644 5f53439... 85bc2f9... R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee"
# To:
# "85bc2f9 R\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee"
ARGF.each do |line|
_, _, old_blob_id, new_blob_id, rest = line.split(/\s/, 5)
old_blob_id.gsub!(/[^\h]/, '')
new_blob_id.gsub!(/[^\h]/, '')
# We can't pass '0000000...' to `git cat-file` given it will not return info about the deleted file
blob_id = new_blob_id =~ /\A0+\z/ ? old_blob_id : new_blob_id
$stdout.puts "#{blob_id} #{rest}"
end
...@@ -74,17 +74,10 @@ module Gitlab ...@@ -74,17 +74,10 @@ module Gitlab
relative_path = name.dup relative_path = name.dup
relative_path << '.git' unless relative_path.end_with?('.git') relative_path << '.git' unless relative_path.end_with?('.git')
gitaly_migrate(:create_repository, repository = Gitlab::Git::Repository.new(storage, relative_path, '')
status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| wrapped_gitaly_errors { repository.gitaly_repository_client.create_repository }
if is_enabled
repository = Gitlab::Git::Repository.new(storage, relative_path, '') true
repository.gitaly_repository_client.create_repository
true
else
repo_path = File.join(Gitlab.config.repositories.storages[storage].legacy_disk_path, relative_path)
Gitlab::Git::Repository.create(repo_path, bare: true, symlink_hooks_to: gitlab_shell_hooks_path)
end
end
rescue => err # Once the Rugged codes gets removes this can be improved rescue => err # Once the Rugged codes gets removes this can be improved
Rails.logger.error("Failed to add repository #{storage}/#{name}: #{err}") Rails.logger.error("Failed to add repository #{storage}/#{name}: #{err}")
false false
...@@ -448,7 +441,11 @@ module Gitlab ...@@ -448,7 +441,11 @@ module Gitlab
end end
def gitaly_migrate(method, status: Gitlab::GitalyClient::MigrationStatus::OPT_IN, &block) def gitaly_migrate(method, status: Gitlab::GitalyClient::MigrationStatus::OPT_IN, &block)
Gitlab::GitalyClient.migrate(method, status: status, &block) wrapped_gitaly_errors { Gitlab::GitalyClient.migrate(method, status: status, &block) }
end
def wrapped_gitaly_errors
yield
rescue GRPC::NotFound, GRPC::BadStatus => e rescue GRPC::NotFound, GRPC::BadStatus => e
# Old Popen code returns [Error, output] to the caller, so we # Old Popen code returns [Error, output] to the caller, so we
# need to do the same here... # need to do the same here...
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment