summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-11-12 13:47:48 +0100
committerDouwe Maan <douwe@gitlab.com>2015-11-18 12:02:09 +0100
commit8937c5ff7adb309f7b52a3ecf7dfe3181e2ceb1b (patch)
treecdca8c997b56953c9fd96c24e7235a5241654c15
parentd0ec28827d33d00ca637b1962b370313701ac3a0 (diff)
downloadgitlab-ce-8937c5ff7adb309f7b52a3ecf7dfe3181e2ceb1b.tar.gz
Load raw repository lazily to recover from failed read
-rw-r--r--app/models/repository.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index fd60c7edbb1..c1836103463 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -6,7 +6,7 @@ class Repository
include Gitlab::ShellAdapter
- attr_accessor :raw_repository, :path_with_namespace, :project
+ attr_accessor :path_with_namespace, :project
def self.clean_old_archives
repository_downloads_path = Gitlab.config.gitlab.repository_downloads_path
@@ -19,14 +19,18 @@ class Repository
def initialize(path_with_namespace, default_branch = nil, project = nil)
@path_with_namespace = path_with_namespace
@project = project
+ end
- if path_with_namespace
- @raw_repository = Gitlab::Git::Repository.new(path_to_repo)
- @raw_repository.autocrlf = :input
- end
+ def raw_repository
+ return nil unless path_with_namespace
- rescue Gitlab::Git::Repository::NoRepository
- nil
+ @raw_repository ||= begin
+ repo = Gitlab::Git::Repository.new(path_to_repo)
+ repo.autocrlf = :input
+ repo
+ rescue Gitlab::Git::Repository::NoRepository
+ nil
+ end
end
# Return absolute path to repository