diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-15 17:28:09 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-15 17:28:09 +0200 |
commit | 26f5d6047d6e21a5c65a4276266648f1e69aac4a (patch) | |
tree | 40e162779bf931dee297a7fdde325cd7bdf7b07b /app/services/compare_service.rb | |
parent | cb6f34e367a58d277c58d7861343af6e08d5508a (diff) | |
download | gitlab-ce-26f5d6047d6e21a5c65a4276266648f1e69aac4a.tar.gz |
Refactor compare and fetch logic
Diffstat (limited to 'app/services/compare_service.rb')
-rw-r--r-- | app/services/compare_service.rb | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index 4c8b35edff8..70f642baaaa 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -3,33 +3,26 @@ require 'securerandom' # Compare 2 branches for one repo or between repositories # and return Gitlab::CompareResult object that responds to commits and diffs class CompareService - def execute(current_user, source_project, source_branch, target_project, target_branch) - # Try to compare branches to get commits list and diffs - if target_project == source_project - Gitlab::CompareResult.new( - Gitlab::Git::Compare.new( - target_project.repository.raw_repository, - target_branch, - source_branch, - ) - ) - else + def execute(source_project, source_branch, target_project, target_branch) + source_sha = source_project.commit(source_branch).sha + + # If compare with other project we need to fetch ref first + unless target_project == source_project random_string = SecureRandom.hex + target_project.repository.fetch_ref( source_project.repository.path_to_repo, "refs/heads/#{source_branch}", "refs/tmp/#{random_string}/head" ) + end - source_sha = source_project.commit(source_branch).sha - - Gitlab::CompareResult.new( - Gitlab::Git::Compare.new( - target_project.repository.raw_repository, - target_branch, - source_sha, - ) + Gitlab::CompareResult.new( + Gitlab::Git::Compare.new( + target_project.repository.raw_repository, + target_branch, + source_sha, ) - end + ) end end |