Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
5fc87138
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5fc87138
编写于
8月 14, 2017
作者:
N
Nick Thomas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Speed up project creation by inlining repository creation
上级
4a2a6d52
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
15 deletion
+55
-15
.gitlab-ci.yml
.gitlab-ci.yml
+0
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+22
-0
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+9
-3
spec/lib/gitlab/shell_spec.rb
spec/lib/gitlab/shell_spec.rb
+24
-11
未找到文件。
.gitlab-ci.yml
浏览文件 @
5fc87138
...
...
@@ -474,7 +474,6 @@ db:rollback-mysql:
variables
:
SIZE
:
"
1"
SETUP_DB
:
"
false"
RAILS_ENV
:
"
development"
script
:
-
git clone https://gitlab.com/gitlab-org/gitlab-test.git
/home/git/repositories/gitlab-org/gitlab-test.git
...
...
lib/gitlab/git/repository.rb
浏览文件 @
5fc87138
...
...
@@ -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
...
...
lib/gitlab/shell.rb
浏览文件 @
5fc87138
...
...
@@ -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
...
...
spec/lib/gitlab/shell_spec.rb
浏览文件 @
5fc87138
...
...
@@ -94,28 +94,41 @@ describe Gitlab::Shell do
end
describe
'projects commands'
do
let
(
:projects_path
)
{
'tmp/tests/shell-projects-test/bin/gitlab-projects'
}
let
(
:gitlab_shell_path
)
{
File
.
expand_path
(
'tmp/tests/gitlab-shell'
)
}
let
(
:projects_path
)
{
File
.
join
(
gitlab_shell_path
,
'bin/gitlab-projects'
)
}
let
(
:gitlab_shell_hooks_path
)
{
File
.
join
(
gitlab_shell_path
,
'hooks'
)
}
before
do
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:path
).
and_return
(
'tmp/tests/shell-projects-test'
)
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:path
).
and_return
(
gitlab_shell_path
)
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:hooks_path
).
and_return
(
gitlab_shell_hooks_path
)
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:git_timeout
).
and_return
(
800
)
end
describe
'#add_repository'
do
it
'returns true when the command succeeds'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
projects_path
,
'add-project'
,
'current/storage'
,
'project/path.git'
],
nil
,
popen_vars
).
and_return
([
nil
,
0
])
it
'creates a repository'
do
created_path
=
File
.
join
(
TestEnv
.
repos_path
,
'project'
,
'path.git'
)
hooks_path
=
File
.
join
(
created_path
,
'hooks'
)
begin
result
=
gitlab_shell
.
add_repository
(
TestEnv
.
repos_path
,
'project/path'
)
repo_stat
=
File
.
stat
(
created_path
)
rescue
nil
hooks_stat
=
File
.
lstat
(
hooks_path
)
rescue
nil
hooks_dir
=
File
.
realpath
(
hooks_path
)
ensure
FileUtils
.
rm_rf
(
created_path
)
end
expect
(
gitlab_shell
.
add_repository
(
'current/storage'
,
'project/path'
)).
to
be
true
expect
(
result
).
to
be_truthy
expect
(
repo_stat
.
mode
&
0
o777
).
to
eq
(
0
o770
)
expect
(
hooks_stat
.
symlink?
).
to
be_truthy
expect
(
hooks_dir
).
to
eq
(
gitlab_shell_hooks_path
)
end
it
'returns false when the command fails'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
projects_path
,
'add-project'
,
'current/storage'
,
'project/path.git'
],
nil
,
popen_vars
).
and_return
([
"error"
,
1
])
expect
(
FileUtils
).
to
receive
(
:mkdir_p
).
and_raise
(
Errno
::
EEXIST
)
expect
(
gitlab_shell
.
add_repository
(
'current/storage'
,
'project/path'
)).
to
be
false
expect
(
gitlab_shell
.
add_repository
(
'current/storage'
,
'project/path'
)).
to
be
_falsy
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录