Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
13992ac9
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,发现更多精彩内容 >>
未验证
提交
13992ac9
编写于
4月 05, 2018
作者:
D
Douglas Barbosa Alexandre
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Checksum calculation is handled by Gitaly when feature is enabled
上级
e892eeb5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
24 deletion
+50
-24
lib/gitlab/git/checksum.rb
lib/gitlab/git/checksum.rb
+19
-4
spec/lib/gitlab/git/checksum_spec.rb
spec/lib/gitlab/git/checksum_spec.rb
+31
-20
未找到文件。
lib/gitlab/git/checksum.rb
浏览文件 @
13992ac9
...
...
@@ -7,13 +7,14 @@ module Gitlab
Failure
=
Class
.
new
(
StandardError
)
attr_reader
:path
,
:relative_path
,
:storage
,
:storage_path
attr_reader
:path
,
:relative_path
,
:storage
,
:storage_path
,
:gl_repository
def
initialize
(
storage
,
relative_path
)
def
initialize
(
storage
,
relative_path
,
gl_repository
)
@storage
=
storage
@storage_path
=
Gitlab
.
config
.
repositories
.
storages
[
storage
].
legacy_disk_path
@relative_path
=
"
#{
relative_path
}
.git"
@path
=
File
.
join
(
storage_path
,
@relative_path
)
@gl_repository
=
gl_repository
end
def
calculate
...
...
@@ -21,7 +22,13 @@ module Gitlab
failure!
(
Gitlab
::
Git
::
Repository
::
NoRepository
,
'No repository for such path'
)
end
calculate_checksum_by_shelling_out
raw_repository
.
gitaly_migrate
(
:calculate_checksum
)
do
|
is_enabled
|
if
is_enabled
calculate_checksum_gitaly
else
calculate_checksum_by_shelling_out
end
end
end
private
...
...
@@ -30,6 +37,10 @@ module Gitlab
raw_repository
.
exists?
end
def
calculate_checksum_gitaly
gitaly_repository_client
.
calculate_checksum
end
def
calculate_checksum_by_shelling_out
args
=
%W(--git-dir=
#{
path
}
show-ref --heads --tags)
output
,
status
=
run_git
(
args
)
...
...
@@ -69,7 +80,11 @@ module Gitlab
end
def
raw_repository
Gitlab
::
Git
::
Repository
.
new
(
storage
,
relative_path
,
nil
)
@raw_repository
||=
Gitlab
::
Git
::
Repository
.
new
(
storage
,
relative_path
,
gl_repository
)
end
def
gitaly_repository_client
raw_repository
.
gitaly_repository_client
end
def
run_git
(
args
)
...
...
spec/lib/gitlab/git/checksum_spec.rb
浏览文件 @
13992ac9
...
...
@@ -2,37 +2,48 @@ require 'spec_helper'
describe
Gitlab
::
Git
::
Checksum
,
seed_helper:
true
do
let
(
:storage
)
{
'default'
}
let
(
:gl_repository
)
{
'project-123'
}
it
'raises Gitlab::Git::Repository::NoRepository when there is no repo'
do
checksum
=
described_class
.
new
(
storage
,
'nonexistent-repo'
)
shared_examples
'calculating checksum'
do
it
'raises Gitlab::Git::Repository::NoRepository when there is no repo'
do
checksum
=
described_class
.
new
(
storage
,
'nonexistent-repo'
,
gl_repository
)
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Repository
::
NoRepository
end
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Repository
::
NoRepository
end
it
'pretends that checksum is 000000... when the repo is empty'
do
FileUtils
.
rm_rf
(
File
.
join
(
SEED_STORAGE_PATH
,
'empty-repo.git'
))
it
'pretends that checksum is 000000... when the repo is empty'
do
FileUtils
.
rm_rf
(
File
.
join
(
SEED_STORAGE_PATH
,
'empty-repo.git'
))
system
(
git_env
,
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
init --bare empty-repo.git)
,
chdir:
SEED_STORAGE_PATH
,
out:
'/dev/null'
,
err:
'/dev/null'
)
system
(
git_env
,
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
init --bare empty-repo.git)
,
chdir:
SEED_STORAGE_PATH
,
out:
'/dev/null'
,
err:
'/dev/null'
)
checksum
=
described_class
.
new
(
storage
,
'empty-repo'
)
checksum
=
described_class
.
new
(
storage
,
'empty-repo'
,
gl_repository
)
expect
(
checksum
.
calculate
).
to
eq
'0000000000000000000000000000000000000000'
end
expect
(
checksum
.
calculate
).
to
eq
'0000000000000000000000000000000000000000'
end
it
'raises Gitlab::Git::Repository::Failure when shelling out to git return non-zero status
'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
)
it
'calculates the checksum when there is a repo
'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
,
gl_repository
)
allow
(
checksum
).
to
receive
(
:popen
).
and_return
([
'output'
,
nil
])
expect
(
checksum
.
calculate
).
to
eq
'54f21be4c32c02f6788d72207fa03ad3bce725e4'
end
end
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Checksum
::
Failure
context
'when calculate_checksum Gitaly feature is enabled'
do
it_behaves_like
'calculating checksum'
end
it
'calculates the checksum when there is a repo'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
)
context
'when calculate_checksum Gitaly feature is disabled'
,
:disable_gitaly
do
it_behaves_like
'calculating checksum'
it
"raises a Gitlab::Git::Repository::Failure error if the `popen` call to git returns a non-zero exit code"
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
,
gl_repository
)
allow
(
checksum
).
to
receive
(
:popen
).
and_return
([
'output'
,
nil
])
expect
(
checksum
.
calculate
).
to
eq
'54f21be4c32c02f6788d72207fa03ad3bce725e4'
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Checksum
::
Failure
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录