Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-24 10:27:33 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-24 10:27:33 +0300
commitfb7d8db46af60bebec09dfaef354ec2facff5828 (patch)
treefeec5850d001ba38d485f0c59aae1abfd61d0047
parent06910935523c37b6dfcf582fd17524eda77bf516 (diff)
parent1ff9080e0fad7e924981f698bea99e57aa973f73 (diff)
Merge branch 'pks-ruby-drop-ported-rpcs' into 'master'
ruby: Drop ported RPCs See merge request gitlab-org/gitaly!3167
-rw-r--r--ruby/lib/gitaly_server/operations_service.rb41
-rw-r--r--ruby/lib/gitaly_server/repository_service.rb8
-rw-r--r--ruby/lib/gitlab/git/repository.rb147
-rw-r--r--ruby/spec/lib/gitlab/git/repository_spec.rb235
4 files changed, 4 insertions, 427 deletions
diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb
index 063a4a660..ca0543ea2 100644
--- a/ruby/lib/gitaly_server/operations_service.rb
+++ b/ruby/lib/gitaly_server/operations_service.rb
@@ -82,47 +82,6 @@ module GitalyServer
Gitaly::UserUpdateBranchResponse.new(pre_receive_error: set_utf8!(ex.message))
end
- def user_merge_to_ref(request, call)
- repo = Gitlab::Git::Repository.from_gitaly(request.repository, call)
- user = Gitlab::Git::User.from_gitaly(request.user)
-
- commit_id = repo.merge_to_ref(user, request.source_sha, request.branch, request.target_ref, request.message.dup, request.first_parent_ref, request.allow_conflicts)
-
- Gitaly::UserMergeToRefResponse.new(commit_id: commit_id)
- rescue Gitlab::Git::CommitError => e
- raise GRPC::FailedPrecondition.new(e.to_s)
- rescue ArgumentError => e
- raise GRPC::InvalidArgument.new(e.to_s)
- rescue Gitlab::Git::PreReceiveError => e
- Gitaly::UserMergeToRefResponse.new(pre_receive_error: set_utf8!(e.message))
- end
-
- def user_merge_branch(session, call)
- Enumerator.new do |y|
- first_request = session.next
-
- repository = Gitlab::Git::Repository.from_gitaly(first_request.repository, call)
- user = Gitlab::Git::User.from_gitaly(first_request.user)
- source_sha = first_request.commit_id.dup
- target_branch = first_request.branch.dup
- message = first_request.message.dup
- timestamp = first_request.timestamp
-
- begin
- result = repository.merge(user, source_sha, target_branch, message, timestamp) do |commit_id|
- y << Gitaly::UserMergeBranchResponse.new(commit_id: commit_id)
-
- second_request = session.next
- raise GRPC::FailedPrecondition.new('merge aborted by client') unless second_request.apply
- end
-
- y << Gitaly::UserMergeBranchResponse.new(branch_update: branch_update_result(result))
- rescue Gitlab::Git::PreReceiveError => e
- y << Gitaly::UserMergeBranchResponse.new(pre_receive_error: set_utf8!(e.message))
- end
- end
- end
-
def user_ff_branch(request, call)
repo = Gitlab::Git::Repository.from_gitaly(request.repository, call)
user = Gitlab::Git::User.from_gitaly(request.user)
diff --git a/ruby/lib/gitaly_server/repository_service.rb b/ruby/lib/gitaly_server/repository_service.rb
index 9707862b6..d4861ec69 100644
--- a/ruby/lib/gitaly_server/repository_service.rb
+++ b/ruby/lib/gitaly_server/repository_service.rb
@@ -4,14 +4,6 @@ module GitalyServer
class RepositoryService < Gitaly::RepositoryService::Service
include Utils
- def fetch_source_branch(request, call)
- source_repository = Gitlab::Git::GitalyRemoteRepository.new(request.source_repository, call)
- repository = Gitlab::Git::Repository.from_gitaly(request.repository, call)
- result = repository.fetch_source_branch!(source_repository, request.source_branch, request.target_ref)
-
- Gitaly::FetchSourceBranchResponse.new(result: result)
- end
-
def set_config(request, call)
repo = Gitlab::Git::Repository.from_gitaly(request.repository, call)
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index e248ad774..9408abcbf 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -82,10 +82,6 @@ module Gitlab
[storage, relative_path] == [other.storage, other.relative_path]
end
- def feature_enabled?(flag, on_by_default: false)
- @feature_flags.enabled?(flag, on_by_default: on_by_default)
- end
-
def add_branch(branch_name, user:, target:, transaction: nil)
target_object = Ref.dereference_object(lookup(target))
raise InvalidRef, "target not found: #{target}" unless target_object
@@ -259,40 +255,6 @@ module Gitlab
tags.find { |tag| tag.name.b == name_b }
end
- def merge_to_ref(user, source_sha, branch, target_ref, message, first_parent_ref, allow_conflicts = false)
- ref = if first_parent_ref.present?
- find_ref(first_parent_ref)
- else
- find_branch(branch)
- end
-
- raise InvalidRef unless ref
-
- OperationService.new(user, self).commit_ref(target_ref, source_sha, from_ref: ref) do
- our_commit = ref.target
- their_commit = source_sha
-
- create_merge_commit(user, our_commit, their_commit, message, nil, allow_conflicts)
- end
- rescue Rugged::ReferenceError, InvalidRef
- raise ArgumentError, 'Invalid merge source'
- end
-
- def merge(user, source_sha, target_branch, message, timestamp = nil)
- OperationService.new(user, self).with_branch(target_branch) do |start_commit|
- our_commit = start_commit.sha
- their_commit = source_sha
-
- commit_id = create_merge_commit(user, our_commit, their_commit, message, timestamp)
-
- yield commit_id
-
- commit_id
- end
- rescue Gitlab::Git::CommitError # when merge_index.conflicts?
- nil
- end
-
def ff_merge(user, source_sha, target_branch)
OperationService.new(user, self).with_branch(target_branch) do |our_commit|
raise ArgumentError, 'Invalid merge target' unless our_commit
@@ -358,7 +320,7 @@ module Gitlab
# rubocop:disable Metrics/ParameterLists
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: nil, timestamp: nil)
worktree = Gitlab::Git::Worktree.new(path, REBASE_WORKTREE_PREFIX, rebase_id)
- env = git_env.merge(user.git_env(timestamp))
+ env = user.git_env(timestamp)
with_repo_branch_commit(remote_repository, remote_branch) do |commit|
diff_range = "#{commit.sha}...#{branch}"
@@ -390,17 +352,16 @@ module Gitlab
def commit_patches(start_point, patches, extra_env: {})
worktree = Gitlab::Git::Worktree.new(path, AM_WORKTREE_PREFIX, SecureRandom.hex)
- env = git_env.merge(extra_env)
- with_worktree(worktree, start_point, env: env) do
- result, status = run_git(%w[am --quiet --3way], chdir: worktree.path, env: env) do |stdin|
+ with_worktree(worktree, start_point, env: extra_env) do
+ result, status = run_git(%w[am --quiet --3way], chdir: worktree.path, env: extra_env) do |stdin|
loop { stdin.write(patches.next) }
end
raise Gitlab::Git::PatchError, result unless status == 0
run_git!(
- %w[rev-parse --quiet --verify HEAD], chdir: worktree.path, env: env
+ %w[rev-parse --quiet --verify HEAD], chdir: worktree.path, env: extra_env
).chomp
end
end
@@ -491,10 +452,6 @@ module Gitlab
end
end
- def fetch_source_branch!(source_repository, source_branch, local_ref)
- rugged_fetch_source_branch(source_repository, source_branch, local_ref)
- end
-
# Directly find a branch with a simple name (e.g. master)
#
# force_reload causes a new Rugged repository to be instantiated
@@ -512,27 +469,10 @@ module Gitlab
end
end
- def find_ref(name)
- rugged_ref = rugged.references[name]
-
- return unless rugged_ref
-
- Gitlab::Git::Ref.new(self, rugged_ref.canonical_name, rugged_ref.target, rugged_ref.target_id)
- end
-
def delete_refs(*ref_names)
git_delete_refs(*ref_names)
end
- # Returns an Array of all ref names, except when it's matching pattern
- #
- # regexp - The pattern for ref names we don't want
- def all_ref_names_except(prefixes)
- rugged.references.reject do |ref|
- prefixes.any? { |p| ref.name.start_with?(p) }
- end.map(&:name)
- end
-
# Returns true if the given branch exists
#
# name - The name of the branch as a String.
@@ -557,19 +497,6 @@ module Gitlab
Gitlab::Git.committer_hash(email: user.email, name: user.name, timestamp: timestamp)
end
- def write_ref(ref_path, ref, old_ref: nil)
- raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ')
- raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00")
- raise ArgumentError, "invalid old_ref #{old_ref.inspect}" if !old_ref.nil? && old_ref.include?("\x00")
-
- if ref_path == 'HEAD'
- run_git!(%W[symbolic-ref #{ref_path} #{ref}])
- else
- input = "update #{ref_path}\x00#{ref}\x00#{old_ref}\x00"
- run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) }
- end
- end
-
# Fetch a commit from the given source repository
def fetch_sha(source_repository, sha)
source_repository = RemoteRepository.new(source_repository) unless source_repository.is_a?(RemoteRepository)
@@ -617,19 +544,6 @@ module Gitlab
remote_update(remote_name, url: url)
end
- def 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 usually go under
- # [remote_name]/) to the top level namespace. We clean the mapping so
- # those don't get deleted.
- rugged.config.delete("remote.#{remote_name}.fetch") if rugged.config["remote.#{remote_name}.mirror"]
-
- rugged.remotes.delete(remote_name)
- true
- rescue Rugged::ConfigError
- false
- end
-
# Update the specified remote using the values in the +options+ hash
#
# Example
@@ -695,41 +609,6 @@ module Gitlab
run_git!(%w[config core.sparseCheckout false], include_stderr: true)
end
- def create_merge_commit(user, our_commit, their_commit, message, timestamp = nil, allow_conflicts = false)
- raise 'Invalid merge target' unless our_commit
- raise 'Invalid merge source' unless their_commit
-
- committer = user_to_committer(user, timestamp)
-
- merge_index = rugged.merge_commits(our_commit, their_commit)
- process_conflicts(rugged, merge_index, allow_conflicts)
-
- return if merge_index.conflicts? # some conflicts are still unresolved
-
- options = {
- parents: [our_commit, their_commit],
- tree: merge_index.write_tree(rugged),
- author: committer,
- committer: committer,
- message: message
- }
-
- create_commit(options)
- end
-
- def process_conflicts(rugged, merge_index, allow_conflicts)
- return unless allow_conflicts
-
- merge_index.conflicts.each do |conflict|
- path = conflict[:ancestor][:path]
- file = merge_index.merge_file(path)
- merge_index.add(path: path, oid: rugged.write(file[:data], :blob), mode: file[:filemode])
- merge_index.conflict_remove(path)
- end
- rescue RuntimeError # conflicts cannot be resolved
- nil
- end
-
def run_git(args, chdir: path, env: {}, nice: false, include_stderr: false, lazy_block: nil, &block)
cmd = [Gitlab.config.git.bin_path, *args]
cmd.unshift("nice") if nice
@@ -748,13 +627,6 @@ module Gitlab
output
end
- def git_env
- {
- 'GL_PROTOCOL' => Gitlab::Git::Hook::GL_PROTOCOL,
- 'GL_REPOSITORY' => gl_repository
- }
- end
-
def check_revert_content(target_commit, source_sha)
args = [target_commit.sha, source_sha]
args << { mainline: 1 } if target_commit.merge_commit?
@@ -904,17 +776,6 @@ module Gitlab
File.write(File.join(worktree_info_path, 'sparse-checkout'), files)
end
- def rugged_fetch_source_branch(source_repository, source_branch, local_ref)
- with_repo_branch_commit(source_repository, source_branch) do |commit|
- if commit
- write_ref(local_ref, commit.sha)
- true
- else
- false
- end
- end
- end
-
def gitlab_projects_error
raise CommandError, @gitlab_projects.output
end
diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb
index 1e9cc78a1..ff2e84564 100644
--- a/ruby/spec/lib/gitlab/git/repository_spec.rb
+++ b/ruby/spec/lib/gitlab/git/repository_spec.rb
@@ -274,84 +274,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength
end
end
- describe '#fetch_source_branch!' do
- let(:local_ref) { 'refs/merge-requests/1/head' }
- let(:repository) { mutable_repository }
- let(:source_repository) { repository }
-
- context 'when the branch exists' do
- context 'when the commit does not exist locally' do
- let(:source_branch) { 'new-branch-for-fetch-source-branch' }
- let(:source_path) { File.join(DEFAULT_STORAGE_DIR, source_repository.relative_path) }
- let(:source_rugged) { Rugged::Repository.new(source_path) }
- let(:new_oid) { new_commit_edit_old_file(source_rugged).oid }
-
- before do
- source_rugged.branches.create(source_branch, new_oid)
- end
-
- it 'writes the ref' do
- expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true)
- expect(repository.commit(local_ref).sha).to eq(new_oid)
- end
- end
-
- context 'when the commit exists locally' do
- let(:source_branch) { 'master' }
- let(:expected_oid) { SeedRepo::LastCommit::ID }
-
- it 'writes the ref' do
- # Sanity check: the commit should already exist
- expect(repository.commit(expected_oid)).not_to be_nil
-
- expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true)
- expect(repository.commit(local_ref).sha).to eq(expected_oid)
- end
- end
- end
-
- context 'when the branch does not exist' do
- let(:source_branch) { 'definitely-not-master' }
-
- it 'does not write the ref' do
- expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(false)
- expect(repository.commit(local_ref)).to be_nil
- end
- end
- end
-
- describe '#write_ref' do
- let(:repository) { mutable_repository }
-
- context 'validations' do
- using RSpec::Parameterized::TableSyntax
-
- where(:ref_path, :ref) do
- 'foo bar' | '123'
- 'foobar' | "12\x003"
- end
-
- with_them do
- it 'raises ArgumentError' do
- expect { repository.write_ref(ref_path, ref) }.to raise_error(ArgumentError)
- end
- end
- end
-
- it 'writes the HEAD' do
- repository.write_ref('HEAD', 'refs/heads/feature')
-
- expect(repository.commit('HEAD')).to eq(repository.commit('feature'))
- expect(repository.root_ref).to eq('feature')
- end
-
- it 'writes other refs' do
- repository.write_ref('refs/heads/feature', SeedRepo::Commit::ID)
-
- expect(repository.commit('feature').sha).to eq(SeedRepo::Commit::ID)
- end
- end
-
describe '#fetch_sha' do
let(:source_repository) { Gitlab::Git::RemoteRepository.new(repository) }
let(:sha) { 'b971194ee2d047f24cb897b6fb0d7ae99c8dd0ca' }
@@ -382,97 +304,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength
end
end
- describe '#merge' do
- let(:repository) { mutable_repository }
- let(:source_sha) { '913c66a37b4a45b9769037c55c2d238bd0942d2e' }
- let(:target_branch) { 'test-merge-target-branch' }
-
- before do
- create_branch(repository, target_branch, '6d394385cf567f80a8fd85055db1ab4c5295806f')
- end
-
- it 'can perform a merge' do
- merge_commit_id = nil
- result = repository.merge(user, source_sha, target_branch, 'Test merge') do |commit_id|
- merge_commit_id = commit_id
- end
-
- expect(result.newrev).to eq(merge_commit_id)
- expect(result.repo_created).to eq(false)
- expect(result.branch_created).to eq(false)
- end
-
- it 'returns nil if there was a concurrent branch update' do
- concurrent_update_id = '33f3729a45c02fc67d00adb1b8bca394b0e761d9'
- result = repository.merge(user, source_sha, target_branch, 'Test merge') do
- # This ref update should make the merge fail
- repository.write_ref(Gitlab::Git::BRANCH_REF_PREFIX + target_branch, concurrent_update_id)
- end
-
- # This 'nil' signals that the merge was not applied
- expect(result).to be_nil
-
- # Our concurrent ref update should not have been undone
- expect(repository.find_branch(target_branch).target).to eq(concurrent_update_id)
- end
- end
-
- describe '#merge_to_ref' do
- let(:repository) { mutable_repository }
- let(:branch_head) { '6d394385cf567f80a8fd85055db1ab4c5295806f' }
- let(:source_sha) { 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660' }
- let(:branch) { 'test-master' }
- let(:first_parent_ref) { 'refs/heads/test-master' }
- let(:target_ref) { 'refs/merge-requests/999/merge' }
- let(:arg_branch) {}
- let(:arg_first_parent_ref) { first_parent_ref }
-
- before do
- create_branch(repository, branch, branch_head)
- end
-
- def fetch_target_ref
- repository.rugged.references[target_ref]
- end
-
- shared_examples_for 'correct behavior' do
- it 'changes target ref to a merge between source SHA and branch' do
- expect(fetch_target_ref).to be_nil
-
- merge_commit_id = repository.merge_to_ref(user, source_sha, arg_branch, target_ref, 'foo', arg_first_parent_ref)
-
- ref = fetch_target_ref
-
- expect(ref.target.oid).to eq(merge_commit_id)
- end
-
- it 'does not change the branch HEAD' do
- expect { repository.merge_to_ref(user, source_sha, arg_branch, target_ref, 'foo', arg_first_parent_ref) }
- .not_to change { repository.find_ref(first_parent_ref).target }
- .from(branch_head)
- end
- end
-
- it_behaves_like 'correct behavior'
-
- context 'when legacy branch parameter is specified and ref path is empty' do
- it_behaves_like 'correct behavior' do
- let(:arg_branch) { branch }
- let(:arg_first_parent_ref) {}
- end
- end
-
- context 'when conflicts detected' do
- it 'raises Gitlab::Git::CommitError' do
- allow(repository.rugged).to receive_message_chain(:merge_commits, :conflicts?) { true }
-
- expect { repository.merge_to_ref(user, source_sha, arg_branch, target_ref, 'foo', arg_first_parent_ref) }
- .to raise_error(Gitlab::Git::CommitError, "Failed to create merge commit for source_sha #{source_sha} and" \
- " target_sha #{branch_head} at #{target_ref}")
- end
- end
- end
-
describe '#ff_merge' do
let(:repository) { mutable_repository }
let(:branch_head) { '6d394385cf567f80a8fd85055db1ab4c5295806f' }
@@ -542,16 +373,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength
expect(repository_rugged.config["remote.#{remote_name}.fetch"]).to eq(mirror_refmap)
end
end
-
- describe '#remove_remote' do
- it 'removes the remote' do
- repository_rugged.remotes.create(remote_name, url)
-
- repository.remove_remote(remote_name)
-
- expect(repository_rugged.remotes[remote_name]).to be_nil
- end
- end
end
describe '#rebase' do
@@ -701,62 +522,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength
repository_rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha)
end
- # Build the options hash that's passed to Rugged::Commit#create
- def commit_options(repo, index, message)
- options = {}
- options[:tree] = index.write_tree(repo)
- options[:author] = {
- email: "test@example.com",
- name: "Test Author",
- time: Time.gm(2014, "mar", 3, 20, 15, 1)
- }
- options[:committer] = {
- email: "test@example.com",
- name: "Test Author",
- time: Time.gm(2014, "mar", 3, 20, 15, 1)
- }
- options[:message] ||= message
- options[:parents] = repo.empty? ? [] : [repo.head.target].compact
- options[:update_ref] = "HEAD"
-
- options
- end
-
- # Writes a new commit to the repo and returns a Rugged::Commit. Replaces the
- # contents of CHANGELOG with a single new line of text.
- def new_commit_edit_old_file(repo)
- oid = repo.write("I replaced the changelog with this text", :blob)
- index = repo.index
- index.read_tree(repo.head.target.tree)
- index.add(path: "CHANGELOG", oid: oid, mode: 0o100644)
-
- options = commit_options(
- repo,
- index,
- "Edit CHANGELOG in its original location"
- )
-
- sha = Rugged::Commit.create(repo, options)
- repo.lookup(sha)
- end
-
- # Writes a new commit to the repo and returns a Rugged::Commit. Moves the
- # CHANGELOG file to the encoding/ directory.
- def new_commit_move_file(repo)
- blob_oid = repo.head.target.tree.detect { |i| i[:name] == "CHANGELOG" }[:oid]
- file_content = repo.lookup(blob_oid).content
- oid = repo.write(file_content, :blob)
- index = repo.index
- index.read_tree(repo.head.target.tree)
- index.add(path: "encoding/CHANGELOG", oid: oid, mode: 0o100644)
- index.remove("CHANGELOG")
-
- options = commit_options(repo, index, "Move CHANGELOG to encoding/")
-
- sha = Rugged::Commit.create(repo, options)
- repo.lookup(sha)
- end
-
def create_branch(repository, branch_name, start_point = 'HEAD')
repository.rugged.branches.create(branch_name, start_point)
end