diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-12-08 17:57:52 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-12-08 17:57:52 +0800 |
commit | 8384d0d8d528ffdd60c9ba9e3c0c9f688cb560ef (patch) | |
tree | fb84cc230333c82d64b248f4fa83a0d5b8d49c24 /app/services/compare_service.rb | |
parent | 23032467d4a1282f69e76bba921bd71c0083f7a8 (diff) | |
download | gitlab-ce-8384d0d8d528ffdd60c9ba9e3c0c9f688cb560ef.tar.gz |
Introduce Repository#with_tmp_ref which we need
commits from the other repository. We'll cleanup
the tmp ref after we're done with our business.
Diffstat (limited to 'app/services/compare_service.rb')
-rw-r--r-- | app/services/compare_service.rb | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/app/services/compare_service.rb b/app/services/compare_service.rb index 5e8fafca98c..4367cb5f615 100644 --- a/app/services/compare_service.rb +++ b/app/services/compare_service.rb @@ -3,23 +3,29 @@ require 'securerandom' # Compare 2 branches for one repo or between repositories # and return Gitlab::Git::Compare object that responds to commits and diffs class CompareService - def execute(source_project, source_branch, target_project, target_branch, straight: false) - source_commit = source_project.commit(source_branch) - return unless source_commit + attr_reader :source_project, :source_sha - source_sha = source_commit.sha + def initialize(new_source_project, source_branch) + @source_project = new_source_project + @source_sha = new_source_project.commit(source_branch).try(:sha) + end - # If compare with other project we need to fetch ref first - unless target_project == source_project - random_string = SecureRandom.hex + def execute(target_project, target_branch, straight: false) + return unless source_sha - target_project.repository.fetch_ref( - source_project.repository.path_to_repo, - "refs/heads/#{source_branch}", - "refs/tmp/#{random_string}/head" - ) + # If compare with other project we need to fetch ref first + if target_project == source_project + compare(target_project, target_branch, straight) + else + target_project.repository.with_tmp_ref(source_project, source_branch) do + compare(target_project, target_branch, straight) + end end + end + + private + def compare(target_project, target_branch, straight) raw_compare = Gitlab::Git::Compare.new( target_project.repository.raw_repository, target_branch, |