diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-18 12:06:23 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-09-18 12:06:23 +0300 |
commit | 2f594206e2f86e332b5d6ff0426ad966efef33b3 (patch) | |
tree | 533f4396f31dd3d65820ca990bfde5f21d22c476 /app/models | |
parent | d86bbe012644c672874ccd99d68847b751c4b635 (diff) | |
parent | 902b5347dcbb8d93d5b055d89d8d0414fdeade74 (diff) |
Merge branch 'operation-service-merge' into 'master'
Prepare Repository#merge for migration to Gitaly
Closes gitaly#559
See merge request gitlab-org/gitlab-ce!14154
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/repository.rb | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index f2b54705e7b..af9911ea045 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -768,17 +768,23 @@ class Repository multi_action(**options) end - def with_branch(user, *args) - result = Gitlab::Git::OperationService.new(user, raw_repository).with_branch(*args) do |start_commit| - yield start_commit - end + def with_cache_hooks + result = yield - newrev, should_run_after_create, should_run_after_create_branch = result + return unless result - after_create if should_run_after_create - after_create_branch if should_run_after_create_branch + after_create if result.repo_created? + after_create_branch if result.branch_created? - newrev + result.newrev + end + + def with_branch(user, *args) + with_cache_hooks do + Gitlab::Git::OperationService.new(user, raw_repository).with_branch(*args) do |start_commit| + yield start_commit + end + end end # rubocop:disable Metrics/ParameterLists @@ -843,30 +849,13 @@ class Repository end end - def merge(user, source, merge_request, options = {}) - with_branch( - user, - merge_request.target_branch) do |start_commit| - our_commit = start_commit.sha - their_commit = source - - raise 'Invalid merge target' unless our_commit - raise 'Invalid merge source' unless their_commit - - merge_index = rugged.merge_commits(our_commit, their_commit) - break if merge_index.conflicts? - - actual_options = options.merge( - parents: [our_commit, their_commit], - tree: merge_index.write_tree(rugged) - ) - - commit_id = create_commit(actual_options) - merge_request.update(in_progress_merge_commit_sha: commit_id) - commit_id + def merge(user, source_sha, merge_request, message) + with_cache_hooks do + raw_repository.merge(user, source_sha, merge_request.target_branch, message) do |commit_id| + merge_request.update(in_progress_merge_commit_sha: commit_id) + nil # Return value does not matter. + end end - rescue Gitlab::Git::CommitError # when merge_index.conflicts? - false end def revert( @@ -1157,12 +1146,6 @@ class Repository Gitlab::Metrics.add_event(event, { path: full_path }.merge(tags)) end - def create_commit(params = {}) - params[:message].delete!("\r") - - Rugged::Commit.create(rugged, params) - end - def last_commit_for_path_by_gitaly(sha, path) c = raw_repository.gitaly_commit_client.last_commit_for_path(sha, path) commit(c) |