summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-09-01 19:16:26 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-09-01 19:16:26 +0000
commita9e28b3dfbbdaf4c0bba4cb5a4f7952ddca0a792 (patch)
tree0453f07d592cae8a3406988a7ede470e556ae47b /app/models
parenta26771926111b4d7bba13f974666aac85dab7a92 (diff)
parentd326d3428da89b943bb5f1d4d396f21b3e999ff7 (diff)
downloadgitlab-ce-a9e28b3dfbbdaf4c0bba4cb5a4f7952ddca0a792.tar.gz
Merge branch 'sh-reload-find-branch' into 'master'
Optimize branch lookups and force a repository reload for Repository#find_branch See merge request !6087
Diffstat (limited to 'app/models')
-rw-r--r--app/models/repository.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 91bdafdac99..f891e8374d2 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -120,8 +120,21 @@ class Repository
commits
end
- def find_branch(name)
- raw_repository.branches.find { |branch| branch.name == name }
+ def find_branch(name, fresh_repo: true)
+ # Since the Repository object may have in-memory index changes, invalidating the memoized Repository object may
+ # cause unintended side effects. Because finding a branch is a read-only operation, we can safely instantiate
+ # a new repo here to ensure a consistent state to avoid a libgit2 bug where concurrent access (e.g. via git gc)
+ # may cause the branch to "disappear" erroneously or have the wrong SHA.
+ #
+ # See: https://github.com/libgit2/libgit2/issues/1534 and https://gitlab.com/gitlab-org/gitlab-ce/issues/15392
+ raw_repo =
+ if fresh_repo
+ Gitlab::Git::Repository.new(path_to_repo)
+ else
+ raw_repository
+ end
+
+ raw_repo.find_branch(name)
end
def find_tag(name)