Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
324af4ac
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,发现更多精彩内容 >>
提交
324af4ac
编写于
5月 26, 2017
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'diffcollection-no-restarts' into 'master'
Fix buffering in DiffCollection See merge request !11659
上级
a59165e7
16168b5b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
21 deletion
+58
-21
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+21
-18
spec/lib/gitlab/git/diff_collection_spec.rb
spec/lib/gitlab/git/diff_collection_spec.rb
+37
-3
未找到文件。
lib/gitlab/git/diff_collection.rb
浏览文件 @
324af4ac
...
...
@@ -19,22 +19,19 @@ module Gitlab
@line_count
=
0
@byte_count
=
0
@overflow
=
false
@empty
=
true
@array
=
Array
.
new
end
def
each
(
&
block
)
if
@populated
# @iterator.each is slower than just iterating the array in place
@array
.
each
(
&
block
)
else
Gitlab
::
GitalyClient
.
migrate
(
:commit_raw_diffs
)
do
each_patch
(
&
block
)
end
Gitlab
::
GitalyClient
.
migrate
(
:commit_raw_diffs
)
do
each_patch
(
&
block
)
end
end
def
empty?
!
@iterator
.
any?
any?
# Make sure the iterator has been exercised
@empty
end
def
overflow?
...
...
@@ -60,7 +57,6 @@ module Gitlab
collection
=
each_with_index
do
|
element
,
i
|
@array
[
i
]
=
yield
(
element
)
end
@populated
=
true
collection
end
...
...
@@ -72,7 +68,6 @@ module Gitlab
return
if
@populated
each
{
nil
}
# force a loop through all diffs
@populated
=
true
nil
end
...
...
@@ -81,15 +76,17 @@ module Gitlab
end
def
each_patch
@iterator
.
each_with_index
do
|
raw
,
i
|
# First yield cached Diff instances from @array
if
@array
[
i
]
yield
@array
[
i
]
next
end
i
=
0
@array
.
each
do
|
diff
|
yield
diff
i
+=
1
end
return
if
@overflow
return
if
@iterator
.
nil?
# We have exhausted @array, time to create new Diff instances or stop.
break
if
@overflow
@iterator
.
each
do
|
raw
|
@empty
=
false
if
!
@all_diffs
&&
i
>=
@max_files
@overflow
=
true
...
...
@@ -115,7 +112,13 @@ module Gitlab
end
yield
@array
[
i
]
=
diff
i
+=
1
end
@populated
=
true
# Allow iterator to be garbage-collected. It cannot be reused anyway.
@iterator
=
nil
end
end
end
...
...
spec/lib/gitlab/git/diff_collection_spec.rb
浏览文件 @
324af4ac
...
...
@@ -10,7 +10,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
no_collapse:
no_collapse
)
end
let
(
:iterator
)
{
Array
.
new
(
file_count
,
fake_diff
(
line_length
,
line_count
))
}
let
(
:iterator
)
{
MutatingConstantIterator
.
new
(
file_count
,
fake_diff
(
line_length
,
line_count
))
}
let
(
:file_count
)
{
0
}
let
(
:line_length
)
{
1
}
let
(
:line_count
)
{
1
}
...
...
@@ -64,7 +64,15 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'3'
)
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
describe
'#size'
do
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
it
'does not change after peeking'
do
subject
.
any?
expect
(
subject
.
size
).
to
eq
(
3
)
end
end
context
'when limiting is disabled'
do
let
(
:all_diffs
)
{
true
}
...
...
@@ -83,7 +91,15 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
subject
{
super
().
real_size
}
it
{
is_expected
.
to
eq
(
'3'
)
}
end
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
describe
'#size'
do
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
it
'does not change after peeking'
do
subject
.
any?
expect
(
subject
.
size
).
to
eq
(
3
)
end
end
end
end
...
...
@@ -457,4 +473,22 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
def
fake_diff
(
line_length
,
line_count
)
{
'diff'
=>
"
#{
'a'
*
line_length
}
\n
"
*
line_count
}
end
class
MutatingConstantIterator
include
Enumerable
def
initialize
(
count
,
value
)
@count
=
count
@value
=
value
end
def
each
loop
do
break
if
@count
.
zero?
# It is critical to decrement before yielding. We may never reach the lines after 'yield'.
@count
-=
1
yield
@value
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录