diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-08-29 22:42:34 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-08-29 22:42:34 +0800 |
commit | 9d3ee1ff139650e064a41fd90d34cd3f558c1099 (patch) | |
tree | b77eb6c616567023a40b128c90cdd0c7f4a34467 /app | |
parent | e6630d7f7276dc5cec2a02e32dc74a0a060886ab (diff) | |
download | gitlab-ce-9d3ee1ff139650e064a41fd90d34cd3f558c1099.tar.gz |
Further break with_repo_branch_commit into partsperf.slow-issuable
So it's more clear what could happen. Also add
more tests about the behaviour.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 04a76c365be..93017dfedf9 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1000,29 +1000,22 @@ class Repository end def with_repo_branch_commit(start_repository, start_branch_name) - tmp_ref = nil return yield nil if start_repository.empty_repo? - branch_commit = - if start_repository == self - commit(start_branch_name) + if start_repository == self + yield commit(start_branch_name) + else + sha = start_repository.commit(start_branch_name).sha + + if branch_commit = commit(sha) + yield branch_commit else - sha = start_repository.find_branch(start_branch_name).target - commit(sha) || - begin - tmp_ref = fetch_ref( - start_repository.path_to_repo, - "#{Gitlab::Git::BRANCH_REF_PREFIX}#{start_branch_name}", - "refs/tmp/#{SecureRandom.hex}/head" - ) - - commit(start_repository.commit(start_branch_name).sha) - end + with_repo_tmp_commit( + start_repository, start_branch_name, sha) do |tmp_commit| + yield tmp_commit + end end - - yield branch_commit - ensure - rugged.references.delete(tmp_ref) if tmp_ref + end end def add_remote(name, url) @@ -1231,4 +1224,16 @@ class Repository .commits_by_message(query, revision: ref, path: path, limit: limit, offset: offset) .map { |c| commit(c) } end + + def with_repo_tmp_commit(start_repository, start_branch_name, sha) + tmp_ref = fetch_ref( + start_repository.path_to_repo, + "#{Gitlab::Git::BRANCH_REF_PREFIX}#{start_branch_name}", + "refs/tmp/#{SecureRandom.hex}/head" + ) + + yield commit(sha) + ensure + rugged.references.delete(tmp_ref) if tmp_ref + end end |