Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
b7e5f455
提交
b7e5f455
编辑于
12 years ago
作者:
Sato Hiroyuki
浏览文件
操作
下载
补丁
差异文件
Refactor: Removing the duplicated code.
上级
79cd1ca3
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
app/models/network/commit.rb
+9
-0
9 个添加, 0 个删除
app/models/network/commit.rb
app/models/network/graph.rb
+30
-47
30 个添加, 47 个删除
app/models/network/graph.rb
app/views/graph/show.json.erb
+1
-1
1 个添加, 1 个删除
app/views/graph/show.json.erb
有
40 个添加
和
48 个删除
app/models/network/commit.rb
+
9
−
0
浏览文件 @
b7e5f455
...
@@ -26,5 +26,14 @@ def space
...
@@ -26,5 +26,14 @@ def space
0
0
end
end
end
end
def
parents
(
map
)
@commit
.
parents
.
map
do
|
p
|
if
map
.
include?
(
p
.
id
)
map
[
p
.
id
]
end
end
.
compact
end
end
end
end
end
此差异已折叠。
点击以展开。
app/models/network/graph.rb
+
30
−
47
浏览文件 @
b7e5f455
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
Network
module
Network
class
Graph
class
Graph
attr_reader
:days
,
:commits
attr_reader
:days
,
:commits
,
:map
def
self
.
max_count
def
self
.
max_count
@max_count
||=
650
@max_count
||=
650
...
@@ -61,9 +61,7 @@ def index_commits
...
@@ -61,9 +61,7 @@ def index_commits
end
end
commits_sort_by_ref
.
each
do
|
commit
|
commits_sort_by_ref
.
each
do
|
commit
|
if
@map
.
include?
commit
.
id
then
place_chain
(
commit
)
place_chain
(
commit
)
end
end
end
# find parent spaces for not overlap lines
# find parent spaces for not overlap lines
...
@@ -115,25 +113,21 @@ def include_ref?(commit)
...
@@ -115,25 +113,21 @@ def include_ref?(commit)
def
find_free_parent_spaces
(
commit
)
def
find_free_parent_spaces
(
commit
)
spaces
=
[]
spaces
=
[]
commit
.
parents
.
each
do
|
p
|
commit
.
parents
(
@map
).
each
do
|
parent
|
if
@map
.
include?
(
p
.
id
)
then
range
=
if
commit
.
time
<
parent
.
time
then
parent
=
@map
[
p
.
id
]
commit
.
time
..
parent
.
time
else
range
=
if
commit
.
time
<
parent
.
time
then
parent
.
time
..
commit
.
time
commit
.
time
..
parent
.
time
end
else
parent
.
time
..
commit
.
time
space
=
if
commit
.
space
>=
parent
.
space
then
end
find_free_parent_space
(
range
,
parent
.
space
,
-
1
,
commit
.
space
)
else
space
=
if
commit
.
space
>=
parent
.
space
then
find_free_parent_space
(
range
,
commit
.
space
,
-
1
,
parent
.
space
)
find_free_parent_space
(
range
,
parent
.
space
,
-
1
,
commit
.
space
)
end
else
find_free_parent_space
(
range
,
commit
.
space
,
-
1
,
parent
.
space
)
mark_reserved
(
range
,
space
)
end
spaces
<<
space
mark_reserved
(
range
,
space
)
spaces
<<
space
end
end
end
spaces
spaces
...
@@ -175,25 +169,18 @@ def place_chain(commit, parent_time = nil)
...
@@ -175,25 +169,18 @@ def place_chain(commit, parent_time = nil)
leaves
.
each
do
|
l
|
leaves
.
each
do
|
l
|
l
.
spaces
<<
space
l
.
spaces
<<
space
# Also add space to parent
# Also add space to parent
l
.
parents
.
each
do
|
p
|
l
.
parents
(
@map
).
each
do
|
parent
|
if
@map
.
include?
(
p
.
id
)
if
parent
.
space
>
0
parent
=
@map
[
p
.
id
]
parent
.
spaces
<<
space
if
parent
.
space
>
0
parent
.
spaces
<<
space
end
end
end
end
end
end
end
# and mark it as reserved
# and mark it as reserved
min_time
=
leaves
.
last
.
time
min_time
=
leaves
.
last
.
time
parents
=
leaves
.
last
.
parents
.
collect
leaves
.
last
.
parents
(
@map
).
each
do
|
parent
|
parents
.
each
do
|
p
|
if
parent
.
time
<
min_time
if
@map
.
include?
p
.
id
min_time
=
parent
.
time
parent
=
@map
[
p
.
id
]
if
parent
.
time
<
min_time
min_time
=
parent
.
time
end
end
end
end
end
...
@@ -206,7 +193,7 @@ def place_chain(commit, parent_time = nil)
...
@@ -206,7 +193,7 @@ def place_chain(commit, parent_time = nil)
# Visit branching chains
# Visit branching chains
leaves
.
each
do
|
l
|
leaves
.
each
do
|
l
|
parents
=
l
.
parents
.
collect
.
select
{
|
p
|
@map
.
include?
p
.
id
and
@map
[
p
.
id
]
.
space
.
zero?
}
parents
=
l
.
parents
(
@map
)
.
select
{
|
p
|
p
.
space
.
zero?
}
for
p
in
parents
for
p
in
parents
place_chain
(
p
,
l
.
time
)
place_chain
(
p
,
l
.
time
)
end
end
...
@@ -215,13 +202,10 @@ def place_chain(commit, parent_time = nil)
...
@@ -215,13 +202,10 @@ def place_chain(commit, parent_time = nil)
def
get_space_base
(
leaves
)
def
get_space_base
(
leaves
)
space_base
=
1
space_base
=
1
if
leaves
.
last
.
parents
.
size
>
0
parents
=
leaves
.
last
.
parents
(
@map
)
first_parent
=
leaves
.
last
.
parents
.
first
if
parents
.
size
>
0
if
@map
.
include?
(
first_parent
.
id
)
if
parents
.
first
.
space
>
0
first_p
=
@map
[
first_parent
.
id
]
space_base
=
parents
.
first
.
space
if
first_p
.
space
>
0
space_base
=
first_p
.
space
end
end
end
end
end
space_base
space_base
...
@@ -266,10 +250,9 @@ def take_left_leaves(raw_commit)
...
@@ -266,10 +250,9 @@ def take_left_leaves(raw_commit)
leaves
.
push
(
commit
)
if
commit
.
space
.
zero?
leaves
.
push
(
commit
)
if
commit
.
space
.
zero?
while
true
while
true
return
leaves
if
commit
.
parents
.
count
.
zero?
return
leaves
if
commit
.
parents
(
@map
).
count
.
zero?
return
leaves
unless
@map
.
include?
commit
.
parents
.
first
.
id
commit
=
@map
[
commit
.
parents
.
first
.
id
]
commit
=
commit
.
parents
(
@map
)
.
first
return
leaves
unless
commit
.
space
.
zero?
return
leaves
unless
commit
.
space
.
zero?
...
...
此差异已折叠。
点击以展开。
app/views/graph/show.json.erb
+
1
−
1
浏览文件 @
b7e5f455
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
days:
@graph
.
days
.
compact
.
map
{
|
d
|
[
d
.
day
,
d
.
strftime
(
"%b"
)]
},
days:
@graph
.
days
.
compact
.
map
{
|
d
|
[
d
.
day
,
d
.
strftime
(
"%b"
)]
},
commits:
@graph
.
commits
.
map
do
|
c
|
commits:
@graph
.
commits
.
map
do
|
c
|
{
{
parents:
parents_zip_spaces
(
c
.
parents
,
c
.
parent_spaces
),
parents:
parents_zip_spaces
(
c
.
parents
(
@graph
.
map
)
,
c
.
parent_spaces
),
author:
{
author:
{
name:
c
.
author
.
name
,
name:
c
.
author
.
name
,
email:
c
.
author
.
email
,
email:
c
.
author
.
email
,
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录