diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-01 22:16:26 +0300 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2016-09-06 03:05:39 +0300 |
commit | f6af87fb5f355247e14ef4d23db923fe4e7bbcc5 (patch) | |
tree | 98dfb30c27b41dfe4761be2124b940a5c4298521 /app | |
parent | d950556be80154f7a2e12521e8e86b41cc1e212d (diff) |
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')
-rw-r--r-- | app/models/repository.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index bdc3b9d1c1c..14e55b8c953 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) |