Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cbdf372e
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 搜索 >>
提交
cbdf372e
编写于
10月 13, 2017
作者:
B
Brett Walker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implemented using an ivar, and added specs
上级
528f9cde
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
11 deletion
+78
-11
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+7
-2
app/views/projects/commit/branches.html.haml
app/views/projects/commit/branches.html.haml
+5
-5
spec/controllers/projects/commit_controller_spec.rb
spec/controllers/projects/commit_controller_spec.rb
+22
-4
spec/views/projects/commit/branches.html.haml_spec.rb
spec/views/projects/commit/branches.html.haml_spec.rb
+44
-0
未找到文件。
app/controllers/projects/commit_controller.rb
浏览文件 @
cbdf372e
...
...
@@ -16,6 +16,8 @@ class Projects::CommitController < Projects::ApplicationController
before_action
:define_note_vars
,
only:
[
:show
,
:diff_for_path
]
before_action
:authorize_edit_tree!
,
only:
[
:revert
,
:cherry_pick
]
BRANCH_SEARCH_LIMIT
=
1000
def
show
apply_diff_view_cookie!
...
...
@@ -59,8 +61,11 @@ class Projects::CommitController < Projects::ApplicationController
# branch_names_contains/tag_names_contains can take a long time when there are thousands of
# branches/tags - each `git branch --contains xxx` request can consume a cpu core.
# so only do the query when there are a manageable number of branches/tags
@branches
=
@project
.
repository
.
branch_count
>
1000
?
[
:limit_exceeded
]
:
@project
.
repository
.
branch_names_contains
(
commit
.
id
)
@tags
=
@project
.
repository
.
tag_count
>
1000
?
[
:limit_exceeded
]
:
@project
.
repository
.
tag_names_contains
(
commit
.
id
)
@branches_limit_exceeded
=
@project
.
repository
.
branch_count
>
BRANCH_SEARCH_LIMIT
@branches
=
@branches_limit_exceeded
?
[]
:
@project
.
repository
.
branch_names_contains
(
commit
.
id
)
@tags_limit_exceeded
=
@project
.
repository
.
tag_count
>
BRANCH_SEARCH_LIMIT
@tags
=
@tags_limit_exceeded
?
[]
:
@project
.
repository
.
tag_names_contains
(
commit
.
id
)
render
layout:
false
end
...
...
app/views/projects/commit/branches.html.haml
浏览文件 @
cbdf372e
-
if
@branches
.
any?
-
branch
=
commit_default_branch
(
@project
,
@branches
)
-
if
branch
==
:limit_exceeded
-
if
@branches
.
any?
||
@branches_limit_exceeded
-
if
@branches_limit_exceeded
=
commit_branch_link
(
'#'
,
_
(
'Too many branches to search'
))
-
else
-
branch
=
commit_default_branch
(
@project
,
@branches
)
=
commit_branch_link
(
project_ref_path
(
@project
,
branch
),
branch
)
-# `commit_default_branch` deletes the default branch from `@branches`,
-# so only render this if we have more branches or tags left
-
if
@branches
.
any?
||
@tags
.
any?
-
if
@branches
.
any?
||
@tags
.
any?
||
@tags_limit_exceeded
%span
=
link_to
"…"
,
"#"
,
class:
"js-details-expand label label-gray"
%span
.js-details-content.hide
=
commit_branches_links
(
@project
,
@branches
)
if
@branches
.
any?
-
if
@tags
.
first
==
:
limit_exceeded
-
if
@tags
_
limit_exceeded
=
commit_tag_link
(
'#'
,
_
(
'Too many tags to search'
))
-
elsif
@tags
.
any?
=
commit_tags_links
(
@project
,
@tags
)
spec/controllers/projects/commit_controller_spec.rb
浏览文件 @
cbdf372e
...
...
@@ -134,8 +134,8 @@ describe Projects::CommitController do
end
end
describe
"GET branches"
do
it
"contains branch and tags information"
do
describe
'GET branches'
do
it
'contains branch and tags information'
do
commit
=
project
.
commit
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
get
(
:branches
,
...
...
@@ -143,8 +143,26 @@ describe Projects::CommitController do
project_id:
project
,
id:
commit
.
id
)
expect
(
assigns
(
:branches
)).
to
include
(
"master"
,
"feature_conflict"
)
expect
(
assigns
(
:tags
)).
to
include
(
"v1.1.0"
)
expect
(
assigns
(
:branches
)).
to
include
(
'master'
,
'feature_conflict'
)
expect
(
assigns
(
:branches_limit_exceeded
)).
to
be_falsey
expect
(
assigns
(
:tags
)).
to
include
(
'v1.1.0'
)
expect
(
assigns
(
:tags_limit_exceeded
)).
to
be_falsey
end
it
'returns :limit_exceeded when number of branches/tags reach a threshhold'
do
commit
=
project
.
commit
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:branch_count
).
and_return
(
1001
)
allow_any_instance_of
(
Repository
).
to
receive
(
:tag_count
).
and_return
(
1001
)
get
(
:branches
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
commit
.
id
)
expect
(
assigns
(
:branches
)).
to
eq
([])
expect
(
assigns
(
:branches_limit_exceeded
)).
to
be_truthy
expect
(
assigns
(
:tags
)).
to
eq
([])
expect
(
assigns
(
:tags_limit_exceeded
)).
to
be_truthy
end
end
...
...
spec/views/projects/commit/branches.html.haml_spec.rb
0 → 100644
浏览文件 @
cbdf372e
require
'spec_helper'
describe
'projects/commit/branches.html.haml'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
assign
(
:project
,
project
)
end
context
'branches and tags'
do
before
do
assign
(
:branches
,
[
'master'
,
'test-branch'
])
assign
(
:branches_limit_exceeded
,
false
)
assign
(
:tags
,
[
'tag1'
])
assign
(
:tags_limit_exceeded
,
false
)
render
end
it
'shows branch and tag links'
do
expect
(
rendered
).
to
have_selector
(
'.js-details-expand'
)
expect
(
rendered
).
to
have_link
(
'master'
)
expect
(
rendered
).
to
have_link
(
'test-branch'
)
expect
(
rendered
).
to
have_link
(
'tag1'
)
end
end
context
'throttled branches and tags'
do
before
do
assign
(
:branches
,
[])
assign
(
:branches_limit_exceeded
,
true
)
assign
(
:tags
,
[])
assign
(
:tags_limit_exceeded
,
true
)
render
end
it
'shows too many to search'
do
expect
(
rendered
).
to
have_selector
(
'.js-details-expand'
)
expect
(
rendered
).
to
have_link
(
'Too many branches to search'
,
href:
'#'
)
expect
(
rendered
).
to
have_link
(
'Too many tags to search'
,
href:
'#'
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录