Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ec78d29a
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,发现更多精彩内容 >>
未验证
提交
ec78d29a
编写于
6月 28, 2018
作者:
Z
Zeger-Jan van de Weg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FindAllCommits mandatory
Closes
https://gitlab.com/gitlab-org/gitaly/issues/326
上级
eaa9d4fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
115 deletion
+38
-115
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+2
-49
spec/lib/gitlab/git/commit_spec.rb
spec/lib/gitlab/git/commit_spec.rb
+36
-66
未找到文件。
lib/gitlab/git/commit.rb
浏览文件 @
ec78d29a
...
...
@@ -149,58 +149,11 @@ module Gitlab
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/326
def
find_all
(
repo
,
options
=
{})
Gitlab
::
GitalyClient
.
migrate
(
:find_all_commits
)
do
|
is_enabled
|
if
is_enabled
find_all_by_gitaly
(
repo
,
options
)
else
find_all_by_rugged
(
repo
,
options
)
end
repo
.
wrapped_gitaly_errors
do
Gitlab
::
GitalyClient
::
CommitService
.
new
(
repo
).
find_all_commits
(
options
)
end
end
def
find_all_by_rugged
(
repo
,
options
=
{})
actual_options
=
options
.
dup
allowed_options
=
[
:ref
,
:max_count
,
:skip
,
:order
]
actual_options
.
keep_if
do
|
key
|
allowed_options
.
include?
(
key
)
end
default_options
=
{
skip:
0
}
actual_options
=
default_options
.
merge
(
actual_options
)
rugged
=
repo
.
rugged
walker
=
Rugged
::
Walker
.
new
(
rugged
)
if
actual_options
[
:ref
]
walker
.
push
(
rugged
.
rev_parse_oid
(
actual_options
[
:ref
]))
else
rugged
.
references
.
each
(
"refs/heads/*"
)
do
|
ref
|
walker
.
push
(
ref
.
target_id
)
end
end
walker
.
sorting
(
rugged_sort_type
(
actual_options
[
:order
]))
commits
=
[]
offset
=
actual_options
[
:skip
]
limit
=
actual_options
[
:max_count
]
walker
.
each
(
offset:
offset
,
limit:
limit
)
do
|
commit
|
commits
.
push
(
decorate
(
repo
,
commit
))
end
walker
.
reset
commits
rescue
Rugged
::
OdbError
[]
end
def
find_all_by_gitaly
(
repo
,
options
=
{})
Gitlab
::
GitalyClient
::
CommitService
.
new
(
repo
).
find_all_commits
(
options
)
end
def
decorate
(
repository
,
commit
,
ref
=
nil
)
Gitlab
::
Git
::
Commit
.
new
(
repository
,
commit
,
ref
)
end
...
...
spec/lib/gitlab/git/commit_spec.rb
浏览文件 @
ec78d29a
...
...
@@ -331,84 +331,54 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
describe
'.find_all'
do
shared_examples
'finding all commits'
do
it
'should return a return a collection of commits'
do
commits
=
described_class
.
find_all
(
repository
)
it
'should return a return a collection of commits'
do
commits
=
described_class
.
find_all
(
repository
)
expect
(
commits
).
to
all
(
be_a_kind_of
(
described_class
)
)
end
context
'max_count'
do
subject
do
commits
=
described_class
.
find_all
(
repository
,
max_count:
50
)
commits
.
map
(
&
:id
)
end
expect
(
commits
).
to
all
(
be_a_kind_of
(
described_class
)
)
end
it
'has 34 elements'
do
expect
(
subject
.
size
).
to
eq
(
34
)
end
context
'max_count'
do
subject
do
commits
=
described_class
.
find_all
(
repository
,
max_count:
50
)
it
'includes the expected commits'
do
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
Commit
::
PARENT_ID
,
SeedRepo
::
FirstCommit
::
ID
)
end
commits
.
map
(
&
:id
)
end
context
'ref + max_count + skip'
do
subject
do
commits
=
described_class
.
find_all
(
repository
,
ref:
'master'
,
max_count:
50
,
skip:
1
)
commits
.
map
(
&
:id
)
end
it
'has 24 elements'
do
expect
(
subject
.
size
).
to
eq
(
24
)
end
it
'includes the expected commits'
do
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
FirstCommit
::
ID
)
expect
(
subject
).
not_to
include
(
SeedRepo
::
LastCommit
::
ID
)
end
it
'has 34 elements'
do
expect
(
subject
.
size
).
to
eq
(
34
)
end
end
context
'when Gitaly find_all_commits feature is enabled'
do
it_behaves_like
'finding all commits'
it
'includes the expected commits'
do
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
Commit
::
PARENT_ID
,
SeedRepo
::
FirstCommit
::
ID
)
end
end
context
'when Gitaly find_all_commits feature is disabled'
,
:skip_gitaly_mock
do
it_behaves_like
'finding all commits'
context
'while applying a sort order based on the `order` option'
do
it
"allows ordering topologically (no parents shown before their children)"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_TOPO
)
described_class
.
find_all
(
repository
,
order: :topo
)
end
it
"allows ordering by date"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_DATE
|
Rugged
::
SORT_TOPO
)
context
'ref + max_count + skip'
do
subject
do
commits
=
described_class
.
find_all
(
repository
,
ref:
'master'
,
max_count:
50
,
skip:
1
)
described_class
.
find_all
(
repository
,
order: :date
)
end
commits
.
map
(
&
:id
)
end
it
"applies no sorting by default"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_NONE
)
it
'has 24 elements'
do
expect
(
subject
.
size
).
to
eq
(
24
)
end
described_class
.
find_all
(
repository
)
end
it
'includes the expected commits'
do
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
FirstCommit
::
ID
)
expect
(
subject
).
not_to
include
(
SeedRepo
::
LastCommit
::
ID
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录