Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4378f56c
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 搜索 >>
提交
4378f56c
编写于
10月 05, 2017
作者:
A
Ahmad Sherif
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass git object dir attributes as relative paths to Gitaly
Fixes gitaly#629
上级
143ace07
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
70 addition
and
30 deletion
+70
-30
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
GITLAB_SHELL_VERSION
GITLAB_SHELL_VERSION
+1
-2
lib/gitlab/git/env.rb
lib/gitlab/git/env.rb
+4
-2
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+13
-1
lib/gitlab/gitaly_client/util.rb
lib/gitlab/gitaly_client/util.rb
+8
-2
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+39
-18
spec/lib/gitlab/gitaly_client/util_spec.rb
spec/lib/gitlab/gitaly_client/util_spec.rb
+4
-4
未找到文件。
GITALY_SERVER_VERSION
浏览文件 @
4378f56c
0.4
5.1
0.4
6.0
GITLAB_SHELL_VERSION
浏览文件 @
4378f56c
5.9.3
5.9.4
lib/gitlab/git/env.rb
浏览文件 @
4378f56c
...
...
@@ -11,9 +11,11 @@ module Gitlab
#
# This class is thread-safe via RequestStore.
class
Env
WHITELISTED_
GIT_
VARIABLES
=
%w[
WHITELISTED_VARIABLES
=
%w[
GIT_OBJECT_DIRECTORY
GIT_OBJECT_DIRECTORY_RELATIVE
GIT_ALTERNATE_OBJECT_DIRECTORIES
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
]
.
freeze
def
self
.
set
(
env
)
...
...
@@ -33,7 +35,7 @@ module Gitlab
end
def
self
.
whitelist_git_env
(
env
)
env
.
select
{
|
key
,
_
|
WHITELISTED_
GIT_
VARIABLES
.
include?
(
key
.
to_s
)
}.
with_indifferent_access
env
.
select
{
|
key
,
_
|
WHITELISTED_VARIABLES
.
include?
(
key
.
to_s
)
}.
with_indifferent_access
end
end
end
...
...
lib/gitlab/git/repository.rb
浏览文件 @
4378f56c
...
...
@@ -12,6 +12,10 @@ module Gitlab
GIT_OBJECT_DIRECTORY
GIT_ALTERNATE_OBJECT_DIRECTORIES
]
.
freeze
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES
=
%w[
GIT_OBJECT_DIRECTORY_RELATIVE
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
]
.
freeze
SEARCH_CONTEXT_LINES
=
3
NoRepository
=
Class
.
new
(
StandardError
)
...
...
@@ -1220,7 +1224,15 @@ module Gitlab
end
def
alternate_object_directories
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_DIRECTORIES_VARIABLES
).
compact
relative_paths
=
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_RELATIVE_DIRECTORIES_VARIABLES
).
flatten
.
compact
if
relative_paths
.
any?
relative_paths
.
map
{
|
d
|
File
.
join
(
path
,
d
)
}
else
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_DIRECTORIES_VARIABLES
)
.
compact
.
flat_map
{
|
d
|
d
.
split
(
File
::
PATH_SEPARATOR
)
}
end
end
# Get the content of a blob for a given commit. If the blob is a commit
...
...
lib/gitlab/gitaly_client/util.rb
浏览文件 @
4378f56c
...
...
@@ -3,12 +3,18 @@ module Gitlab
module
Util
class
<<
self
def
repository
(
repository_storage
,
relative_path
,
gl_repository
)
git_object_directory
=
Gitlab
::
Git
::
Env
[
'GIT_OBJECT_DIRECTORY_RELATIVE'
].
presence
||
Gitlab
::
Git
::
Env
[
'GIT_OBJECT_DIRECTORY'
].
presence
git_alternate_object_directories
=
Array
.
wrap
(
Gitlab
::
Git
::
Env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
]).
presence
||
Array
.
wrap
(
Gitlab
::
Git
::
Env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
]).
flat_map
{
|
d
|
d
.
split
(
File
::
PATH_SEPARATOR
)
}
Gitaly
::
Repository
.
new
(
storage_name:
repository_storage
,
relative_path:
relative_path
,
gl_repository:
gl_repository
,
git_object_directory:
Gitlab
::
Git
::
Env
[
'GIT_OBJECT_DIRECTORY'
]
.
to_s
,
git_alternate_object_directories:
Array
.
wrap
(
Gitlab
::
Git
::
Env
[
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
])
git_object_directory:
git_object_directory
.
to_s
,
git_alternate_object_directories:
git_alternate_object_directories
)
end
...
...
spec/lib/gitlab/git/repository_spec.rb
浏览文件 @
4378f56c
...
...
@@ -68,31 +68,52 @@ describe Gitlab::Git::Repository, seed_helper: true do
expect
{
broken_repo
.
rugged
}.
to
raise_error
(
Gitlab
::
Git
::
Repository
::
NoRepository
)
end
context
'with no Git env stored'
do
before
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({})
end
describe
'alternates keyword argument'
do
context
'with no Git env stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({})
end
it
"whitelist some variables and pass them via the alternates keyword argument
"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
[])
it
"is passed an empty array
"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
[])
repository
.
rugged
repository
.
rugged
end
end
end
context
'with some Git env stored'
do
before
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'bar'
,
'GIT_OTHER'
=>
'another_env'
})
context
'with absolute and relative Git object dir envvars stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY_RELATIVE'
=>
'./objects/foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'
=>
[
'./objects/bar'
,
'./objects/baz'
],
'GIT_OBJECT_DIRECTORY'
=>
'ignored'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'ignored:ignored'
,
'GIT_OTHER'
=>
'another_env'
})
end
it
"is passed the relative object dir envvars after being converted to absolute ones"
do
alternates
=
%w[foo bar baz]
.
map
{
|
d
|
File
.
join
(
repository
.
path
,
'./objects'
,
d
)
}
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
alternates
)
repository
.
rugged
end
end
it
"whitelist some variables and pass them via the alternates keyword argument"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
%w[foo bar]
)
context
'with only absolute Git object dir envvars stored'
do
before
do
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'bar:baz'
,
'GIT_OTHER'
=>
'another_env'
})
end
repository
.
rugged
it
"is passed the absolute object dir envvars as is"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
%w[foo bar baz]
)
repository
.
rugged
end
end
end
end
...
...
spec/lib/gitlab/gitaly_client/util_spec.rb
浏览文件 @
4378f56c
...
...
@@ -6,16 +6,16 @@ describe Gitlab::GitalyClient::Util do
let
(
:relative_path
)
{
'my/repo.git'
}
let
(
:gl_repository
)
{
'project-1'
}
let
(
:git_object_directory
)
{
'.git/objects'
}
let
(
:git_alternate_object_directory
)
{
'/dir/one:/dir/two'
}
let
(
:git_alternate_object_directory
)
{
[
'/dir/one'
,
'/dir/two'
]
}
subject
do
described_class
.
repository
(
repository_storage
,
relative_path
,
gl_repository
)
end
it
'creates a Gitaly::Repository with the given data'
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_OBJECT_DIRECTORY
'
)
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_OBJECT_DIRECTORY_RELATIVE
'
)
.
and_return
(
git_object_directory
)
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_ALTERNATE_OBJECT_DIRECTORIES
'
)
allow
(
Gitlab
::
Git
::
Env
).
to
receive
(
:[]
).
with
(
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
'
)
.
and_return
(
git_alternate_object_directory
)
expect
(
subject
).
to
be_a
(
Gitaly
::
Repository
)
...
...
@@ -23,7 +23,7 @@ describe Gitlab::GitalyClient::Util do
expect
(
subject
.
relative_path
).
to
eq
(
relative_path
)
expect
(
subject
.
gl_repository
).
to
eq
(
gl_repository
)
expect
(
subject
.
git_object_directory
).
to
eq
(
git_object_directory
)
expect
(
subject
.
git_alternate_object_directories
).
to
eq
(
[
git_alternate_object_directory
]
)
expect
(
subject
.
git_alternate_object_directories
).
to
eq
(
git_alternate_object_directory
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录