Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cf09c826
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 搜索 >>
提交
cf09c826
编写于
5月 11, 2017
作者:
A
Alejandro Rodríguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Re-enable gitaly migration for ref_name_for_sha after bugfixes
上级
9a10a6bf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
33 deletion
+53
-33
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+13
-13
lib/gitlab/gitaly_client/ref.rb
lib/gitlab/gitaly_client/ref.rb
+1
-1
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+25
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+14
-19
未找到文件。
lib/gitlab/git/repository.rb
浏览文件 @
cf09c826
...
...
@@ -471,19 +471,19 @@ module Gitlab
# Returns a RefName for a given SHA
def
ref_name_for_sha
(
ref_path
,
sha
)
# NOTE: This feature is intentionally disabled until
# https://gitlab.com/gitlab-org/gitaly/issues/180 is resolved
#
gitaly_migrate(:find_ref_name) do |is_enabled|
#
if is_enabled
#
gitaly_ref_client.find_ref_name(sha, ref_path)
#
else
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
ref_path
}
--contains
#{
sha
}
)
# Not found -> ["", 0]
# Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
Gitlab
::
Popen
.
popen
(
args
,
@path
).
first
.
split
.
last
#
end
#
end
raise
ArgumentError
,
"sha can't be empty"
unless
sha
.
present?
gitaly_migrate
(
:find_ref_name
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_client
.
find_ref_name
(
sha
,
ref_path
)
else
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
ref_path
}
--contains
#{
sha
}
)
# Not found -> ["", 0]
# Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
Gitlab
::
Popen
.
popen
(
args
,
@path
).
first
.
split
.
last
end
end
end
# Returns commits collection
...
...
lib/gitlab/gitaly_client/ref.rb
浏览文件 @
cf09c826
...
...
@@ -28,7 +28,7 @@ module Gitlab
def
find_ref_name
(
commit_id
,
ref_prefix
)
request
=
Gitaly
::
FindRefNameRequest
.
new
(
repository:
@
repository
,
repository:
@
gitaly_repo
,
commit_id:
commit_id
,
prefix:
ref_prefix
)
...
...
spec/lib/gitlab/git/repository_spec.rb
浏览文件 @
cf09c826
...
...
@@ -26,6 +26,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
'with gitaly enabled'
do
before
{
stub_gitaly
}
after
{
Gitlab
::
GitalyClient
.
clear_stubs!
}
it
'gets the branch name from GitalyClient'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Ref
).
to
receive
(
:default_branch_name
)
...
...
@@ -120,6 +121,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
'with gitaly enabled'
do
before
{
stub_gitaly
}
after
{
Gitlab
::
GitalyClient
.
clear_stubs!
}
it
'gets the branch names from GitalyClient'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Ref
).
to
receive
(
:branch_names
)
...
...
@@ -157,6 +159,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context
'with gitaly enabled'
do
before
{
stub_gitaly
}
after
{
Gitlab
::
GitalyClient
.
clear_stubs!
}
it
'gets the tag names from GitalyClient'
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Ref
).
to
receive
(
:tag_names
)
...
...
@@ -1046,6 +1049,28 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#ref_name_for_sha'
do
let
(
:ref_path
)
{
'refs/heads'
}
let
(
:sha
)
{
repository
.
find_branch
(
'master'
).
dereferenced_target
.
id
}
let
(
:ref_name
)
{
'refs/heads/master'
}
it
'returns the ref name for the given sha'
do
expect
(
repository
.
ref_name_for_sha
(
ref_path
,
sha
)).
to
eq
(
ref_name
)
end
it
"returns an empty name if the ref doesn't exist"
do
expect
(
repository
.
ref_name_for_sha
(
ref_path
,
"000000"
)).
to
eq
(
""
)
end
it
"raise an exception if the ref is empty"
do
expect
{
repository
.
ref_name_for_sha
(
ref_path
,
""
)
}.
to
raise_error
(
ArgumentError
)
end
it
"raise an exception if the ref is nil"
do
expect
{
repository
.
ref_name_for_sha
(
ref_path
,
nil
)
}.
to
raise_error
(
ArgumentError
)
end
end
describe
'#find_commits'
do
it
'should return a return a collection of commits'
do
commits
=
repository
.
find_commits
...
...
spec/models/repository_spec.rb
浏览文件 @
cf09c826
...
...
@@ -110,22 +110,11 @@ describe Repository, models: true do
end
describe
'#ref_name_for_sha'
do
context
'ref found'
do
it
'returns the ref'
do
allow_any_instance_of
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
and_return
([
"b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit
\t
refs/environments/production/77
\n
"
,
0
])
it
'returns the ref'
do
allow
(
repository
.
raw_repository
).
to
receive
(
:ref_name_for_sha
).
and_return
(
'refs/environments/production/77'
)
expect
(
repository
.
ref_name_for_sha
(
'bla'
,
'0'
*
40
)).
to
eq
'refs/environments/production/77'
end
end
context
'ref not found'
do
it
'returns nil'
do
allow_any_instance_of
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
and_return
([
""
,
0
])
expect
(
repository
.
ref_name_for_sha
(
'bla'
,
'0'
*
40
)).
to
eq
nil
end
expect
(
repository
.
ref_name_for_sha
(
'bla'
,
'0'
*
40
)).
to
eq
'refs/environments/production/77'
end
end
...
...
@@ -1917,12 +1906,18 @@ describe Repository, models: true do
describe
'#is_ancestor?'
do
context
'Gitaly is_ancestor feature enabled'
do
it
"asks Gitaly server if it's an ancestor"
do
commit
=
repository
.
commit
expect
(
repository
.
raw_repository
).
to
receive
(
:is_ancestor?
).
and_call_original
let
(
:commit
)
{
repository
.
commit
}
let
(
:ancestor
)
{
commit
.
parents
.
first
}
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:enabled?
).
and_return
(
true
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
with
(
:is_ancestor
).
and_return
(
true
)
end
it
"asks Gitaly server if it's an ancestor"
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Commit
).
to
receive
(
:is_ancestor
).
with
(
ancestor
.
id
,
commit
.
id
)
expect
(
repository
.
is_ancestor?
(
commit
.
id
,
commit
.
id
)).
to
be
true
repository
.
is_ancestor?
(
ancestor
.
id
,
commit
.
id
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录