summaryrefslogtreecommitdiff
path: root/lib/gitlab/git
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-01-11 22:24:50 +0000
committerRobert Speicher <robert@gitlab.com>2018-01-11 22:24:50 +0000
commit587242656f57df997b7356f31369cc30d7a79f6c (patch)
tree9aee9eaf0b3ef4ade3be99cbef7729723dc274fd /lib/gitlab/git
parentb384d4781ada21ebb4bf8c703f59f188823b0ada (diff)
parent42265d445f88408501e89b0a9aa959fd6f8d3bcf (diff)
downloadgitlab-ce-587242656f57df997b7356f31369cc30d7a79f6c.tar.gz
Merge branch 'feature/migrate-rebase-to-gitaly' into 'master'
Migrate Gitlab::Git::Repository#rebase to Gitaly Closes gitaly#863 See merge request gitlab-org/gitlab-ce!16259
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r--lib/gitlab/git/repository.rb70
1 files changed, 48 insertions, 22 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 6ada9a145db..b294b7a5582 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1236,28 +1236,20 @@ module Gitlab
end
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
- rebase_path = worktree_path(REBASE_WORKTREE_PREFIX, rebase_id)
- env = git_env_for_user(user)
-
- if remote_repository.is_a?(RemoteRepository)
- env.merge!(remote_repository.fetch_env)
- remote_repo_path = GITALY_INTERNAL_URL
- else
- remote_repo_path = remote_repository.path
- end
-
- with_worktree(rebase_path, branch, env: env) do
- run_git!(
- %W(pull --rebase #{remote_repo_path} #{remote_branch}),
- chdir: rebase_path, env: env
- )
-
- rebase_sha = run_git!(%w(rev-parse HEAD), chdir: rebase_path, env: env).strip
-
- Gitlab::Git::OperationService.new(user, self)
- .update_branch(branch, rebase_sha, branch_sha)
-
- rebase_sha
+ gitaly_migrate(:rebase) do |is_enabled|
+ if is_enabled
+ gitaly_rebase(user, rebase_id,
+ branch: branch,
+ branch_sha: branch_sha,
+ remote_repository: remote_repository,
+ remote_branch: remote_branch)
+ else
+ git_rebase(user, rebase_id,
+ branch: branch,
+ branch_sha: branch_sha,
+ remote_repository: remote_repository,
+ remote_branch: remote_branch)
+ end
end
end
@@ -2039,6 +2031,40 @@ module Gitlab
tree_id
end
+ def gitaly_rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
+ gitaly_operation_client.user_rebase(user, rebase_id,
+ branch: branch,
+ branch_sha: branch_sha,
+ remote_repository: remote_repository,
+ remote_branch: remote_branch)
+ end
+
+ def git_rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:)
+ rebase_path = worktree_path(REBASE_WORKTREE_PREFIX, rebase_id)
+ env = git_env_for_user(user)
+
+ if remote_repository.is_a?(RemoteRepository)
+ env.merge!(remote_repository.fetch_env)
+ remote_repo_path = GITALY_INTERNAL_URL
+ else
+ remote_repo_path = remote_repository.path
+ end
+
+ with_worktree(rebase_path, branch, env: env) do
+ run_git!(
+ %W(pull --rebase #{remote_repo_path} #{remote_branch}),
+ chdir: rebase_path, env: env
+ )
+
+ rebase_sha = run_git!(%w(rev-parse HEAD), chdir: rebase_path, env: env).strip
+
+ Gitlab::Git::OperationService.new(user, self)
+ .update_branch(branch, rebase_sha, branch_sha)
+
+ rebase_sha
+ end
+ end
+
def local_fetch_ref(source_path, source_ref:, target_ref:)
args = %W(fetch --no-tags -f #{source_path} #{source_ref}:#{target_ref})
run_git(args)