diff options
author | Oswaldo Ferreira <> | 2019-04-19 04:00:41 +0300 |
---|---|---|
committer | Oswaldo Ferreira <> | 2019-04-19 22:01:49 +0300 |
commit | 976d373ac1dbe2c0584b254492c6bd8fac738b65 (patch) | |
tree | 9e863962babdf86cedfb803c3dad2f529cba77ff /lib/gitlab/git | |
parent | 1ac4b24dd3153acd1fa7a66f6261911ee74ce734 (diff) |
Make use of local ref if it is reachable
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r-- | lib/gitlab/git/repository.rb | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index d7f5720c795..c12cb6a6434 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -732,20 +732,27 @@ module Gitlab end def compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:) - if source_repository == self - return Gitlab::Git::Compare.new(self, target_branch_name, source_branch_name, straight: straight) - end + reachable_ref = + if source_repository == self + source_branch_name + else + # If a tmp ref was created before for a separate repo comparison (forks), + # we're able to short-circuit the tmp ref re-creation: + # 1. Take the SHA from the source repo + # 2. Read that in the current "target" repo + # 3. If that SHA is still known (readable), it means GC hasn't + # cleaned it up yet, so we can use it instead re-writing the tmp ref. + source_commit_id = source_repository.commit(source_branch_name)&.sha + commit(source_commit_id)&.sha if source_commit_id + end + + return compare(target_branch_name, reachable_ref, straight: straight) if reachable_ref tmp_ref = "refs/tmp/#{SecureRandom.hex}" return unless fetch_source_branch!(source_repository, source_branch_name, tmp_ref) - Gitlab::Git::Compare.new( - self, - target_branch_name, - tmp_ref, - straight: straight - ) + compare(target_branch_name, tmp_ref, straight: straight) ensure delete_refs(tmp_ref) if tmp_ref end @@ -1003,6 +1010,13 @@ module Gitlab private + def compare(base_ref, head_ref, straight:) + Gitlab::Git::Compare.new(self, + base_ref, + head_ref, + straight: straight) + end + def empty_diff_stats Gitlab::Git::DiffStatsCollection.new([]) end |