diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-01-05 01:52:21 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-01-05 01:52:21 +0800 |
commit | 99ac0935271b1e99f4512e496104219045f1018e (patch) | |
tree | e79085e860ecd2adf281519e3e0bd5c9441a6ae6 /app/models/repository.rb | |
parent | 05d742a047cca3ded10e6e3a545e211a3592c89c (diff) | |
download | gitlab-ce-99ac0935271b1e99f4512e496104219045f1018e.tar.gz |
Introduce Repository#with_repo_branch_commit
We merge repository checks inside it so we don't have to
check it on the call site, and we could also load the commit
for the caller. This greatly reduce code duplication.
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_20572919
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 46995bdcb33..b1a789492d3 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1063,19 +1063,26 @@ class Repository Gitlab::Popen.popen(args, path_to_repo).first.lines.map(&:strip) end - def with_tmp_ref(source_repository, source_branch_name) - tmp_ref = "refs/tmp/#{SecureRandom.hex}/head" + def with_repo_branch_commit(source_repository, source_branch_name) + branch_name_or_sha = + if source_repository == self + source_branch_name + else + tmp_ref = "refs/tmp/#{SecureRandom.hex}/head" - fetch_ref( - source_repository.path_to_repo, - "#{Gitlab::Git::BRANCH_REF_PREFIX}#{source_branch_name}", - tmp_ref - ) + fetch_ref( + source_repository.path_to_repo, + "#{Gitlab::Git::BRANCH_REF_PREFIX}#{source_branch_name}", + tmp_ref + ) + + source_repository.commit(source_branch_name).sha + end - yield + yield(commit(branch_name_or_sha)) ensure - rugged.references.delete(tmp_ref) + rugged.references.delete(tmp_ref) if tmp_ref end def fetch_ref(source_path, source_ref, target_ref) |