Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
144e37c6
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,发现更多精彩内容 >>
提交
144e37c6
编写于
6月 27, 2017
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove Gitlab::Git::Repository#find_all
上级
eacce60b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
103 addition
and
110 deletion
+103
-110
app/models/network/graph.rb
app/models/network/graph.rb
+1
-1
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+75
-2
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+0
-78
spec/lib/gitlab/git/commit_spec.rb
spec/lib/gitlab/git/commit_spec.rb
+27
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+0
-29
未找到文件。
app/models/network/graph.rb
浏览文件 @
144e37c6
...
...
@@ -113,7 +113,7 @@ module Network
opts
[
:ref
]
=
@commit
.
id
if
@filter_ref
@repo
.
find_commits
(
opts
)
Gitlab
::
Git
::
Commit
.
find_all
(
@repo
.
raw_repository
,
opts
)
end
def
commits_sort_by_ref
...
...
lib/gitlab/git/commit.rb
浏览文件 @
144e37c6
...
...
@@ -104,9 +104,68 @@ module Gitlab
[]
end
# Delegate Repository#find_commits
# Returns commits collection
#
# Ex.
# Commit.find_all(
# repo,
# ref: 'master',
# max_count: 10,
# skip: 5,
# order: :date
# )
#
# +options+ is a Hash of optional arguments to git
# :ref is the ref from which to begin (SHA1 or name)
# :contains is the commit contained by the refs from which to begin (SHA1 or name)
# :max_count is the maximum number of commits to fetch
# :skip is the number of commits to skip
# :order is the commits order and allowed value is :none (default), :date,
# :topo, or any combination of them (in an array). Commit ordering types
# are documented here:
# http://www.rubydoc.info/github/libgit2/rugged/Rugged#SORT_NONE-constant)
#
def
find_all
(
repo
,
options
=
{})
repo
.
find_commits
(
options
)
actual_options
=
options
.
dup
allowed_options
=
[
:ref
,
:max_count
,
:skip
,
:contains
,
: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
]))
elsif
actual_options
[
:contains
]
repo
.
branches_contains
(
actual_options
[
:contains
]).
each
do
|
branch
|
walker
.
push
(
branch
.
target_id
)
end
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
(
commit
))
end
walker
.
reset
commits
rescue
Rugged
::
OdbError
[]
end
def
decorate
(
commit
,
ref
=
nil
)
...
...
@@ -131,6 +190,20 @@ module Gitlab
diff
.
find_similar!
(
break_rewrites:
break_rewrites
)
diff
end
# Returns the `Rugged` sorting type constant for one or more given
# sort types. Valid keys are `:none`, `:topo`, and `:date`, or an array
# containing more than one of them. `:date` uses a combination of date and
# topological sorting to closer mimic git's native ordering.
def
rugged_sort_type
(
sort_type
)
@rugged_sort_types
||=
{
none:
Rugged
::
SORT_NONE
,
topo:
Rugged
::
SORT_TOPO
,
date:
Rugged
::
SORT_DATE
|
Rugged
::
SORT_TOPO
}
@rugged_sort_types
.
fetch
(
sort_type
,
Rugged
::
SORT_NONE
)
end
end
def
initialize
(
raw_commit
,
head
=
nil
)
...
...
lib/gitlab/git/repository.rb
浏览文件 @
144e37c6
...
...
@@ -494,70 +494,6 @@ module Gitlab
end
end
# Returns commits collection
#
# Ex.
# repo.find_commits(
# ref: 'master',
# max_count: 10,
# skip: 5,
# order: :date
# )
#
# +options+ is a Hash of optional arguments to git
# :ref is the ref from which to begin (SHA1 or name)
# :contains is the commit contained by the refs from which to begin (SHA1 or name)
# :max_count is the maximum number of commits to fetch
# :skip is the number of commits to skip
# :order is the commits order and allowed value is :none (default), :date,
# :topo, or any combination of them (in an array). Commit ordering types
# are documented here:
# http://www.rubydoc.info/github/libgit2/rugged/Rugged#SORT_NONE-constant)
#
def
find_commits
(
options
=
{})
actual_options
=
options
.
dup
allowed_options
=
[
:ref
,
:max_count
,
:skip
,
:contains
,
:order
]
actual_options
.
keep_if
do
|
key
|
allowed_options
.
include?
(
key
)
end
default_options
=
{
skip:
0
}
actual_options
=
default_options
.
merge
(
actual_options
)
walker
=
Rugged
::
Walker
.
new
(
rugged
)
if
actual_options
[
:ref
]
walker
.
push
(
rugged
.
rev_parse_oid
(
actual_options
[
:ref
]))
elsif
actual_options
[
:contains
]
branches_contains
(
actual_options
[
:contains
]).
each
do
|
branch
|
walker
.
push
(
branch
.
target_id
)
end
else
rugged
.
references
.
each
(
"refs/heads/*"
)
do
|
ref
|
walker
.
push
(
ref
.
target_id
)
end
end
sort_type
=
rugged_sort_type
(
actual_options
[
:order
])
walker
.
sorting
(
sort_type
)
commits
=
[]
offset
=
actual_options
[
:skip
]
limit
=
actual_options
[
:max_count
]
walker
.
each
(
offset:
offset
,
limit:
limit
)
do
|
commit
|
gitlab_commit
=
Gitlab
::
Git
::
Commit
.
decorate
(
commit
)
commits
.
push
(
gitlab_commit
)
end
walker
.
reset
commits
rescue
Rugged
::
OdbError
[]
end
# Returns branch names collection that contains the special commit(SHA1
# or name)
#
...
...
@@ -1228,20 +1164,6 @@ module Gitlab
rescue
GRPC
::
BadStatus
=>
e
raise
CommandError
.
new
(
e
)
end
# Returns the `Rugged` sorting type constant for one or more given
# sort types. Valid keys are `:none`, `:topo`, and `:date`, or an array
# containing more than one of them. `:date` uses a combination of date and
# topological sorting to closer mimic git's native ordering.
def
rugged_sort_type
(
sort_type
)
@rugged_sort_types
||=
{
none:
Rugged
::
SORT_NONE
,
topo:
Rugged
::
SORT_TOPO
,
date:
Rugged
::
SORT_DATE
|
Rugged
::
SORT_TOPO
}
@rugged_sort_types
.
fetch
(
sort_type
,
Rugged
::
SORT_NONE
)
end
end
end
end
spec/lib/gitlab/git/commit_spec.rb
浏览文件 @
144e37c6
...
...
@@ -244,6 +244,33 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
describe
'.find_all'
do
it
'should return a return a collection of commits'
do
commits
=
described_class
.
find_all
(
repository
)
expect
(
commits
).
not_to
be_empty
expect
(
commits
).
to
all
(
be_a_kind_of
(
Gitlab
::
Git
::
Commit
)
)
end
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
)
described_class
.
find_all
(
repository
,
order: :date
)
end
it
"applies no sorting by default"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_NONE
)
described_class
.
find_all
(
repository
)
end
end
context
'max_count'
do
subject
do
commits
=
Gitlab
::
Git
::
Commit
.
find_all
(
...
...
spec/lib/gitlab/git/repository_spec.rb
浏览文件 @
144e37c6
...
...
@@ -1101,35 +1101,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#find_commits'
do
it
'should return a return a collection of commits'
do
commits
=
repository
.
find_commits
expect
(
commits
).
not_to
be_empty
expect
(
commits
).
to
all
(
be_a_kind_of
(
Gitlab
::
Git
::
Commit
)
)
end
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
)
repository
.
find_commits
(
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
)
repository
.
find_commits
(
order: :date
)
end
it
"applies no sorting by default"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_NONE
)
repository
.
find_commits
end
end
end
describe
'#branches with deleted branch'
do
before
(
:each
)
do
ref
=
double
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录