summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhttp://jneen.net/ <jneen@jneen.net>2017-08-21 15:20:44 -0700
committerhttp://jneen.net/ <jneen@jneen.net>2017-08-21 15:40:55 -0700
commit00b440443808fba04fc55f7e77c61f79e29c21ea (patch)
tree781641c942d3b69c90dd992502b204b826b0b5a3
parentc13f712c77e0837760e79293b6fb41c734741e77 (diff)
downloadgitlab-ce-00b440443808fba04fc55f7e77c61f79e29c21ea.tar.gz
skip the branch fetch if we already have the sha
-rw-r--r--app/models/repository.rb28
1 files changed, 16 insertions, 12 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 1c3080c0efd..61fab9764e8 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -991,23 +991,27 @@ class Repository
end
def with_repo_branch_commit(start_repository, start_branch_name)
- return yield(nil) if start_repository.empty_repo?
+ tmp_ref = nil
+ return yield nil if start_repository.empty_repo?
- branch_name_or_sha =
+ branch_commit =
if start_repository == self
- start_branch_name
+ commit(start_branch_name)
else
- tmp_ref = fetch_ref(
- start_repository.path_to_repo,
- "#{Gitlab::Git::BRANCH_REF_PREFIX}#{start_branch_name}",
- "refs/tmp/#{SecureRandom.hex}/head"
- )
-
- start_repository.commit(start_branch_name).sha
+ 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
end
- yield(commit(branch_name_or_sha))
-
+ yield branch_commit
ensure
rugged.references.delete(tmp_ref) if tmp_ref
end