diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-08-16 12:45:25 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-08-16 12:45:25 +0300 |
commit | e254014d3def5d4254f60b46a4e7cf6fcbc1248b (patch) | |
tree | 7ae25ab7775684b3ff1daa19257fe32307e71990 /lib | |
parent | fdd03d29cd23c2dff418bf458c12bf4a3652392e (diff) | |
parent | 5fc871381ad0768bb38879ab1621e538ca3008d0 (diff) |
Merge branch '34533-speed-up-project-creation' into 'master'
Speed up project creation by inlining repository creation
Closes #34533
See merge request !13529
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/shell.rb | 12 |
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 38772d06dbd..1d5ca68137a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -18,6 +18,28 @@ module Gitlab InvalidBlobName = Class.new(StandardError) InvalidRef = Class.new(StandardError) + class << self + # Unlike `new`, `create` takes the storage path, not the storage name + def create(storage_path, name, bare: true, symlink_hooks_to: nil) + repo_path = File.join(storage_path, name) + repo_path += '.git' unless repo_path.end_with?('.git') + + FileUtils.mkdir_p(repo_path, mode: 0770) + + # Equivalent to `git --git-path=#{repo_path} init [--bare]` + repo = Rugged::Repository.init_at(repo_path, bare) + repo.close + + if symlink_hooks_to.present? + hooks_path = File.join(repo_path, 'hooks') + FileUtils.rm_rf(hooks_path) + FileUtils.ln_s(symlink_hooks_to, hooks_path) + end + + true + end + end + # Full path to repo attr_reader :path diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index 0cb28732402..280a9abf03e 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -73,8 +73,10 @@ module Gitlab # # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/387 def add_repository(storage, name) - gitlab_shell_fast_execute([gitlab_shell_projects_path, - 'add-project', storage, "#{name}.git"]) + Gitlab::Git::Repository.create(storage, name, bare: true, symlink_hooks_to: gitlab_shell_hooks_path) + rescue => err + Rails.logger.error("Failed to add repository #{storage}/#{name}: #{err}") + false end # Import repository @@ -273,7 +275,11 @@ module Gitlab protected def gitlab_shell_path - Gitlab.config.gitlab_shell.path + File.expand_path(Gitlab.config.gitlab_shell.path) + end + + def gitlab_shell_hooks_path + File.expand_path(Gitlab.config.gitlab_shell.hooks_path) end def gitlab_shell_user_home |