diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-04 10:56:26 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-04 10:56:26 +0000 |
commit | dabce2c571d105cc20bb132d0d8c848592e9aa15 (patch) | |
tree | be5a84bb9ed7c6c3365e35396e62b8cf4ec80f1b /app/services | |
parent | a6f9470b4aff72d78520eb8c7ed9a1f88ac0aa0e (diff) | |
parent | 129d6bf2de3195263553e706d1ecbb04ebb71441 (diff) | |
download | gitlab-ce-dabce2c571d105cc20bb132d0d8c848592e9aa15.tar.gz |
Merge branch 'git-operation-service-to-git' into 'master'
Prepare GitOperationService for moving to Gitlab::Git
See merge request !13773
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/compare_service.rb | 22 | ||||
-rw-r--r-- | app/services/git_operation_service.rb | 27 |
2 files changed, 18 insertions, 31 deletions
diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index a5ae4927412..53f16a236d2 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -11,26 +11,8 @@ class CompareService end def execute(target_project, target_branch, straight: false) - # If compare with other project we need to fetch ref first - target_project.repository.with_repo_branch_commit( - start_project.repository, - start_branch_name) do |commit| - break unless commit + raw_compare = target_project.repository.compare_source_branch(target_branch, start_project.repository, start_branch_name, straight: straight) - compare(commit.sha, target_project, target_branch, straight: straight) - end - end - - private - - def compare(source_sha, target_project, target_branch, straight:) - raw_compare = Gitlab::Git::Compare.new( - target_project.repository.raw_repository, - target_branch, - source_sha, - straight: straight - ) - - Compare.new(raw_compare, target_project, straight: straight) + Compare.new(raw_compare, target_project, straight: straight) if raw_compare end end diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb index 6b7a56e6922..b484e9f6f2b 100644 --- a/app/services/git_operation_service.rb +++ b/app/services/git_operation_service.rb @@ -5,6 +5,11 @@ class GitOperationService committer = Gitlab::Git::Committer.from_user(committer) if committer.is_a?(User) @committer = committer + # Refactoring aid + unless new_repository.is_a?(Gitlab::Git::Repository) + raise "expected a Gitlab::Git::Repository, got #{new_repository}" + end + @repository = new_repository end @@ -55,10 +60,14 @@ class GitOperationService def with_branch( branch_name, start_branch_name: nil, - start_project: repository.project, + start_repository: repository, &block) - start_repository = start_project.repository + # Refactoring aid + unless start_repository.is_a?(Gitlab::Git::Repository) + raise "expected a Gitlab::Git::Repository, got #{start_repository}" + end + start_branch_name = nil if start_repository.empty_repo? if start_branch_name && !start_repository.branch_exists?(start_branch_name) @@ -75,6 +84,7 @@ class GitOperationService private + # Returns [newrev, should_run_after_create, should_run_after_create_branch] def update_branch_with_hooks(branch_name) update_autocrlf_option @@ -93,12 +103,7 @@ class GitOperationService ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name update_ref_in_hooks(ref, newrev, oldrev) - # If repo was empty expire cache - repository.after_create if was_empty - repository.after_create_branch if - was_empty || Gitlab::Git.blank_ref?(oldrev) - - newrev + [newrev, was_empty, was_empty || Gitlab::Git.blank_ref?(oldrev)] end def find_oldrev_from_branch(newrev, branch) @@ -140,7 +145,7 @@ class GitOperationService command = %W[#{Gitlab.config.git.bin_path} update-ref --stdin -z] _, status = Gitlab::Popen.popen( command, - repository.path_to_repo) do |stdin| + repository.path) do |stdin| stdin.write("update #{ref}\x00#{newrev}\x00#{oldrev}\x00") end @@ -152,8 +157,8 @@ class GitOperationService end def update_autocrlf_option - if repository.raw_repository.autocrlf != :input - repository.raw_repository.autocrlf = :input + if repository.autocrlf != :input + repository.autocrlf = :input end end end |